#include <Index.h>
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 | |
Abstract structure for an index
Supports adding vertices and searching them.
Currently only asymmetric queries are supported: database-to-database queries are not implemented.
|
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.
x | input 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.
|
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.
xids | if 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.
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.
x | input vector, size d |
residual | output residual vector, size d |
key | encoded index, as returned by search and assign |
void faiss::Index::display | ( | ) | 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).
x | input vectors to search, size n * d |
radius | search radius |
result | result table |
Reimplemented in faiss::IndexIVFFlat, and faiss::IndexFlat.
|
virtual |
Reconstruct a stored vector (or an approximation if lossy coding)
this function may not be defined for some indexes
key | id of the vector to reconstruct |
recons | reconstucted 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.
Reconstruct vectors i0 to i0 + ni - 1
this function may not be defined for some indexes
recons | reconstucted vector (size ni * d) |
Reimplemented in faiss::IndexPreTransform, faiss::IndexIVFPQR, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexFlat, faiss::IndexIVFPQ, and faiss::IndexPQ.
|
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.
|
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.
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::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.
|
inlinevirtual |
Perform training on a representative set of vectors
n | nb of training vectors |
x | training vecors, size n * d |
Reimplemented in faiss::IndexIVFPQCompact, faiss::IndexPreTransform, faiss::IndexSplitVectors, faiss::MultiIndexQuantizer, faiss::IndexRefineFlat, faiss::IndexShards, faiss::IndexScalarQuantizer, faiss::gpu::GpuIndexIVFPQ, faiss::gpu::GpuIndexFlat, faiss::IndexIVF, faiss::gpu::GpuIndexIVFFlat, faiss::IndexLSH, faiss::gpu::IndexProxy, faiss::IndexPQ, and faiss::IndexIDMap.