Faiss

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Public Member Functions | Public Attributes | List of all members
faiss::IndexIVF Struct Referenceabstract

`#include <IndexIVF.h>`

Inheritance diagram for faiss::IndexIVF:

## Public Member Functions
| IndexIVF (Index *quantizer, size_t d, size_t nlist, MetricType metric=METRIC_INNER_PRODUCT)
void | reset () override
| removes all elements from the database.
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)
virtual void | merge_from_residuals (IndexIVF &other)=0
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)
virtual void | add_with_ids (idx_t n, const float *x, const long *xids)
virtual void | search (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const =0
virtual void | range_search (idx_t n, const float *x, float radius, RangeSearchResult *result) const
void | assign (idx_t n, const float *x, idx_t *labels, idx_t k=1)
virtual long | remove_ids (const IDSelector &sel)
virtual void | reconstruct (idx_t key, float *recons) const
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
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

Index based on a inverted file (IVF)

In the inverted file, the quantizer (an Index instance) provides a quantization index for each vector to be added. The quantization index maps to a list (aka inverted list or posting list), where the id of the vector is then stored.

At search time, the vector to be searched is also quantized, and only the list corresponding to the quantization index is searched. This speeds up the search by making it non-exhaustive. This can be relaxed using multi-probe search: a few (nprobe) quantization indices are selected and several inverted lists are visited.

Sub-classes implement a post-filtering of the index that refines the distance estimation from the query to databse vectors.

Definition at line 45 of file IndexIVF.h.

## Constructor & Destructor Documentation

faiss::IndexIVF::IndexIVF | ( | Index * | quantizer,
|  | size_t | d,
|  | size_t | nlist,
|  | MetricType | metric = `METRIC_INNER_PRODUCT`
| ) |  |

The Inverted file takes a quantizer (an Index) on input, which implements the function mapping a vector to a list identifier. The pointer is borrowed: the quantizer should not be deleted while the IndexIVF is in use.

Definition at line 31 of file IndexIVF.cpp.

## Member Function Documentation

void faiss::IndexIVF::make_direct_map | ( | bool | new_maintain_direct_map = `true` | ) |

intialize a direct map

Parameters

  new_maintain_direct_map | if true, create a direct map, else clear it

Definition at line 68 of file IndexIVF.cpp.

void faiss::IndexIVF::merge_from | ( | IndexIVF & | other,
|  | idx_t | add_id
| ) |  |
| virtual

moves the entries from another dataset to self. On output, other is empty. add_id is added to all moved ids (for sequential ids, this would be this->ntotal

Definition at line 169 of file IndexIVF.cpp.

virtual void faiss::IndexIVF::merge_from_residuals | ( | IndexIVF & | other | ) |
| pure virtual

implemented by sub-classes

Implemented in faiss::IndexIVFPQR, faiss::IndexIVFFlat, faiss::IndexIVFScalarQuantizer, faiss::IndexIVFPQ, and faiss::IndexIVFScalarQuantizer.

void faiss::IndexIVF::train_residual | ( | idx_t | n,
|  | const float * | x
| ) |  |
| virtual

Sub-classes that encode the residuals can train their encoders here does nothing by default

Reimplemented in faiss::IndexIVFPQR, faiss::IndexIVFScalarQuantizer, faiss::IndexIVFScalarQuantizer, and faiss::IndexIVFPQ.

Definition at line 131 of file IndexIVF.cpp.

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