11 #ifndef FAISS_INDEX_IVF_H
12 #define FAISS_INDEX_IVF_H
19 #include "InvertedLists.h"
20 #include "Clustering.h"
48 void train_q1 (
size_t n,
const float *x,
bool verbose,
69 struct InvertedListScanner;
103 std::vector <long> direct_map;
114 void reset()
override;
120 void add(
idx_t n,
const float* x)
override;
129 const idx_t *list_nos,
130 uint8_t * codes)
const = 0;
156 const float *centroid_dis,
157 float *distances,
idx_t *labels,
164 float *distances,
idx_t *labels)
const override;
168 bool store_pairs=
false)
const {
172 void reconstruct (idx_t key,
float* recons)
const override;
183 void reconstruct_n(idx_t i0, idx_t ni,
float* recons)
const override;
195 float *distances, idx_t *labels,
196 float *recons)
const override;
206 float* recons)
const;
231 long a1,
long a2)
const;
235 size_t get_list_size (
size_t list_no)
const
266 virtual void set_query (
const float *query_vector) = 0;
269 virtual void set_list (idx_t list_no,
float coarse_dis) = 0;
285 const uint8_t *codes,
287 float *distances, idx_t *labels,
299 size_t nheap_updates;
virtual void encode_vectors(idx_t n, const float *x, const idx_t *list_nos, uint8_t *codes) const =0
virtual 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
void check_compatible_for_merge(const IndexIVF &other) const
double imbalance_factor() const
1= perfectly balanced, >1: imbalanced
void search_and_reconstruct(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons) const override
virtual void copy_subset_to(IndexIVF &other, int subset_type, long a1, long a2) const
virtual void reconstruct_from_offset(long list_no, long offset, float *recons) const
size_t nprobe
number of probes at query time
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
virtual size_t list_size(size_t list_no) const =0
get the size of a list
void reconstruct(idx_t key, float *recons) const override
virtual void train_residual(idx_t n, const float *x)
virtual float distance_to_code(const uint8_t *code) const =0
compute a single query-to-code distance
void train(idx_t n, const float *x) override
Trains the quantizer and calls train_residual to train sub-quantizers.
void reconstruct_n(idx_t i0, idx_t ni, float *recons) const override
char quantizer_trains_alone
virtual void set_list(idx_t list_no, float coarse_dis)=0
following codes come from this inverted list
virtual size_t scan_codes(size_t n, const uint8_t *codes, const idx_t *ids, float *distances, idx_t *labels, size_t k) const =0
long idx_t
all indices are this type
void replace_invlists(InvertedLists *il, bool own=false)
replace the inverted lists, old one is deallocated if own_invlists
ClusteringParameters cp
to override default clustering params
void reset() override
removes all elements from the database.
Index * clustering_index
to override index used during clustering
void train_q1(size_t n, const float *x, bool verbose, MetricType metric_type)
Trains the quantizer and calls train_residual to train sub-quantizers.
size_t nprobe
number of probes at query time
void make_direct_map(bool new_maintain_direct_map=true)
void print_stats() const
display some stats about the inverted lists
InvertedLists * invlists
Acess to the actual data.
void add(idx_t n, const float *x) override
Calls add_with_ids with NULL ids.
size_t max_codes
max nb of codes to visit to do a query
Index * quantizer
quantizer that maps vectors to inverted lists
long remove_ids(const IDSelector &sel) override
Dataset manipulation functions.
size_t max_codes
max nb of codes to visit to do a query
virtual InvertedListScanner * get_InvertedListScanner(bool store_pairs=false) const
get a scanner for this index (store_pairs means ignore labels)
bool maintain_direct_map
map for direct access to the elements. Enables reconstruct().
bool own_fields
whether object owns the quantizer
virtual void set_query(const float *query_vector)=0
from now on we handle this query.
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
virtual void merge_from(IndexIVF &other, idx_t add_id)
size_t nlist
number of possible key values
size_t code_size
code size per vector in bytes
MetricType
Some algorithms support both an inner product version and a L2 search version.