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 |
IVF分区总子空间个数。 |
int |
大于等于1。 |
|
nb |
底库向量的数量。 |
int32_t |
限制与dataset的长度保持一致,其中“dataset”表示底库向量。 |
|
metricType |
向量的距离类型。 |
std::string |
“dot_product”或“squared_l2” |
|
dims_per_block |
PQ量化合并维度数。 |
int |
[1, dim],其中“dim”表示底库向量的维度。 |
|
avq_threshold |
不对称分桶参数,仅对L2(squared_l2)数据集生效。 |
float |
[0,1] |
|
dim |
底库向量的维度。 |
int32_t |
限制与dataset的维度保持一致,其中“dataset”表示底库向量。 |
|
topK |
最终返回结果数量。 |
int |
大于等于1。 |
|
soar_lambda |
控制正交性的参数,仅对IP(dot product)数据集生效。 |
float |
大于0,当值为“-1”时表示不开启此参数。 |
|
overretrieve_factor |
指定过检索因子,与“soar_lambda”一起使用,仅对IP(dot_product)数据集生效。 |
float |
[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()判断是否成功。 |