首页/AI/RAG 与向量库速查/efSearch 召回与延迟调优
Embedding 与检索50 条

efSearch 召回与延迟调优

efSearch 控制 HNSW 查询时候选队列的长度:数值越大越接近精确搜索、延迟越高;调优时从 32 或 64 起测,在召回曲线趋缓处停下,并把取值写入服务配置固化。

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

用召回率选 efSearch

用召回率选 efSearch
import faiss, numpy as np

d = 128
xb = np.random.rand(50000, d).astype("float32")
q = np.random.rand(200, d).astype("float32")
flat = faiss.IndexFlatL2(d); flat.add(xb)
_, exact = flat.search(q, 10)                  # 精确 top-10 基线
index = faiss.IndexHNSWFlat(d, 32); index.add(xb)
for ef in (16, 32, 64, 128, 256):
    index.hnsw.efSearch = ef
    _, got = index.search(q, 10)
    # 与 exact 对比算 recall@10,记录 (ef, recall, 平均延迟)
把 efSearch 作为一个整体档位(如 64)在部署配置里固定,改动前先跑评测回归。

易错点

  • 只测延迟不测召回,把参数一路调小直到答案质量明显下滑
  • 构建参数(efConstruction)与查询参数(efSearch)混为一谈,改错位置不生效

数据来源与参考

  • FAISS wiki(HNSW 参数)
  • Qdrant 官方文档(hnsw_ef 查询参数)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌