Milvus 官方指南:什么时候该用 HNSW 索引
做 RAG 或实时推荐、正在选向量索引的工程师可以看这篇。Milvus 官方把 HNSW 的 M、efConstruction、ef 三个参数讲清楚了,还给出内存不够时的 HNSW_PQ、IVF_PQ 和 DiskANN 替代方案,比看文档省时间。
Milvus 官方发文说明 HNSW 索引的适用场景:当向量与图结构可以完整放进内存、需要低延迟高召回时,HNSW 是首选,典型场景包括实时推荐和 RAG 检索。其原理是分层图搜索,上层引导搜索方向,底层在邻域内精细查找。
文中拆解了三个关键参数:M 控制图连接密度,增大可提升召回但增加内存并拖慢建索引;efConstruction 控制建图时的候选邻居池大小;ef 控制查询时的搜索广度,调大 ef 可提升召回,代价是延迟上升,而且不用重建索引。
若内存紧张,可用 HNSW_SQ 或 HNSW_PQ 压缩向量;数据集超出内存则建议在高速 SSD 上基准测试 DiskANN。官方建议先用代表性查询调 ef,用精确搜索结果测 recall@k,并在预期并发下跟踪 p95 延迟。
𝗪𝗵𝗲𝗻 𝘀𝗵𝗼𝘂𝗹𝗱 𝘆𝗼𝘂 𝘂𝘀𝗲 𝗛𝗡𝗦𝗪 𝗶𝗻 𝗠𝗶𝗹𝘃𝘂𝘀? HNSW is a good starting point for low-latency, high-recall vector search when the vectors and the graph fit comfortably in RAM. Think real-time recommendations or RAG retrieval. HNSW searches a layered graph. The upper layers guide it toward promising areas, and the bottom layer searches those neighborhoods in more detail. • 𝗠 controls how densely connected the graph is. More links can improve recall, use more RAM, and slow down index builds. • 𝗲𝗳𝗖𝗼𝗻𝘀𝘁𝗿𝘂𝗰𝘁𝗶𝗼𝗻 controls how many candidate neighbors HNSW considers during the build. A larger pool can improve graph quality and takes longer to evaluate. • 𝗲𝗳 controls how broadly HNSW searches at query time. Raising it can improve recall at the cost of higher latency. You can tune it without rebuilding the index. If RAM is tight, HNSW_SQ and HNSW_PQ compress the vectors while keeping the graph. For cluster-based search, IVF_FLAT keeps the original vectors and IVF_PQ compresses them. If the dataset exceeds available RAM, benchmark DISKANN on a fast SSD. Start by tuning ef on representative queries. Measure recall @k against exact search results and track p95 latency at your expected concurrency. Revisit the build settings if query-time tuning falls shor milvus.io/docs/hnsw.md us #Milvus un #VectorDatabase s #OpenSource BK28axJ #Milvus #VectorDatabase #OpenSource
本条情报归属 AITOP「技巧」核心追踪栏目。在跨区域产业观察坐标中,该动态直接关联「AI 开发者工具链、Coding Agent 与工程化实践」研究主线,反映出当前技术演进与商业落地的最新风向。涉及核心实体与技术议题包括:Milvus、HNSW、向量数据库、RAG,读者可通过下方标签进入对应专题页查阅历史脉络与关联对比。
信源核验说明:本文原始线索采编自「Milvus」(@milvusio),经 AITOP 多维评分管线结构化提炼。