12 #ifndef FAISS_INDEX_IVFPQ_H
13 #define FAISS_INDEX_IVFPQ_H
49 size_t M,
size_t nbits_per_idx);
58 const long *xids,
float *residuals_2,
59 const long *precomputed_idx =
nullptr);
92 void encode (
long key,
const float * x, uint8_t * code)
const;
104 const float * x, uint8_t * codes,
105 bool compute_keys =
false)
const;
109 const uint8_t * xcodes,
float * x)
const;
113 const float *centroid_dis,
114 float *distances,
idx_t *labels,
115 bool store_pairs)
const override;
134 size_t n_hamming_pass;
139 size_t assign_cycles;
140 size_t search_cycles;
141 size_t refine_cycles;
144 size_t init_query_cycles;
145 size_t init_list_cycles;
168 size_t M,
size_t nbits_per_idx,
169 size_t M_refine,
size_t nbits_per_idx_refine);
171 void reset()
override;
182 const long *precomputed_idx =
nullptr);
194 idx_t* labels)
const override;
228 const float *centroid_dis,
229 float *distances,
idx_t *labels,
230 bool store_pairs)
const override;
233 void add(
idx_t,
const float*)
override;
234 void reset()
override;
uint32_t * compact_ids
size ntotal
uint8_t * compact_codes
size ntotal * code_size
void precompute_table()
build precomputed table
void merge_from(IndexIVF &other, idx_t add_id) override
void reconstruct(idx_t key, float *recons) const override
ProductQuantizer refine_pq
3rd level quantizer
PolysemousTraining * polysemous_training
if NULL, use default
void add(idx_t, const float *) override
the three following functions will fail at runtime
void reconstruct_n(idx_t i0, idx_t ni, 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
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
uint32_t * limits
size nlist + 1
std::vector< float > precomputed_table
int polysemous_ht
Hamming thresh for polysemous filtering.
void reset() override
removes all elements from the database.
void add_with_ids(idx_t n, const float *x, const long *xids=nullptr) override
std::vector< std::vector< long > > ids
Inverted lists for indexes.
Index * quantizer
quantizer that maps vectors to inverted lists
size_t max_codes
max nb of codes to visit to do a query
Alloc_type_t
how were the compact tables allocated?
std::vector< uint8_t > refine_codes
corresponding codes
void train_residual(idx_t n, const float *x) override
trains the product quantizer
void encode_multiple(size_t n, long *keys, const float *x, uint8_t *codes, bool compute_keys=false) const
void train(idx_t, const float *) override
Trains the quantizer and calls train_residual to train sub-quantizers.
long idx_t
all indices are this type
optimizes the order of indices in a ProductQuantizer
bool by_residual
Encode residual or plain vector?
ProductQuantizer pq
produces the codes
size_t nlist
number of possible key values
void reconstruct_n(idx_t i0, idx_t ni, float *recons) const override
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
void reset() override
removes all elements from the database.
void add_with_ids(idx_t n, const float *x, const long *xids) override
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
size_t find_duplicates(idx_t *ids, size_t *lims) const
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