首页/AI/RAG 与向量库速查/nprobe 与 IVF 召回权衡
Embedding 与检索50 条

nprobe 与 IVF 召回权衡

nprobe 决定 IVF 查询扫描多少个聚类:nprobe 增大覆盖更多候选、召回上升但延迟增加;常用小数据集先测精确基线,再用网格搜索在召回-延迟曲线上选择工作点。

RAG 与向量库速查AI更新于 2026-10-12

nprobe 网格搜索

nprobe 网格搜索
import faiss, numpy as np

d = 256
index = faiss.IndexIVFFlat(faiss.IndexFlatL2(d), d, 128)
index.train(np.random.rand(100000, d).astype("float32"))
index.add(np.random.rand(500000, d).astype("float32"))
q = np.random.rand(100, d).astype("float32")
for nprobe in (1, 4, 8, 16, 32, 64):
    index.nprobe = nprobe
    D, I = index.search(q, 10)      # 记录 recall@10 与 p95 延迟
nprobe 与 nlist 配对比曲线更能说明问题:nlist 变大后,同一 nprobe 覆盖比例会变小。

易错点

  • 生产库直接把 nprobe 设为 1,省了延迟却丢掉大量相关文档
  • 调完 nprobe 不回填评测集基线,无法判断改动是收益还是波动

数据来源与参考

  • FAISS wiki(IVF 参数)
  • Milvus 官方文档(IVF_FLAT 的 nprobe)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌