SearchWithMask

API definition

APP_ERROR SearchWithMask(const AscendIndexSearchParams& searchParams, const std::vector<uint8_t>& mask);

Function

Queries the AscendIndexGreat feature vectors by returning distances and IDs of the most similar topK features based on the input feature vectors. You can enter an uint8 array to mask vector IDs, so that the vectors corresponding to this ID array can be excluded from retrieval.

Input

For details about the searchParams structure, 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: extra filtering mask input externally, in bits. The value 0 indicates that the feature is filtered, and the value 1 indicates that the feature is selected.

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. If the number of valid retrieval results is less than topK, the remaining invalid labels are padded with -1.

Return value

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

Restrictions

  • topK ∈ (0, 4096]
  • n ∈ (0, 10000]
  • queryData cannot be empty, and the data length must be greater than or equal to n × dim.
  • dists cannot be empty, and its pointed data length must be greater than or equal to n × topK.
  • labels cannot be empty, and its pointed data length must be greater than or equal to n × topK.
  • The total data volume specified by mask must be greater than or equal to n × ceil(nTotal/8).