Faiss
 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:
faiss::gpu::GpuIndex faiss::gpu::IndexProxy faiss::IndexFlat faiss::IndexIDMap faiss::IndexIVF faiss::IndexLSH faiss::IndexPQ faiss::IndexPreTransform faiss::IndexRefineFlat faiss::IndexScalarQuantizer faiss::IndexShards faiss::IndexSplitVectors faiss::MultiIndexQuantizer

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, const float *)
 
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
 

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
xinput matrix, size n * d

Implemented in faiss::IndexIVFPQCompact, faiss::IndexPreTransform, faiss::MultiIndexQuantizer, faiss::IndexFlat1D, faiss::IndexSplitVectors, faiss::IndexRefineFlat, faiss::IndexShards, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexIVF, 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
xidsif non-null, ids to store for the vectors (size n)

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

Definition at line 30 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
xinput vectors to search, size n * d
labelsoutput labels of the NNs, size n*k

Definition at line 23 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
xinput vector, size d
residualoutput residual vector, size d
keyencoded index, as returned by search and assign

Definition at line 57 of file Index.cpp.

void faiss::Index::display ( ) const

Display the actual class name and some more info

Definition at line 65 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
xinput vectors to search, size n * d
radiussearch radius
resultresult table

Reimplemented in faiss::IndexIVFFlat, and faiss::IndexFlat.

Definition at line 17 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
keyid of the vector to reconstruct
reconsreconstucted vector (size d)

Reimplemented in faiss::IndexIVFFlat, faiss::MultiIndexQuantizer, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexIVFPQ, faiss::IndexIDMap2, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexFlat.

Definition at line 43 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
reconsreconstucted vector (size ni * d)

Reimplemented in faiss::IndexPreTransform, faiss::IndexIVFPQR, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexIVFPQ, and faiss::IndexPQ.

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

Definition at line 37 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
xinput vectors to search, size n * d
labelsoutput labels of the NNs, size n*k
distancesoutput pairwise distances, size n*k

Implemented in faiss::IndexPreTransform, faiss::IndexIVFFlatIPBounds, faiss::IndexIVFPQR, faiss::IndexFlat1D, faiss::IndexIVFFlat, faiss::IndexIVFScalarQuantizer, faiss::MultiIndexQuantizer, faiss::IndexSplitVectors, faiss::IndexRefineFlat, faiss::IndexShards, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexFlatL2BaseShift, faiss::gpu::GpuIndex, faiss::IndexIVFPQ, faiss::gpu::IndexProxy, faiss::IndexLSH, faiss::IndexPQ, faiss::IndexIDMap, and faiss::IndexFlat.

virtual void faiss::Index::train ( idx_t  ,
const float *   
)
inlinevirtual

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