The Untaught Lessons of RAG Retrieval: Cosine Is Not the Foundation

· Source: Towards Data Science · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Data Science & Analytics · Depth: Advanced, medium

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

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

Topics

Code references

Best for: AI Engineer, Machine Learning Engineer, AI Architect

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.