#define TINYQUANT_H_VERSION "0.1.0"
#ifndef TINYQUANT_H
#define TINYQUANT_H
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef enum {
TINY_QUANT_COMPRESSION_POLICY_COMPRESS = 0,
TINY_QUANT_COMPRESSION_POLICY_PASSTHROUGH = 1,
TINY_QUANT_COMPRESSION_POLICY_FP16 = 2,
} TinyQuantCompressionPolicy;
typedef enum {
TINY_QUANT_ERROR_KIND_OK = 0,
TINY_QUANT_ERROR_KIND_INVALID_HANDLE = 1,
TINY_QUANT_ERROR_KIND_DIMENSION_MISMATCH = 2,
TINY_QUANT_ERROR_KIND_CONFIG_MISMATCH = 3,
TINY_QUANT_ERROR_KIND_CODEBOOK_INCOMPATIBLE = 4,
TINY_QUANT_ERROR_KIND_DUPLICATE_VECTOR = 5,
TINY_QUANT_ERROR_KIND_IO = 6,
TINY_QUANT_ERROR_KIND_INVALID_ARGUMENT = 7,
TINY_QUANT_ERROR_KIND_PANIC = 98,
TINY_QUANT_ERROR_KIND_UNKNOWN = 99,
} TinyQuantErrorKind;
typedef struct {
uint8_t _private[0];
} CodebookHandle;
typedef struct {
uint8_t _private[0];
} CodecConfigHandle;
typedef struct {
TinyQuantErrorKind kind;
char *message;
} TinyQuantError;
typedef struct {
uint8_t _private[0];
} CompressedVectorHandle;
typedef struct {
uint8_t _private[0];
} CorpusHandle;
#ifdef __cplusplus
extern "C" {
#endif
void tq_bytes_free(uint8_t *ptr, uintptr_t len);
uint8_t tq_codebook_bit_width(const CodebookHandle *handle);
void tq_codebook_free(CodebookHandle *handle);
TinyQuantErrorKind tq_codebook_train(const float *training_vectors,
uintptr_t rows,
uintptr_t cols,
const CodecConfigHandle *config,
CodebookHandle **out,
TinyQuantError *err);
TinyQuantErrorKind tq_codec_compress(const CodecConfigHandle *config,
const CodebookHandle *codebook,
const float *vector,
uintptr_t vector_len,
CompressedVectorHandle **out,
TinyQuantError *err);
uint8_t tq_codec_config_bit_width(const CodecConfigHandle *handle);
uint32_t tq_codec_config_dimension(const CodecConfigHandle *handle);
void tq_codec_config_free(CodecConfigHandle *handle);
const char *tq_codec_config_hash(const CodecConfigHandle *handle);
TinyQuantErrorKind tq_codec_config_new(uint8_t bit_width,
uint64_t seed,
uint32_t dimension,
bool residual_enabled,
CodecConfigHandle **out,
TinyQuantError *err);
bool tq_codec_config_residual_enabled(const CodecConfigHandle *handle);
uint64_t tq_codec_config_seed(const CodecConfigHandle *handle);
TinyQuantErrorKind tq_codec_decompress(const CodecConfigHandle *config,
const CodebookHandle *codebook,
const CompressedVectorHandle *compressed,
float *out,
uintptr_t out_len,
TinyQuantError *err);
uint8_t tq_compressed_vector_bit_width(const CompressedVectorHandle *handle);
uint32_t tq_compressed_vector_dimension(const CompressedVectorHandle *handle);
void tq_compressed_vector_free(CompressedVectorHandle *handle);
TinyQuantErrorKind tq_compressed_vector_from_bytes(const uint8_t *data,
uintptr_t data_len,
CompressedVectorHandle **out,
TinyQuantError *err);
TinyQuantErrorKind tq_compressed_vector_to_bytes(const CompressedVectorHandle *handle,
uint8_t **out_bytes,
uintptr_t *out_len,
TinyQuantError *err);
bool tq_corpus_contains(const CorpusHandle *handle, const char *vector_id);
void tq_corpus_free(CorpusHandle *handle);
TinyQuantErrorKind tq_corpus_insert(CorpusHandle *handle,
const char *vector_id,
const float *vector,
uintptr_t vector_len,
int64_t timestamp,
TinyQuantError *err);
TinyQuantErrorKind tq_corpus_new(const char *corpus_id,
const CodecConfigHandle *config,
const CodebookHandle *codebook,
TinyQuantCompressionPolicy policy,
CorpusHandle **out,
TinyQuantError *err);
uintptr_t tq_corpus_vector_count(const CorpusHandle *handle);
void tq_error_free(TinyQuantError *err);
void tq_error_free_message(char *message);
const char *tq_version(void);
#ifdef __cplusplus
} #endif
#endif