Faiss

- Main Page
- Namespaces
- Classes
- Files

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

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

`#include <Index.h>`

Inheritance diagram for faiss::Index:

## Public Types
typedef long | idx_t
| all indices are this type

## Public Member Functions
| Index (idx_t d=0, MetricType metric=METRIC_L2)
virtual void | train (idx_t n, const float *x)
virtual void | add (idx_t n, const float *x)=0
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 void | reset ()=0
| removes all elements from the database.
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
virtual void | search_and_reconstruct (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons) const
void | compute_residual (const float *x, float *residual, idx_t key) const
void | display () const

## Public Attributes
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

## Detailed Description

Abstract structure for an index

Supports adding vertices and searching them.

Currently only asymmetric queries are supported: database-to-database queries are not implemented.

Definition at line 62 of file Index.h.

## Member Function Documentation

virtual void faiss::Index::add | ( | idx_t | n,
|  | const float * | x
| ) |  |
| pure virtual

Add n vectors of dimension d to the index.

Vectors are implicitly assigned labels ntotal .. ntotal + n - 1 This function slices the input vectors in chuncks smaller than blocksize_add and calls add_core.

Parameters

  x | input matrix, size n * d

Implemented in faiss::IndexPreTransform, faiss::Index2Layer, faiss::IndexSplitVectors, faiss::MultiIndexQuantizer, faiss::IndexFlat1D, faiss::IndexScalarQuantizer, faiss::IndexRefineFlat, faiss::IndexIVF, faiss::IndexShards, faiss::gpu::GpuIndexFlat, faiss::IndexHNSW, faiss::gpu::GpuIndexIVF, faiss::gpu::IndexProxy, faiss::IndexLSH, faiss::gpu::GpuIndex, faiss::IndexPQ, faiss::IndexIDMap, and faiss::IndexFlat.

void faiss::Index::add_with_ids | ( | idx_t | n,
|  | const float * | x,
|  | const long * | xids
| ) |  |
| virtual

Same as add, but stores xids instead of sequential ids.

The default implementation fails with an assertion, as it is not supported by all indexes.

Parameters

  xids | if non-null, ids to store for the vectors (size n)

Reimplemented in faiss::IndexPreTransform, faiss::IndexIVFPQR, faiss::IndexIVFScalarQuantizer, faiss::IndexShards, faiss::IndexIVFFlatDedup, faiss::IndexIDMap2, faiss::IndexIVFPQ, faiss::gpu::GpuIndex, faiss::IndexIVFFlat, and faiss::IndexIDMap.

Definition at line 42 of file Index.cpp.

void faiss::Index::assign | ( | idx_t | n,
|  | const float * | x,
|  | idx_t * | labels,
|  | idx_t | k = `1`
| ) |  |

return the indexes of the k vectors closest to the query x.

This function is identical as search but only return labels of neighbors.

Parameters

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

Definition at line 35 of file Index.cpp.

void faiss::Index::compute_residual | ( | const float * | x,
|  | float * | residual,
|  | idx_t | key
| ) |  | const

Computes a residual vector after indexing encoding.

The residual vector is the difference between a vector and the reconstruction that can be decoded from its representation in the index. The residual can be used for multiple-stage indexing methods, like IndexIVF's methods.

Parameters

  x | input vector, size d
  residual | output residual vector, size d
  key | encoded index, as returned by search and assign

Definition at line 87 of file Index.cpp.

void faiss::Index::display | ( |  | ) | const

Display the actual class name and some more info

Definition at line 95 of file Index.cpp.

void faiss::Index::range_search | ( | idx_t | n,
|  | const float * | x,
|  | float | radius,
|  | RangeSearchResult * | result
| ) |  | const
| 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 in faiss::IndexIVFFlatDedup, faiss::IndexIVFFlat, faiss::IndexIDMap, and faiss::IndexFlat.

Definition at line 29 of file Index.cpp.

void faiss::Index::reconstruct | ( | idx_t | key,
|  | float * | recons
| ) |  | const
| 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 in faiss::IndexPreTransform, faiss::Index2Layer, faiss::IndexIVF, faiss::MultiIndexQuantizer, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexHNSW, faiss::IndexIDMap2, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexFlat.

Definition at line 55 of file Index.cpp.

void faiss::Index::reconstruct_n | ( | idx_t | i0,
|  | idx_t | ni,
|  | float * | recons
| ) |  | const
| virtual

Reconstruct vectors i0 to i0 + ni - 1

this function may not be defined for some indexes

Parameters

  recons | reconstucted vector (size ni * d)

Reimplemented in faiss::IndexPreTransform, faiss::Index2Layer, faiss::IndexIVF, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, and faiss::IndexPQ.

Definition at line 60 of file Index.cpp.

long faiss::Index::remove_ids | ( | const IDSelector & | sel | ) |
| virtual

removes IDs from the index. Not supported by all indexes

Reimplemented in faiss::IndexPreTransform, faiss::IndexIVF, faiss::IndexIVFPQR, faiss::IndexIVFFlatDedup, faiss::IndexIDMap2, faiss::IndexFlat, faiss::IndexPQ, and faiss::IndexIDMap.

Definition at line 49 of file Index.cpp.

virtual void faiss::Index::search | ( | idx_t | n,
|  | const float * | x,
|  | idx_t | k,
|  | float * | distances,
|  | idx_t * | labels
| ) |  | const
| pure 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

Implemented in faiss::IndexPreTransform, faiss::Index2Layer, faiss::MultiIndexQuantizer2, faiss::IndexHNSW2Level, faiss::IndexIVF, faiss::IndexSplitVectors, faiss::IndexFlat1D, faiss::MultiIndexQuantizer, faiss::IndexScalarQuantizer, faiss::IndexShards, faiss::IndexRefineFlat, faiss::gpu::GpuIndexFlat, faiss::IndexHNSW, faiss::IndexFlatL2BaseShift, faiss::gpu::GpuIndex, faiss::gpu::IndexProxy, faiss::IndexLSH, faiss::IndexPQ, faiss::IndexIDMap, and faiss::IndexFlat.

void faiss::Index::search_and_reconstruct | ( | idx_t | n,
|  | const float * | x,
|  | idx_t | k,
|  | float * | distances,
|  | idx_t * | labels,
|  | float * | recons
| ) |  | const
| virtual

Similar to search, but also reconstructs the stored vectors (or an approximation in the case of lossy coding) for the search results.

If there are not enough results for a query, the resulting arrays is padded with -1s.

Parameters

  recons | reconstructed vectors size (n, k, d)

Reimplemented in faiss::IndexPreTransform, and faiss::IndexIVF.

Definition at line 67 of file Index.cpp.

void faiss::Index::train | ( | idx_t | n,
|  | const float * | x
| ) |  |
| virtual

Perform training on a representative set of vectors

Parameters

  n | nb of training vectors
  x | training vecors, size n * d

Reimplemented in faiss::IndexPreTransform, faiss::Index2Layer, faiss::MultiIndexQuantizer2, faiss::IndexSplitVectors, faiss::IndexHNSWPQ, faiss::MultiIndexQuantizer, faiss::IndexShards, faiss::IndexScalarQuantizer, faiss::IndexRefineFlat, faiss::IndexIVF, faiss::gpu::GpuIndexIVFPQ, faiss::IndexHNSW, faiss::gpu::GpuIndexFlat, faiss::IndexIVFFlatDedup, faiss::gpu::GpuIndexIVFFlat, faiss::IndexLSH, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexIDMap.

Definition at line 24 of file Index.cpp.

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

- /tmp/faiss/Index.h
- /tmp/faiss/Index.cpp