#include <IndexHNSW.h>
Public Types | |
typedef HNSW::storage_idx_t | storage_idx_t |
![]() | |
using | idx_t = long |
all indices are this type | |
using | component_t = float |
using | distance_t = float |
Public Member Functions | |
IndexHNSW (int d=0, int M=32) | |
IndexHNSW (Index *storage, int M=32) | |
virtual DistanceComputer * | get_distance_computer () const =0 |
void | add (idx_t n, const float *x) override |
void | train (idx_t n, const float *x) override |
Trains the storage if needed. | |
void | search (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override |
entry point for search | |
void | reconstruct (idx_t key, float *recons) const override |
void | reset () override |
removes all elements from the database. | |
void | shrink_level_0_neighbors (int size) |
void | search_level_0 (idx_t n, const float *x, idx_t k, const storage_idx_t *nearest, const float *nearest_d, float *distances, idx_t *labels, int nprobe=1, int search_type=1) const |
void | init_level_0_from_knngraph (int k, const float *D, const idx_t *I) |
alternative graph building | |
void | init_level_0_from_entry_points (int npt, const storage_idx_t *points, const storage_idx_t *nearests) |
alternative graph building | |
void | reorder_links () |
void | link_singletons () |
![]() | |
Index (idx_t d=0, MetricType metric=METRIC_L2) | |
virtual void | add_with_ids (idx_t n, const float *x, const long *xids) |
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 long | remove_ids (const IDSelector &sel) |
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 | |
HNSW | hnsw |
bool | own_fields |
Index * | storage |
ReconstructFromNeighbors * | reconstruct_from_neighbors |
![]() | |
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 | |
The HNSW index is a normal random-access index with a HNSW link structure built on top
Definition at line 69 of file IndexHNSW.h.
|
overridevirtual |
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 |
Implements faiss::Index.
Definition at line 294 of file IndexHNSW.cpp.
|
overridevirtual |
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 from faiss::Index.
Definition at line 312 of file IndexHNSW.cpp.
void faiss::IndexHNSW::search_level_0 | ( | idx_t | n, |
const float * | x, | ||
idx_t | k, | ||
const storage_idx_t * | nearest, | ||
const float * | nearest_d, | ||
float * | distances, | ||
idx_t * | labels, | ||
int | nprobe = 1 , |
||
int | search_type = 1 |
||
) | const |
Perform search only on level 0, given the starting points for each vertex.
search_type | 1:perform one search per nprobe, 2: enqueue all entry points |
Definition at line 355 of file IndexHNSW.cpp.