Search (AscendIndex)

API definition

void Search(std::vector<AscendIndex *> indexes, idx_t n, const float *x, idx_t k,float *distances, idx_t *labels, bool merged);

Function

Queries the feature vectors for multiple AscendIndex libraries and returns the distance and IDs of the most similar k features based on the input feature vectors.

The following algorithms are supported:

  • AscendIndexSQ subtype derived from Index (QuantizerType is QT_8bit)
  • AscendIndexFlat subtype derived from Index (FlatIP, FlatL2)
  • AscendIndexIVFSP subtype derived from Index

Input

std::vector<AscendIndex *> indexes: multiple indexes to perform retrieval.

idx_t n: number of queries for retrieval.

const float *x: query vectors for retrieval.

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

bool merged: whether to merge the retrieval results of multiple indexes.

Output

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

idx_t *labels: IDs of the first k nearest vectors that are queried.

Return value

N/A

Restrictions

  • Indexes involved in retrieval must be created on the same card.
  • The following lists the supported indexes types:
    • indexes: pointer to AscendIndexSQ, with QuantizerType being QT_8bit; 0 < indexes.size() ≤ 10000.
    • indexes: pointer to AscendIndexIVFSP, with QuantizerType being QT_8bit, MetricType being METRIC_L2; 0 < indexes.size() ≤ 10000. The AscendIndexIVFSP indexes involved in retrieval must share the same codebook at the shared memory address. You can create an instance by using the shared codebook constructor or loadAllData provided by AscendIndexIVFSP.
    • indexes: pointer to AscendIndexFlat; 0 < indexes.size() ≤ 10000.
  • The value of n cannot exceed 1024.
  • The value of k cannot exceed 1024.
  • x must be a non-null pointer with a length of dim × n. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.
  • distances and labels must be non-null pointers and meet the following requirements:
    • If merged is set to true, the length must be k × n. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.
    • If merged is set to false, the length must be indexes.size() × k × n. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.