昇腾社区首页
中文
注册

AscendIndexIVFSP接口

将参数“config”传递给函数前,请根据实际情况先设置conf.handleBatch、conf.nprobe、conf.searchListSize的值(字段描述参考公共参数)。

其中conf.handleBatch、conf.searchListSize值需与IVFSP业务算子模型文件生成中的<nprobe handle batch>、<search list size>保持一致。

conf.filterable(继承自AscendIndexConfig)默认为“false”,如果要使用search_with_filter()接口,需设置conf.filterable = true“conf.filterable”设置为“true”将在NPU卡上存储额外的信息,消耗更多的NPU卡上内存。

API定义

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());

功能描述

AscendIndexIVFSP的构造函数,根据“config”中配置的值设置Device侧资源。

输入

int dims:AscendIndexIVFSP管理的一组特征向量的维度。

int nonzeroNum:特征向量压缩降维后非零维度个数。

int nlist:聚类中心的个数,与IVFSP业务算子模型文件生成中的<centroid num>参数值对应。

const char *codeBookPath:IVFSP使用的码本文件路径。

faiss::ScalarQuantizer::QuantizerType qType:标量量化类型,当前仅支持“ScalarQuantizer::QuantizerType::QT_8bit”。

faiss::MetricType metric:AscendIndex在执行特征向量相似度检索的时候使用的距离度量类型。当前“faiss::MetricType metric”仅支持“METRIC_L2”

AscendIndexIVFSPConfig:Device侧资源配置。

输出

返回值

约束说明

  • 训练生成码本时的<dim>、<nonzero num>、<centroid num> 值应该与此函数的参数“dims”“nonzeroNum”“nlist”对应。
  • “codeBookPath”加载的码本应该与此函数的参数“dims”“nonzeroNum”“nlist”对应,且程序的执行用户是码本文件的属主;且码本文件不能为软链接。
  • 当dims ∈ {64, 128, 256}时,nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384};当dims ∈ {512, 768}时,nlist∈ {256, 512, 1024, 2048}。
  • “nonzeroNum”需为16的倍数且小于等于min(128, dims)。
  • metric ∈ {faiss::MetricType::METRIC_L2}。

API定义

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());

功能描述

AscendIndexIVFSP的构造函数,根据“config”中配置的值设置Device侧资源。

输入

int dims:AscendIndexIVFSP管理的一组特征向量的维度。

int nonzeroNum:特征向量压缩降维后非零维度个数。

int nlist:聚类中心的个数,与IVFSP业务算子模型文件生成中的<centroid num>参数值对应。

const AscendIndexIVFSP &codeBookSharedIdx:共享码本的AscendIndexIVFSP对象。

faiss::ScalarQuantizer::QuantizerType qType:标量量化类型,当前仅支持“ScalarQuantizer::QuantizerType::QT_8bit”。

faiss::MetricType metric:AscendIndex在执行特征向量相似度检索的时候使用的距离度量类型。当前“faiss::MetricType metric”仅支持“METRIC_L2”

AscendIndexIVFSPConfig:Device侧资源配置。

输出

返回值

约束说明

  • 训练生成码本时的<dim>、<nonzero num>、<centroid num> 值应该与此函数的参数“dims”“nonzeroNum”“nlist”对应。
  • codeBookSharedIdx共享码本的码本配置要与当前Index的码本配置相同,且配置相同的Device资源。
  • 当dims ∈ {64, 128, 256}时,nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384};当dims ∈ {512, 768}时,nlist∈ {256, 512, 1024, 2048}。
  • “nonzeroNum”需为16的倍数且小于等于min(128, dims)。
  • metric ∈ {faiss::MetricType::METRIC_L2}。

API定义

AscendIndexIVFSP (const AscendIndexIVFSP&) = delete;

功能描述

声明此index拷贝构造函数为空,即不可拷贝类型。

输入

const AscendIndexIVFSP&:常量AscendIndexIVFSP。

输出

返回值

约束说明

API定义

virtual ~AscendIndexIVFSP();

功能描述

AscendIndexIVFSP的析构函数,销毁AscendIndexIVFSP对象,释放资源。

输入

输出

返回值

约束说明

API定义

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

功能描述

AscendIndexIVFSP的构造函数,根据“config”中配置的值设置Device侧资源。

输入

  • int dims:AscendIndexIVFSP管理的一组特征向量的维度。
  • int nonzeroNum:特征向量压缩降维后非零维度个数。
  • int nlist:聚类中心的个数,与IVFSP章节的“IVFSP业务算子模型文件生成”中的<centroid num>参数值对应。
  • faiss::ScalarQuantizer::QuantizerType qType:标量量化类型,当前仅支持“ScalarQuantizer::QuantizerType::QT_8bit”。
  • faiss::MetricType metric:AscendIndex在执行特征向量相似度检索时使用的距离度量类型。当前“faiss::MetricType metric”仅支持“METRIC_L2”。
  • AscendIndexIVFSPConfig:Device侧资源配置。

输出

返回值

约束说明

  • 当dims ∈ {64, 128, 256}时,nlist∈ {256, 512, 1024, 2048, 4096, 8192, 16384};当dims ∈ {512, 768}时,nlist∈ {256, 512, 1024, 2048}。
  • “nonzeroNum”需为16的倍数且小于等于min(128, dims)。
  • metric ∈ {faiss::MetricType::METRIC_L2}。