10 #ifndef FAISS_INDEX_IVFPQ_H
11 #define FAISS_INDEX_IVFPQ_H
63 size_t M,
size_t nbits_per_idx);
69 const idx_t *list_nos,
70 uint8_t * codes)
const override;
76 const long *xids,
float *residuals_2,
77 const long *precomputed_idx =
nullptr);
86 float* recons)
const override;
102 void encode (
long key,
const float * x, uint8_t * code)
const;
114 const float * x, uint8_t * codes,
115 bool compute_keys =
false)
const;
119 const uint8_t * xcodes,
float * x)
const;
137 size_t n_hamming_pass;
142 size_t search_cycles;
143 size_t refine_cycles;
164 size_t M,
size_t nbits_per_idx,
165 size_t M_refine,
size_t nbits_per_idx_refine);
167 void reset()
override;
178 const long *precomputed_idx =
nullptr);
181 float* recons)
const override;
188 const float *centroid_dis,
189 float *distances,
idx_t *labels,
231 void add(
idx_t n,
const float* x)
override;
239 idx_t* labels)
const override;
245 void reset()
override;
void precompute_table()
build precomputed table
int polysemous_ht
Hamming thresh for polysemous filtering.
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
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
void encode_vectors(idx_t n, const float *x, const idx_t *list_nos, uint8_t *codes) const override
int polysemous_ht
Hamming thresh for polysemous filtering.
InvertedListScanner * get_InvertedListScanner(bool store_pairs) const override
get a scanner for this index (store_pairs means ignore labels)
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
default implementation that calls encode_vectors
long idx_t
all indices are this type
std::vector< uint8_t > refine_codes
corresponding codes
void train_residual(idx_t n, const float *x) override
trains the product quantizer
static size_t precomputed_table_max_bytes
2G by default, accommodates tables up to PQ32 w/ 65536 centroids
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
size_t scan_table_threshold
use table computation or on-the-fly?
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)
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 IVFSearchParameters *params=nullptr) const override
long remove_ids(const IDSelector &sel) override
Dataset manipulation functions.
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
default implementation that calls encode_vectors
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