All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
faiss::IndexIVFFlat Struct Reference

`#include <IndexIVF.h>`

Inheritance diagram for faiss::IndexIVFFlat:

## Public Member Functions

| IndexIVFFlat (Index *quantizer, size_t d, size_t nlist_, MetricType=METRIC_INNER_PRODUCT)
virtual void | add_core (idx_t n, const float *x, const long *xids, const long *precomputed_idx)
| same as add_with_ids, with precomputed coarse quantizer
void | add_with_ids (idx_t n, const float *x, const long *xids) override
| implemented for all IndexIVF* classes
void | search (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
void | search_preassigned (idx_t n, const float *x, idx_t k, const idx_t *assign, float *distances, idx_t *labels) const
| perform search, without computing the assignment to the quantizer
void | range_search (idx_t n, const float *x, float radius, RangeSearchResult *result) const override
void | copy_subset_to (IndexIVFFlat &other, int subset_type, long a1, long a2) const
void | reset () override
| removes all elements from the database.
long | remove_ids (const IDSelector &sel) override
void | search_knn_inner_product (size_t nx, const float *x, const long *keys, float_minheap_array_t *res) const
| Implementation of the search for the inner product metric.
void | search_knn_L2sqr (size_t nx, const float *x, const long *keys, float_maxheap_array_t *res) const
| Implementation of the search for the L2 metric.
void | update_vectors (int nv, idx_t *idx, const float *v)
void | reconstruct (idx_t key, float *recons) const override
void | merge_from_residuals (IndexIVF &other) override
Public Member Functions inherited from faiss::IndexIVF
| IndexIVF (Index *quantizer, size_t d, size_t nlist, MetricType metric=METRIC_INNER_PRODUCT)
void | train (idx_t n, const float *x) override
| Trains the quantizer and calls train_residual to train sub-quantizers.
void | add (idx_t n, const float *x) override
| Quantizes x and calls add_with_key.
virtual void | train_residual (idx_t n, const float *x)
virtual void | merge_from (IndexIVF &other, idx_t add_id)
size_t | get_list_size (size_t list_no) const
void | make_direct_map (bool new_maintain_direct_map=true)
double | imbalance_factor () const
| 1= perfectly balanced, >1: imbalanced
void | print_stats () const
| display some stats about the inverted lists
Public Member Functions inherited from faiss::Index
| Index (idx_t d=0, MetricType metric=METRIC_INNER_PRODUCT)
void | assign (idx_t n, const float *x, idx_t *labels, idx_t k=1)
virtual void | reconstruct_n (idx_t i0, idx_t ni, float *recons) const
void | compute_residual (const float *x, float *residual, idx_t key) const
void | display () const

## Public Attributes

std::vector< std::vector< float > > | vecs
Public Attributes inherited from faiss::IndexIVF
size_t | nlist
| number of possible key values
size_t | nprobe
| number of probes at query time
Index * | quantizer
| quantizer that maps vectors to inverted lists
bool | quantizer_trains_alone
| just pass over the trainset to quantizer
bool | own_fields
| whether object owns the quantizer
ClusteringParameters | cp
| to override default clustering params
std::vector< std::vector< long > > | ids
| Inverted lists for indexes.
bool | maintain_direct_map
| map for direct access to the elements. Enables reconstruct().
std::vector< long > | direct_map
Public Attributes inherited from faiss::Index
int | d
| vector dimension
idx_t | ntotal
| total nb of indexed vectors
bool | verbose
| verbosity level
bool | is_trained
| set if the Index does not require training, or if training is done already
MetricType | metric_type
| type of metric this index uses for search

## Additional Inherited Members

Public Types inherited from faiss::Index
typedef long | idx_t
| all indices are this type

## Detailed Description

Inverted file with stored vectors. Here the inverted file pre-selects the vectors to be searched, but they are not otherwise encoded.

Definition at line 132 of file IndexIVF.h.

## Member Function Documentation

void faiss::IndexIVFFlat::copy_subset_to | ( | IndexIVFFlat & | other,
|  | int | subset_type,
|  | long | a1,
|  | long | a2
| ) |  | const

copy a subset of the entries index to the other index

if subset_type == 0: copies ids in [a1, a2) if subset_type == 1: copies ids if id % a1 == a2

Definition at line 462 of file IndexIVF.cpp.

void faiss::IndexIVFFlat::merge_from_residuals | ( | IndexIVF & | other | ) |

override virtual

implemented by sub-classes

Implements faiss::IndexIVF.

Definition at line 450 of file IndexIVF.cpp.

void faiss::IndexIVFFlat::range_search | ( | idx_t | n,
|  | const float * | x,
|  | float | radius,
|  | RangeSearchResult * | result
| ) |  | const

override virtual

query n vectors of dimension d to the index.

return all vectors with distance < radius. Note that many indexes do not implement the range_search (only the k-NN search is mandatory).

Parameters

  x | input vectors to search, size n * d
  radius | search radius
  result | result table

Reimplemented from faiss::Index.

Definition at line 400 of file IndexIVF.cpp.

void faiss::IndexIVFFlat::reconstruct | ( | idx_t | key,
|  | float * | recons
| ) |  | const

override virtual

Reconstruct a stored vector (or an approximation if lossy coding)

this function may not be defined for some indexes

Parameters

  key | id of the vector to reconstruct
  recons | reconstucted vector (size d)

Reimplemented from faiss::Index.

Definition at line 572 of file IndexIVF.cpp.

long faiss::IndexIVFFlat::remove_ids | ( | const IDSelector & | sel | ) |

override virtual

removes IDs from the index. Not supported by all indexes

Reimplemented from faiss::Index.

Definition at line 540 of file IndexIVF.cpp.

void faiss::IndexIVFFlat::search | ( | idx_t | n,
|  | const float * | x,
|  | idx_t | k,
|  | float * | distances,
|  | idx_t * | labels
| ) |  | const

override virtual

query n vectors of dimension d to the index.

return at most k vectors. If there are not enough results for a query, the result array is padded with -1s.

Parameters

  x | input vectors to search, size n * d
  labels | output labels of the NNs, size n*k
  distances | output pairwise distances, size n*k

Implements faiss::Index.

Reimplemented in faiss::IndexIVFFlatIPBounds.

Definition at line 372 of file IndexIVF.cpp.

void faiss::IndexIVFFlat::update_vectors | ( | int | nv,
|  | idx_t * | idx,
|  | const float * | v
| ) |  |

Update a subset of vectors.

The index must have a direct_map

Parameters

  nv | nb of vectors to update
  idx | vector indices to update, size nv
  v | vectors of new values, size nv*d

Definition at line 487 of file IndexIVF.cpp.

## Member Data Documentation

std::vector< std::vector<float> > faiss::IndexIVFFlat::vecs

Inverted list of original vectors. Each list is a nl * d matrix, where nl is the nb of vectors stored in the list.

Definition at line 135 of file IndexIVF.h.

The documentation for this struct was generated from the following files:

- /data/users/matthijs/github_faiss/faiss/IndexIVF.h
- /data/users/matthijs/github_faiss/faiss/IndexIVF.cpp