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 60 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::Index2Layer, faiss::IndexPreTransform, faiss::IndexHNSW, faiss::IndexIVFPQCompact, faiss::MultiIndexQuantizer, faiss::IndexFlat1D, faiss::IndexSplitVectors, faiss::IndexRefineFlat, faiss::IndexScalarQuantizer, faiss::IndexShards, faiss::IndexIVF, faiss::gpu::GpuIndexFlat, 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::IndexIVFFlat, faiss::IndexIVFPQR, faiss::IndexIVFScalarQuantizer, faiss::IndexShards, faiss::IndexIDMap2, faiss::gpu::GpuIndex, faiss::IndexIVFPQ, and faiss::IndexIDMap.

Definition at line 41 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 34 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 86 of file Index.cpp.

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

Display the actual class name and some more info

Definition at line 94 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::IndexIVFFlat, faiss::IndexIDMap, and faiss::IndexFlat.

Definition at line 28 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::IndexHNSW, faiss::MultiIndexQuantizer, faiss::IndexIVF, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexIDMap2, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexFlat.

Definition at line 54 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 59 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::IndexIDMap2, faiss::IndexFlat, and faiss::IndexIDMap.

Definition at line 48 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::IndexHNSW2Level, faiss::IndexPreTransform, faiss::Index2Layer, faiss::IndexHNSW, faiss::IndexFlat1D, faiss::IndexSplitVectors, faiss::MultiIndexQuantizer, faiss::IndexIVF, faiss::IndexRefineFlat, faiss::IndexScalarQuantizer, faiss::IndexShards, faiss::gpu::GpuIndexFlat, 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 66 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::IndexHNSWPQ, faiss::Index2Layer, faiss::IndexPreTransform, faiss::IndexHNSW, faiss::IndexIVFPQCompact, faiss::IndexSplitVectors, faiss::MultiIndexQuantizer, faiss::IndexShards, faiss::IndexRefineFlat, faiss::IndexScalarQuantizer, faiss::IndexIVF, faiss::gpu::GpuIndexIVFPQ, faiss::gpu::GpuIndexFlat, faiss::gpu::GpuIndexIVFFlat, faiss::IndexLSH, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexIDMap.

Definition at line 23 of file Index.cpp.

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

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