MultiSearchWithMask

API definition

APP_ERROR MultiSearchWithMask(std::vector<AscendIndexVStar*>& indexes, const AscendIndexSearchParams& params, const std::vector<uint8_t>& mask, bool merge);

Function

Queries the feature vectors for multiple AscendIndexVStar libraries and returns the distance and IDs of the most similar topK features based on the input feature vectors. Also, it determines whether the database is involved in distance calculation based on mask. mask is a bit string of 0 and 1. Each bit indicates whether the corresponding feature in the database is involved in distance calculation. The value 0 indicates that the feature is not involved, and the value 1 indicates that the feature is involved.

Input

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

const AscendIndexSearchParams& params: search parameter. For details, see AscendIndexSearchParams.

size_t n: number of feature vectors to be queried.

std::vector<float>& queryData: feature vector data.

int topK: number of the most similar results to be returned.

const std::vector<uint8_t>& mask: feature mask.

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

Output

std::vector<float>& dists: distance between a vector and the topK nearest vectors.

std::vector<int64_t>& labels: IDs of the topK nearest vectors that are queried.

Return value

APP_ERROR: return status. For details, see Return Code Reference.

Restrictions

  • n ∈ (0, 10000]. Ensure that the value of n × dim × sizeof(float) is less than the remaining memory of the card. Otherwise, the retrieval may fail due to insufficient memory.
  • Length of queryDatan × dim
  • topK ∈ (0, 4096]
  • dists and labels must meet the following requirements:
    • merge = true: The length must be greater than or equal to n × topK.
    • merge = false: The length must be greater than or equal to indexes.size() × n × topK.
  • mask: The length must be greater than or equal to n × ceil (ntotal_max/8), where ntotal_max indicates the maximum number of features among all indexes.
  • indexes must meet the requirement: 0 < indexes.size() ≤ 150.