12 #ifndef FAISS_INDEX_IVF_H
13 #define FAISS_INDEX_IVF_H
20 #include "Clustering.h"
48 void train_q1 (
size_t n,
const float *x,
bool verbose,
79 virtual size_t list_size(
size_t list_no)
const = 0;
82 virtual const uint8_t *
get_codes (
size_t list_no)
const = 0;
85 virtual const idx_t *
get_ids (
size_t list_no)
const = 0;
88 virtual idx_t
get_single_id (
size_t list_no,
size_t offset)
const;
92 size_t list_no,
size_t offset)
const;
102 virtual size_t add_entry (
size_t list_no, idx_t theid,
103 const uint8_t *code);
105 virtual size_t add_entries (
106 size_t list_no,
size_t n_entry,
107 const idx_t* ids,
const uint8_t *code) = 0;
109 virtual void update_entry (
size_t list_no,
size_t offset,
110 idx_t
id,
const uint8_t *code);
112 virtual void update_entries (
size_t list_no,
size_t offset,
size_t n_entry,
113 const idx_t *ids,
const uint8_t *code) = 0;
115 virtual void resize (
size_t list_no,
size_t new_size) = 0;
117 virtual void reset ();
124 std::vector < std::vector<uint8_t> > codes;
125 std::vector < std::vector<idx_t> >
ids;
129 size_t list_size(
size_t list_no)
const override;
130 const uint8_t *
get_codes (
size_t list_no)
const override;
131 const idx_t *
get_ids (
size_t list_no)
const override;
134 size_t list_no,
size_t n_entry,
135 const idx_t*
ids,
const uint8_t *code)
override;
137 void update_entries (
size_t list_no,
size_t offset,
size_t n_entry,
138 const idx_t *
ids,
const uint8_t *code)
override;
140 void resize (
size_t list_no,
size_t new_size)
override;
178 std::vector <long> direct_map;
189 void reset()
override;
195 void add(
idx_t n,
const float* x)
override;
219 const float *centroid_dis,
220 float *distances,
idx_t *labels,
221 bool store_pairs)
const = 0;
225 float *distances,
idx_t *labels)
const override;
250 float *distances,
idx_t *labels,
251 float *recons)
const override;
261 float* recons)
const;
281 long a1,
long a2)
const;
285 size_t get_list_size (
size_t list_no)
const
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 =0
const uint8_t * get_codes(size_t list_no) const override
const idx_t * get_ids(size_t list_no) const override
virtual const idx_t * get_ids(size_t list_no) const =0
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 idx_t get_single_id(size_t list_no, size_t offset) const
size_t code_size
code size per vector in bytes
void train(idx_t n, const float *x) override
Trains the quantizer and calls train_residual to train sub-quantizers.
virtual const uint8_t * get_single_code(size_t list_no, size_t offset) const
void reconstruct_n(idx_t i0, idx_t ni, float *recons) const override
char quantizer_trains_alone
virtual size_t add_entry(size_t list_no, idx_t theid, const uint8_t *code)
add one entry to an inverted list
long idx_t
all indices are this type
ClusteringParameters cp
to override default clustering params
void reset() override
removes all elements from the database.
virtual void prefetch_lists(const long *list_nos, int nlist) const
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 nlist
number of possible key values
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.
std::vector< std::vector< idx_t > > ids
Inverted lists for indexes.
void add(idx_t n, const float *x) override
Quantizes x and calls add_with_key.
virtual const uint8_t * get_codes(size_t list_no) const =0
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
bool maintain_direct_map
map for direct access to the elements. Enables reconstruct().
bool own_fields
whether object owns the quantizer
size_t list_size(size_t list_no) const override
get the size of a list
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.