Files
nexus/wiki/concepts/Retrieval.md

35 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Retrieval"
type: concept
tags: [rag, retrieval, vector-search, similarity]
last_updated: 2025-01-16
---
## Definition
Retrieval检索阶段是 RAG Pipeline 的第二步根据用户问题的语义向量Embedding Vector在向量数据库中按相似度找出 Top-k 个最相关的文档块Split
## Process
1. **Query Embedding**:将用户问题通过同一个 Embedding Model 转化为语义向量
2. **Vector Search**:在 Vector Store 中按相似度(余弦相似度/点积/欧氏距离)检索最接近的 k 个向量
3. **Result Selection**返回对应的原始文本块Split作为上下文
## Key Parameters
- **Top-kk值**决定返回多少个最相关的文档块k 过小可能遗漏关键信息k 过大则引入噪声
- **Similarity Metric**:余弦相似度最常用,适合方向性语义匹配;点积适合归一化向量;欧氏距离适合几何距离度量
## In RAG Pipeline
- **上游**:依赖 Indexing 阶段构建的向量数据库
- **下游**:检索结果传递给 Generation 阶段作为上下文
## Challenges
- **语义鸿沟**:用户问题的措辞与文档中相关内容可能不同(词汇不匹配)
- **上下文窗口限制**Top-k 个文档块的总 token 数不能超过 LLM 的 Context Window
- **噪声召回**:向量相似度高但实际无关的文档块可能被召回
## Related Concepts
- [[RAG]] — Retrieval 是 RAG Pipeline 的第二阶段
- [[Vector Store]] — 检索的数据库后端
- [[Embedding]] — 检索的向量来源
- [[Generation]] — Retrieval 的下一阶段,接收检索结果作为上下文
- [[Hybrid Search]] — 结合向量检索与关键词检索以弥补单一向量检索的不足