Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

索引参数

本页汇总 VSAG 各索引类型的常用参数。完整枚举请参考源码:

  • 构建参数键:src/constants.cpp
  • 公开常量:include/vsag/constants.h
  • 每个索引的示例:examples/cpp/*_index_*.cpp(例如 103_index_hgraph.cpp

通用参数

所有索引在构建时都需要提供以下顶层字段:

字段取值说明
dim正整数向量维度,构建后不可更改
dtypefloat32 / fp16 / bf16 / int8向量数据类型,决定索引内部表示
metric_typel2 / ip / cosine距离度量

HGraph

HGraph 的构建参数使用通用的 index_param 键(参见 examples/cpp/103_index_hgraph.cpp); hgraph 键则保留给搜索期参数。

{
    "dim": 128,
    "dtype": "float32",
    "metric_type": "l2",
    "index_param": {
        "base_quantization_type": "fp32",
        "max_degree": 32,
        "ef_construction": 400
    }
}
字段典型值说明
max_degree16~48每节点最大出边数
ef_construction200~500构建阶段候选集大小,越大召回越高、构建越慢
base_quantization_typefp32 / fp16 / bf16 / sq8 / sq4 / pq主存储的量化策略 —— 支持的全部取值见量化章节

搜索时:

{"hgraph": {"ef_search": 100}}

hgraph 搜索参数还接受 brute_force_threshold[0.0, 1.0] 区间的 float, 默认 0.0)。当取值 > 0 且当前请求的 filter 的 ValidRatio() 不超过该 阈值时,HGraph 会跳过图遍历,直接在通过过滤的 id 上做精确暴扫。详见 HGraph 索引文档

LazyHGraph

LazyHGraph 的构建参数可以放在顶层 lazy_hgraph 对象中(推荐,语义更清晰),也可以放在 通用的 index_param 对象中。hgraph 子对象会转交给转换后的内部 HGraph。

{
    "dim": 128,
    "dtype": "float32",
    "metric_type": "l2",
    "lazy_hgraph": {
        "transition_threshold": 1000,
        "hgraph": {
            "base_quantization_type": "sq8",
            "max_degree": 26,
            "ef_construction": 100
        }
    }
}
字段典型值说明
transition_threshold1000 或按业务规模设置从精确 flat 搜索转换到 HGraph 的正整数向量数量阈值
hgraphHGraph 构建对象graph 阶段的参数;见 HGraph

LazyHGraph 只支持 dtype: "float32"。搜索参数使用 hgraph 对象,例如 {"hgraph": {"ef_search": 100}}。详见 LazyHGraph 索引文档

hgraph 搜索参数还接受以下 filter 相关参数:

参数类型默认值说明
skip_ratiofloat0.2控制带 filter 搜索时跳过候选检查的比例,取值范围为 [0.0, 1.0]。值越大,跳过越激进,搜索越快但可能影响召回。
skip_strategystring"deterministic_accumulative"跳过策略。支持 "random""deterministic_accumulative"

IVF

{
    "ivf": {
        "nlist": 4096,
        "base_quantization_type": "sq8",
        "nprobe": 32
    }
}

Brute Force

{"brute_force": {}}

无需额外参数。

Pyramid

Pyramid 支持按 tag 组织多棵子图:

{
    "pyramid": {
        "tag_dim": 1,
        "max_degree": 24,
        "ef_construction": 300
    }
}

SINDI(稀疏向量)

{
    "sindi": {
        "top_k": 32,
        "doc_prune_ratio": 0.1
    }
}

运行期参数

除构建参数外,Index::TuneSearchParam 可在运行时调整 ef_searchnprobe 等参数。参考 优化器 与各 examples/cpp/3xx_feature_*.cpp 示例。