SearchWithFilter (Multi-Filter AscendIndex)

API definition

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

Function

Performs retrieval of multiple indexes and returns the IDs of the most similar k features based on the input feature vectors.

It also provides the CID-based filtering function. filters is a pointer array whose size is n. Each pointer in filters points to a uint32_t array with a length of 6 × indexes.size(). Every six uint32_t arrays form a filter. The first four digits (128 bits) of each filter indicate the corresponding CID, and the last two digits indicate the left-closed range of the corresponding timestamp, that is, [x, y).

Input

std::vector<Index *> 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.

void *filters[]: filter criteria.

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.
  • 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.
  • filters must be a pointer array whose length is n, and each pointer in the array points to a uint32_t array whose length is indexes.size() × 6. Otherwise, an out-of-bounds read/write error may occur, causing program breakdown.