mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 00:36:56 +02:00
Add IVF index for vec0 virtual table
Add inverted file (IVF) index type: partitions vectors into clusters via k-means, quantizes to int8, and scans only the nearest nprobe partitions at query time. Includes shadow table management, insert/delete, KNN integration, compile flag (SQLITE_VEC_ENABLE_IVF), fuzz targets, and tests. Removes superseded ivf-benchmarks/ directory.
This commit is contained in:
parent
43982c144b
commit
3358e127f6
22 changed files with 5237 additions and 28 deletions
|
|
@ -5,6 +5,10 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef SQLITE_VEC_ENABLE_IVF
|
||||
#define SQLITE_VEC_ENABLE_IVF 1
|
||||
#endif
|
||||
|
||||
int min_idx(
|
||||
const float *distances,
|
||||
int32_t n,
|
||||
|
|
@ -68,8 +72,36 @@ enum Vec0IndexType {
|
|||
#ifdef SQLITE_VEC_ENABLE_RESCORE
|
||||
VEC0_INDEX_TYPE_RESCORE = 2,
|
||||
#endif
|
||||
VEC0_INDEX_TYPE_IVF = 3,
|
||||
};
|
||||
|
||||
enum Vec0RescoreQuantizerType {
|
||||
VEC0_RESCORE_QUANTIZER_BIT = 1,
|
||||
VEC0_RESCORE_QUANTIZER_INT8 = 2,
|
||||
};
|
||||
|
||||
struct Vec0RescoreConfig {
|
||||
enum Vec0RescoreQuantizerType quantizer_type;
|
||||
int oversample;
|
||||
};
|
||||
|
||||
#if SQLITE_VEC_ENABLE_IVF
|
||||
enum Vec0IvfQuantizer {
|
||||
VEC0_IVF_QUANTIZER_NONE = 0,
|
||||
VEC0_IVF_QUANTIZER_INT8 = 1,
|
||||
VEC0_IVF_QUANTIZER_BINARY = 2,
|
||||
};
|
||||
|
||||
struct Vec0IvfConfig {
|
||||
int nlist;
|
||||
int nprobe;
|
||||
int quantizer;
|
||||
int oversample;
|
||||
};
|
||||
#else
|
||||
struct Vec0IvfConfig { char _unused; };
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_VEC_ENABLE_RESCORE
|
||||
enum Vec0RescoreQuantizerType {
|
||||
VEC0_RESCORE_QUANTIZER_BIT = 1,
|
||||
|
|
@ -93,6 +125,7 @@ struct VectorColumnDefinition {
|
|||
#ifdef SQLITE_VEC_ENABLE_RESCORE
|
||||
struct Vec0RescoreConfig rescore;
|
||||
#endif
|
||||
struct Vec0IvfConfig ivf;
|
||||
};
|
||||
|
||||
int vec0_parse_vector_column(const char *source, int source_length,
|
||||
|
|
@ -114,6 +147,10 @@ void _test_rescore_quantize_float_to_int8(const float *src, int8_t *dst, size_t
|
|||
size_t _test_rescore_quantized_byte_size_bit(size_t dimensions);
|
||||
size_t _test_rescore_quantized_byte_size_int8(size_t dimensions);
|
||||
#endif
|
||||
#if SQLITE_VEC_ENABLE_IVF
|
||||
void ivf_quantize_int8(const float *src, int8_t *dst, int D);
|
||||
void ivf_quantize_binary(const float *src, uint8_t *dst, int D);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* SQLITE_VEC_INTERNAL_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue