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_INNER_PRODUCT)
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
void | compute_residual (const float *x, float *residual, idx_t key) const
void | display () const
virtual std::string | get_typename () const
virtual void | set_typename ()=0

## Public Attributes
std::string | index_typename
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 61 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::IndexIVFPQCompact, faiss::IndexPreTransform, faiss::IndexFlat1D, faiss::MultiIndexQuantizer, faiss::IndexRefineFlat, faiss::IndexSplitVectors, faiss::IndexShards, faiss::gpu::GpuIndexFlat, faiss::IndexIVF, faiss::gpu::GpuIndexIVF, faiss::IndexLSH, faiss::gpu::IndexProxy, faiss::IndexPQ, faiss::IndexIDMap, faiss::gpu::GpuIndex, 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::IndexIVFFlat, faiss::gpu::GpuIndexIVFPQ, faiss::IndexShards, faiss::gpu::GpuIndexIVFFlat, faiss::IndexIVFPQ, and faiss::IndexIDMap.

Definition at line 32 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 24 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 58 of file Index.cpp.

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

Display the actual class name and some more info

Definition at line 66 of file Index.cpp.

virtual std::string faiss::Index::get_typename | ( |  | ) | const
| inline virtual

Return the typeName of the index (which includes main parameters

Definition at line 188 of file Index.h.

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, and faiss::IndexFlat.

Definition at line 18 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::IndexIVFFlat, faiss::MultiIndexQuantizer, faiss::IndexIVFPQ, faiss::gpu::GpuIndexFlat, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexFlat.

Definition at line 45 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::IndexIVFPQR, faiss::gpu::GpuIndexFlat, faiss::IndexIVFPQ, and faiss::IndexPQ.

Definition at line 50 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::IndexIVFPQR, faiss::IndexIVFFlat, and faiss::IndexIVFPQ.

Definition at line 38 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::IndexIVFPQR, faiss::IndexFlat1D, faiss::MultiIndexQuantizer, faiss::IndexIVFFlat, faiss::IndexRefineFlat, faiss::IndexSplitVectors, faiss::gpu::GpuIndexIVFPQ, faiss::IndexFlatL2BaseShift, faiss::IndexShards, faiss::gpu::GpuIndexIVFFlat, faiss::gpu::GpuIndexFlat, faiss::IndexIVFPQ, faiss::gpu::IndexProxy, faiss::IndexLSH, faiss::IndexPQ, faiss::IndexIDMap, and faiss::IndexFlat.

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

Perform training on a representative set of vectors

Parameters

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

Reimplemented in faiss::IndexIVFPQCompact, faiss::IndexPreTransform, faiss::MultiIndexQuantizer, faiss::IndexSplitVectors, faiss::IndexRefineFlat, faiss::IndexShards, faiss::gpu::GpuIndexIVFPQ, faiss::gpu::GpuIndexFlat, faiss::gpu::GpuIndexIVFFlat, faiss::IndexIVF, faiss::IndexLSH, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexIDMap.

Definition at line 92 of file Index.h.

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

- Index.h
- Index.cpp