The Untaught Lessons of RAG Retrieval: Cosine Is Not the Foundation
Summary
This article challenges the mainstream RAG retrieval approach (embed question, top-k by cosine, optional rerank). It proposes an alternative for enterprise RAG, treating retrieval as filtering on structured tables (`line_df` and `toc_df`) rather than free text search. The core idea is a three-signal parallel retrieval system: keyword search on lines, TOC reasoning, and embeddings as an optional fallback. This approach is detailed through six "untaught lessons": retrieval is filtering, not searching; anchor and context should be kept separate; embeddings come last; keywords prove absence while embeddings cannot; co-occurrence beats BM25 on narrow corpora; and one LLM pass over the TOC catches paraphrases. This method is supported by runnable companion notebooks on GitHub and is applicable across various sectors.
Key takeaway
For AI Engineers building enterprise RAG systems, abandon the default chunk-embed-cosine approach. Instead, treat retrieval as filtering on structured data like `line_df` and `toc_df`. Prioritize deterministic keyword searches and LLM-based TOC reasoning, reserving embeddings for vocabulary mismatches. This strategy improves auditability, precision, and cost-efficiency, ensuring more reliable answers and clearer absence proofs in narrow corporate datasets.
Key insights
Enterprise RAG retrieval should prioritize structured filtering and keyword signals, using embeddings as a last resort.
Principles
- Retrieval is filtering, not searching.
- Separate anchor from context for precision.
- Keywords prove absence; embeddings cannot.
Method
Implement a three-signal parallel retrieval pipeline: keyword search on `line_df`, LLM reasoning on `toc_df`, and embedding cosine as an optional fallback, with an LLM arbiter for final ranking.
In practice
- Use `line_df` and `toc_df` for structured filtering.
- Employ keyword search for deterministic absence proof.
- Apply LLM for TOC reasoning to catch paraphrases.
Topics
- RAG Retrieval
- Enterprise AI
- Document Intelligence
- Keyword Search
- Table of Contents Reasoning
- Embedding Models
Code references
Best for: AI Engineer, Machine Learning Engineer, AI Architect
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.