AscendIndexIVFSP

Before passing config to the function, set conf.handleBatch, conf.nprobe, and conf.searchListSize based on your requirements. For details about the field description, see Common Parameters.

The values of conf.handleBatch and conf.searchListSize must be the same as those of <nprobe handle batch> and <search list size> specified in the service operator model file in IVFSP.

The default value of conf.filterable (inherited from AscendIndexConfig) is false. To use the search_with_filter() API, you need to set conf.filterable to true. If conf.filterable is set to true, additional information is stored on the NPU, consuming more NPU memory.

API definition

AscendIndexIVFSP(int dims, int nonzeroNum, int nlist, const char *codeBookPath, faiss::ScalarQuantizer::QuantizerType qType = ScalarQuantizer::QuantizerType::QT_8bit, faiss::MetricType metric = MetricType::METRIC_L2, AscendIndexIVFSPConfig config = AscendIndexIVFSPConfig());

Function

Constructor of AscendIndexIVFSP. The device resources are set based on the value configured in config.

Input

int dims: dimensions of a group of feature vectors managed by AscendIndexIVFSP.

int nonzeroNum: number of non-zero dimensions after feature vector compression and dimension reduction.

int nlist: number of cluster centroids, which corresponds to the value of <centroid num> in Generating the IVFSP Service Operator Model File.

const char *codeBookPath: path of the codebook file used by the IVFSP.

faiss::ScalarQuantizer::QuantizerType qType: scalar quantization type. Currently, only ScalarQuantizer::QuantizerType::QT_8bit is supported.

faiss::MetricType metric: distance measurement type used by AscendIndex when it retrieves feature vector similarity. Currently, faiss::MetricType metric supports only METRIC_L2.

AscendIndexIVFSPConfig: resource configuration on the device.

Output

N/A

Return value

N/A

Restrictions

  • The values of <dim>, <nonzero num>, and <centroid num> during codebook generation should correspond to dims, nonzeroNum, and nlist of this function.
  • The codebook loaded by codeBookPath must correspond to dims, nonzeroNum, and nlist of this function. The program is executed by the owner of the codebook file, and the codebook file cannot be a soft link.
  • If dims ∈ {64, 128, 256}, nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384}; if dims ∈ {512, 768}, nlist∈ {256, 512, 1024, 2048}.
  • The value of nonzeroNum must be a multiple of 16 and less than or equal to min(128, dims).
  • metric ∈ {faiss::MetricType::METRIC_L2}.

API definition

AscendIndexIVFSP(int dims, int nonzeroNum, int nlist, const AscendIndexIVFSP &codeBookSharedIdx, faiss::ScalarQuantizer::QuantizerType qType = ScalarQuantizer::QuantizerType::QT_8bit, faiss::MetricType metric = MetricType::METRIC_L2, AscendIndexIVFSPConfig config = AscendIndexIVFSPConfig());

Function

Constructor of AscendIndexIVFSP. The device resources are set based on the information configured in config.

Input

int dims: dimensions of a group of feature vectors managed by AscendIndexIVFSP.

int nonzeroNum: number of non-zero dimensions after feature vector compression and dimension reduction.

int nlist: number of cluster centroids, which corresponds to the value of <centroid num> in Generating the IVFSP Service Operator Model File.

const AscendIndexIVFSP &codeBookSharedIdx: AscendIndexIVFSP object of the shared codebook.

faiss::ScalarQuantizer::QuantizerType qType: scalar quantization type. Currently, only ScalarQuantizer::QuantizerType::QT_8bit is supported.

faiss::MetricType metric: distance measurement type used by AscendIndex when it retrieves feature vector similarity. Currently, faiss::MetricType metric supports only METRIC_L2.

AscendIndexIVFSPConfig: resource configuration on the device.

Output

N/A

Return value

N/A

Restrictions

  • The values of <dim>, <nonzero num>, and <centroid num> during training of the generated codebook should correspond to dims, nonzeroNum, and nlist of this function.
  • The codebook configuration of codeBookSharedIdx must be the same as that of the current Index, and the same device resources must be configured.
  • If dims ∈ {64, 128, 256}, nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384}; if dims ∈ {512, 768}, nlist∈ {256, 512, 1024, 2048}.
  • The value of nonzeroNum must be a multiple of 16 and less than or equal to min(128, dims).
  • metric ∈ {faiss::MetricType::METRIC_L2}.

API definition

AscendIndexIVFSP (const AscendIndexIVFSP&) = delete;

Function

Declares that the copy constructor of this Index class is void, that is, it cannot be copied.

Input

const AscendIndexIVFSP&: constant AscendIndexIVFSP.

Output

N/A

Return value

N/A

Restrictions

N/A

API definition

virtual ~AscendIndexIVFSP();

Function

Destructor of AscendIndexIVFSP, which is used to destroy the AscendIndexIVFSP object and resources.

Input

N/A

Output

N/A

Return value

N/A

Restrictions

N/A

API definition

AscendIndexIVFSP(int dims, int nonzeroNum, int nlist, faiss::ScalarQuantizer::QuantizerType qType = ScalarQuantizer::QuantizerType::QT_8bit, faiss::MetricType metric = MetricType::METRIC_L2, AscendIndexIVFSPConfig config = AscendIndexIVFSPConfig());

Function

Constructor of AscendIndexIVFSP. The device resources are set based on the value configured in config.

Input

  • int dims: dimensions of a group of feature vectors managed by AscendIndexIVFSP.
  • int nonzeroNum: number of non-zero dimensions after feature vector compression and dimension reduction.
  • int nlist: number of cluster centroids, which corresponds to the value of <centroid num> for IVFSP service operator model file generation in IVFSP.
  • faiss::ScalarQuantizer::QuantizerType qType: scalar quantization type. Currently, only ScalarQuantizer::QuantizerType::QT_8bit is supported.
  • faiss::MetricType metric: distance measurement type used by AscendIndex when it retrieves feature vector similarity. Currently, faiss::MetricType metric supports only METRIC_L2.
  • AscendIndexIVFSPConfig: resource configuration on the device.

Output

N/A

Return value

N/A

Restrictions

  • If dims ∈ {64, 128, 256}, nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384}; if dims ∈ {512, 768}, nlist∈ {256, 512, 1024, 2048}.
  • The value of nonzeroNum must be a multiple of 16 and less than or equal to min(128, dims).
  • metric ∈ {faiss::MetricType::METRIC_L2}.