12 #ifndef FAISS_INDEX_IVFPQ_H
13 #define FAISS_INDEX_IVFPQ_H
48 size_t M,
size_t nbits_per_idx);
57 const long *xids,
float *residuals_2,
58 const long *precomputed_idx =
nullptr);
67 float* recons)
const override;
83 void encode (
long key,
const float * x, uint8_t * code)
const;
95 const float * x, uint8_t * codes,
96 bool compute_keys =
false)
const;
100 const uint8_t * xcodes,
float * x)
const;
104 const float *centroid_dis,
105 float *distances,
idx_t *labels,
106 bool store_pairs)
const override;
124 size_t n_hamming_pass;
129 size_t assign_cycles;
130 size_t search_cycles;
131 size_t refine_cycles;
134 size_t init_query_cycles;
135 size_t init_list_cycles;
158 size_t M,
size_t nbits_per_idx,
159 size_t M_refine,
size_t nbits_per_idx_refine);
161 void reset()
override;
172 const long *precomputed_idx =
nullptr);
175 float* recons)
const override;
182 const float *centroid_dis,
183 float *distances,
idx_t *labels,
184 bool store_pairs)
const override;
223 void add(
idx_t n,
const float* x)
override;
231 idx_t* labels)
const override;
237 void reset()
override;
void precompute_table()
build precomputed table
void merge_from(IndexIVF &other, idx_t add_id) override
void transfer_to_IVFPQ(IndexIVFPQ &other) const
transfer the flat codes to an IVFPQ index
size_t code_size_2
size of the code for the second level
void reconstruct_from_offset(long list_no, long offset, float *recons) const override
void search_preassigned(idx_t n, const float *x, idx_t k, const idx_t *assign, const float *centroid_dis, float *distances, idx_t *labels, bool store_pairs) const override
ProductQuantizer refine_pq
3rd level quantizer
PolysemousTraining * polysemous_training
if NULL, use default
void reconstruct_n(idx_t i0, idx_t ni, float *recons) const override
size_t code_size
code_size_1 + code_size_2
void reset() override
removes all elements from the database.
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
void decode_multiple(size_t n, const long *keys, const uint8_t *xcodes, float *x) const
inverse of encode_multiple
void train_residual_o(idx_t n, const float *x, float *residuals_2)
same as train_residual, also output 2nd level residuals
bool do_polysemous_training
reorder PQ centroids after training?
size_t scan_table_threshold
use table computation or on-the-fly?
void train_residual(idx_t n, const float *x) override
trains the two product quantizers
void add_core(idx_t n, const float *x, const long *xids, const long *precomputed_idx=nullptr)
same as add_with_ids, but optionally use the precomputed list ids
std::vector< float > precomputed_table
Level1Quantizer q1
first level quantizer
int polysemous_ht
Hamming thresh for polysemous filtering.
void reset() override
removes all elements from the database.
std::vector< uint8_t > codes
Codes. Size ntotal * code_size.
void add_with_ids(idx_t n, const float *x, const long *xids=nullptr) override
std::vector< uint8_t > refine_codes
corresponding codes
void train_residual(idx_t n, const float *x) override
trains the product quantizer
void reconstruct_from_offset(long list_no, long offset, float *recons) const override
void encode_multiple(size_t n, long *keys, const float *x, uint8_t *codes, bool compute_keys=false) const
long idx_t
all indices are this type
void train(idx_t n, const float *x) override
optimizes the order of indices in a ProductQuantizer
void add(idx_t n, const float *x) override
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
not implemented
bool by_residual
Encode residual or plain vector?
ProductQuantizer pq
produces the codes
size_t code_size_1
size of the code for the first level (ceil(log8(q1.nlist)))
void add_core_o(idx_t n, const float *x, const long *xids, float *residuals_2, const long *precomputed_idx=nullptr)
long remove_ids(const IDSelector &sel) override
Dataset manipulation functions.
void search_preassigned(idx_t n, const float *x, idx_t k, const idx_t *assign, const float *centroid_dis, float *distances, idx_t *labels, bool store_pairs) const override
Index * quantizer
quantizer that maps vectors to inverted lists
ProductQuantizer pq
second level quantizer is always a PQ
void add_with_ids(idx_t n, const float *x, const long *xids) override
void reconstruct(idx_t key, float *recons) const override
size_t nlist
number of possible key values
size_t find_duplicates(idx_t *ids, size_t *lims) const
MetricType
Some algorithms support both an inner product version and a L2 search version.
float k_factor
factor between k requested in search and the k requested from the IVFPQ
int use_precomputed_table
if by_residual, build precompute tables