---
title: "关键词与向量混合检索：花钱之前"
url: https://memory.wiki/O0TNYxHW
updated: 2026-11-25T21:56:56.822Z
source: "memory.wiki"
---
# 关键词与向量混合检索：花钱之前

## 为什么「关键词与向量混合检索」对本地 RAG 很重要

保留 BM25，精确货号与 ID 才不易漏。检索增强生成通常是团队基于本地模型做的第一个正经项目，因为文档留在内网，也不用微调。它同样是小设计决定大信任的地方。

## 先做好入库

垃圾输入会产出自信的错误答案。在考虑嵌入模型之前：

- 保留结构：PDF 或 Office 文件转换后，标题、表格和列表要还在。
- 每个分块都带元数据：来源文件、章节、版本和文档日期。
- 没有负责人或没有日期的文档拒收，过期政策是负债。
- 保留原始文件，分块器改进后可以重新入库。

## 分块与检索

先用中等分块大小加一定重叠，再用你自己的问题评测，而不是照搬博客参数。中文需要按句子切分的分块器，不能套用英文的空格规则。纯向量检索会漏掉零件号、合同编号、SKU 这类精确标识，所以要在向量库旁边保留关键词索引并合并结果。政策随时间变化时，检索要偏向最新的有效版本。

## 可重复的评测

整理一组真实问题，附上标准答案和应当支撑答案的文档。每次修改分块、嵌入模型或提示词后都跑一遍，同时看答案和检索到的段落。如果正确段落没有被检索出来，提示词再怎么改也没用。

## 运维

- 备份向量库，并实际演练一次恢复。
- 按部门或客户拆分集合，方便执行权限规则。
- 记录每个回答引用了哪些来源。
- 明确助手必须拒答的内容，并公布出来。

## 一个实际例子

一家小型制造企业希望工程师能查询内部技术规范。第一版只用向量检索，经常返回错误版本的文档。团队把文档日期和版本号加进元数据，排序前过滤掉已被替代的版本，并为零件号保留关键词索引。他们还改写了分块方式，把表格单独存成记录。改完后用同一批评测问题重跑，检查正确来源是否出现在检索结果中。直到检索稳定，他们才开始花时间调整回答提示词。

相关资料可参考[本地 RAG 知识库教程](https://microaione.com/tutorials/local-rag-knowledge-base/)，另见[本地 AI 教程中心](https://microaione.com/tutorials/)。


## 速记要点

- 公布助手会拒绝做的事。
- 每次变更都写上日期和负责人。
- 引用速度之前，用自己的提示词实测。
- 所有运行时共用一个模型目录。

*作者：[本地AI 1号网](https://microaione.com/)，深圳团队，专注本地大模型软硬件、装机与私有化部署。*

---

## Summary
本地RAG系统应通过保留关键词索引来确保精确匹配，并优先优化数据入库质量与检索策略。在调整提示词之前，必须建立可重复的评测机制以确保检索结果的准确性。

## Themes
- Local RAG optimization
- Hybrid retrieval strategy
- Data ingestion quality
- Systematic evaluation

## Key takeaways
- Hybrid retrieval combining BM25 and vector search is essential for accuracy in technical document retrieval.
- Data ingestion requires preserving document structure, metadata, and strict version control to prevent the use of outdated information.
- Evaluation should be based on a fixed set of real questions and standard answers to measure the impact of changes to chunking or embedding models.
- Retrieval systems should filter out obsolete document versions before performing similarity searches.
- Operational security requires separating data collections by department or client to enforce access permissions.

## Insights
- The effectiveness of RAG is determined more by data hygiene and retrieval architecture than by prompt engineering.
- Pure vector search is insufficient for technical environments because it fails to retrieve exact identifiers like SKU or part numbers.
- Evaluation must be iterative and include both the retrieved context and the final generated answer to identify the root cause of failures.

## Open questions / gaps
- What specific metrics should be used to quantify the success of the retrieval phase versus the generation phase?

