Initialize
接口定义
Status ScannInterface::Initialize(ConstSpan<float> dataset, DatapointIndex n_points, const std::string& config, int training_threads);
接口用途
用于构建索引(与开源算法方法保持一致)。
参数说明
参数名称 |
数据类型 |
描述 |
取值范围 |
|
|---|---|---|---|---|
dataset |
ConstSpan<float> |
底库向量。 |
限制非空。 |
|
n_points |
DatapointIndex |
底库向量的数量。 |
限制与dataset的长度保持一致,其中“dataset”表示底库向量。 |
|
config |
const std::string& |
构建索引所需的配置文件,包含所有配置参数。 |
- |
|
training_threads |
int |
构建索引时的线程数。 |
大于等于1。 |
|
其中,“config”由create_config.py结合以下参数生成,参数说明如下所示:
参数名称 |
数据类型 |
描述 |
取值范围 |
|
|---|---|---|---|---|
n_leaves |
int |
IVF分区总子空间个数。 |
大于等于1。 |
|
nb |
int32_t |
底库向量的数量。 |
限制与dataset的长度保持一致,其中“dataset”表示底库向量。 |
|
metricType |
std::string |
向量的距离类型。 |
“dot_product”或“squared_l2” |
|
dims_per_block |
int |
PQ量化合并维度数。 |
[1, dim],其中“dim”表示底库向量的维度。 |
|
avq_threshold |
float |
不对称分桶参数,仅对L2(squared_l2)数据集生效。 |
[0,1] |
|
dim |
int32_t |
底库向量的维度。 |
限制与dataset的维度保持一致,其中“dataset”表示底库向量。 |
|
topK |
int |
最终返回结果数量。 |
大于等于1。 |
|
soar_lambda |
float |
控制正交性的参数,仅对IP(dot product)数据集生效。 |
大于0,当值为“-1”时表示不开启此参数。 |
|
overretrieve_factor |
float |
指定过检索因子,与“soar_lambda”一起使用,仅对IP(dot_product)数据集生效。 |
[1,2],当值为“-1”时表示不开启此参数。 |
|
python create_config.py + std::to_string(n_leaves) + " "
+ std::to_string(nb) + " "
+ metricType + " "
+ std::to_string(dims_per_block) + " "
+ std::to_string(avq_threshold) + " "
+ std::to_string(dim) + " "
+ std::to_string(topK) + " "
+ std::to_string(soar_lambda) + " "
+ std::to_string(overretrieve_factor)
返回值
数据类型 |
说明 |
|---|---|
Status |
表示方法执行状态,通过status.ok()判断是否成功。 |