0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · 课时

索引、过滤与混合搜索

理解索引类型,将元数据过滤与相似度结合,并通过混合搜索融合关键词检索和向量检索,从而让向量搜索在大规模场景下既快速又精准。

索引、过滤与混合搜索 是 CoddyKit 上的免费 LLM Apps in Production (RAG + Vector DB + Caching) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 LLM Apps in Production (RAG + Vector DB + Caching) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The Scale Problem

Comparing a query against millions of vectors one by one is too slow for production. Vector databases use indexes to find near neighbors quickly without scanning everything.

Approximate Nearest Neighbors

Most vector indexes are approximate (ANN): they trade a tiny bit of accuracy for huge speed gains. For RAG, near-perfect recall at fast speed is a great deal.

HNSW Indexes

HNSW (Hierarchical Navigable Small World) is a popular graph-based index. It navigates layers of connections to reach neighbors fast, balancing speed and accuracy via tunable parameters.

IVF Indexes

IVF clusters vectors into cells; a query only searches the closest cells. The nprobe parameter trades recall for speed by controlling how many cells to check.

Metadata Filtering

Pure similarity can return the wrong scope — old versions, other tenants. Storing metadata with each vector lets you filter results to the right subset.

results = store.similarity_search(
    query,
    k=4,
    filter={'tenant': 'acme', 'lang': 'en'}
)

Pre vs Post Filtering

Filters apply two ways:

  • Pre-filter: restrict candidates before the ANN search (more correct)
  • Post-filter: search, then drop non-matches (may return too few)

Prefer pre-filtering when the DB supports it.

Where Vector Search Struggles

Vectors capture meaning but can miss exact terms — product codes, names, acronyms. A query for SKU-9F may semantically match nothing useful.

Hybrid search fixes this.

What Is Hybrid Search?

Hybrid search runs both keyword (e.g. BM25) and vector search, then merges the results. You get semantic understanding plus exact-term precision.

Combining Scores with RRF

Reciprocal Rank Fusion merges the two ranked lists by rewarding items ranked high in either, without needing comparable score scales.

def rrf(ranks, k=60):
    return sum(1 / (k + r) for r in ranks)

Tuning the Balance

Many databases let you weight keyword vs vector contributions (alpha). Term-heavy domains lean keyword; conceptual queries lean vector. Tune on your test set.

results = store.similarity_search(query, k=4, alpha=0.5)

Operational Tips

For healthy vector search at scale:

  • Rebuild or update indexes as data grows
  • Keep embeddings and index dimensions consistent
  • Benchmark recall and latency together

Quick Check

Test your vector database knowledge.

Recap

You learned to scale and sharpen vector search:

  • ANN indexes like HNSW and IVF make search fast
  • Metadata filters scope results; prefer pre-filtering
  • Hybrid search blends keyword and vector retrieval
  • Fuse rankings with RRF and tune the balance
  • Maintain indexes and benchmark recall vs latency

These techniques keep retrieval both fast and accurate in production.

常见问题解答

「索引、过滤与混合搜索」课时是免费的吗?

是的 — 「索引、过滤与混合搜索」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 LLM Apps in Production (RAG + Vector DB + Caching) 课程的其余内容,请升级到 CoddyKit PRO。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。

「索引、过滤与混合搜索」这节课中我会学到什么?

理解索引类型,将元数据过滤与相似度结合,并通过混合搜索融合关键词检索和向量检索,从而让向量搜索在大规模场景下既快速又精准。 你通过在浏览器中直接运行的动手代码来练习 LLM Apps in Production (RAG + Vector DB + Caching),全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 LLM Apps in Production (RAG + Vector DB + Caching) 需要有经验吗?

无需任何先前经验。CoddyKit 上的 LLM Apps in Production (RAG + Vector DB + Caching) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「索引、过滤与混合搜索」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 LLM Apps in Production (RAG + Vector DB + Caching) 课中编写并运行代码吗?

能。每节 LLM Apps in Production (RAG + Vector DB + Caching) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 向量数据库的必要性
  2. 向量嵌入与相似度搜索
  3. 集成向量数据库
  4. 索引、过滤与混合搜索
← 返回 LLM Apps in Production (RAG + Vector DB + Caching)