search

API definition

void search(idx_t n, const uint8_t *x, idx_t k, int32_t *distances, idx_t *labels, const SearchParameters *params) const override;

Function

Queries feature vectors. It returns the IDs and distances of the most similar k features based on the input feature vectors.

Input

idx_t n: number of query vectors.

const uint8_t *x: query vectors.

idx_t k: number of the most similar results to be returned.

const SearchParameters *params (not supported now): optional parameter in Faiss. The default value is nullptr.

Output

int32_t*distances: distance between a vector and the first k nearest vectors.

idx_t *labels: IDs of k nearest vectors.

Return value

N/A

Restrictions

  • The length of the queried feature vector data x must be dims/8 × n, and the lengths of distances and labels must be k × n. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.
  • 0 < n ≤ 1e9; 0 < k ≤ 1e5 (n ≤ 1e9 is far greater than the actual available resources. Select a proper number of query vectors based on the service scenario.)

API definition

void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const;

Function

Queries feature vectors and returns the IDs and distances of the most similar k features based on the input feature vectors. It can be used to search for binary features and retrieval features of the float type.

Input

idx_t n: number of query vectors.

const float *x: query vector.

idx_t k: number of the most similar results to be returned.

Output

float *distances: distance between a query vector and the first k nearest vectors.

idx_t *labels: IDs of k nearest vectors.

Return value

N/A

Restrictions

  • The length of the queried feature vector data x must be dims × n, and the lengths of distances and labels must be k × n. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.
  • 0 < n ≤ 1e9; 0 < k ≤ 1e5 (n ≤ 1e9 is far greater than the actual available resources. Select a proper number of query vectors based on the service scenario.)