Retrieval-Augmented Generation (RAG)

Sparse Retrieval

Definition

Sparse retrieval encompasses traditional information retrieval approaches where documents and queries are represented as high-dimensional vectors where most dimensions correspond to vocabulary terms and most values are zero (only terms that appear in the document have non-zero values). The most prominent sparse retrieval algorithms are BM25 (Best Match 25) and TF-IDF (Term Frequency-Inverse Document Frequency). Sparse retrieval matches documents to queries based on shared terms, weighted by how frequently the term appears in the document and how rare it is across the full corpus. Despite being the 'old' approach, sparse retrieval remains highly competitive for queries involving specific technical terms, product names, error codes, or precise phrases.

Why It Matters

Sparse retrieval provides complementary strengths to dense retrieval — they fail on different query types. Dense retrieval excels when semantics matter more than exact terms; sparse retrieval excels when exact terms matter (error codes, product names, technical identifiers, proper nouns). A RAG system relying only on dense retrieval will miss documents that contain the exact product model number or error code the user mentioned. Combining sparse and dense retrieval (hybrid retrieval) captures the strengths of both approaches and consistently outperforms either method alone.

How It Works

Sparse retrieval indexes documents by building an inverted index that maps each vocabulary term to the documents containing it, along with frequency and weighting information. When a query arrives, each query term is looked up in the inverted index, and documents are scored based on how well their term distribution matches the query. BM25 scoring uses a formula that rewards: documents where query terms appear frequently (TF component), documents where query terms are rare across the corpus (IDF component), and applies length normalization so longer documents are not unfairly rewarded for containing more terms. Inverted index search is extremely fast and memory-efficient.

Sparse vs Dense Retrieval — Vector Representation Comparison

Sparse Vector

BM25, SPLADE, TF-IDF

Dimensions:30,000 dims
Non-zero:~20 non-zero
Strength:Exact term matching
Best for:Keyword & hybrid search

Dense Vector

text-embedding-3, BGE

Dimensions:768–1536 dims
Non-zero:All non-zero
Strength:Semantic meaning
Best for:Similarity search

Sparse vector — 30,000 dimensions (simplified to 40)

Only ~20 positions are non-zero — one per matched term in the vocabulary.

Dimensionality

Sparse (BM25/SPLADE)
30,000
Dense (text-embedding-3)
1,536
Dense (BGE-base)
768

Sparse index speed

Inverted index lookup — O(k) where k = matching terms. Near-instant for exact term queries.

Dense index speed

ANN search over all vectors — fast but requires HNSW or IVF index structure.

Real-World Example

A 99helpers customer finds that their dense-only RAG system struggles when users cite specific error codes (e.g., 'error 403', 'exception NullPointerException') — the dense embedding model treats error codes as similar to other words, while they should be treated as precise identifiers. After adding BM25 sparse retrieval in a hybrid configuration, queries containing exact error codes now reliably retrieve the specific troubleshooting articles for those errors. Customer-reported resolution rate for error-code queries increases from 52% to 81%.

Common Mistakes

  • Dismissing sparse retrieval as obsolete — BM25 is highly competitive for precise queries and remains the strongest baseline for many retrieval tasks
  • Using sparse retrieval alone without semantic search — keyword matching misses relevant content that uses synonyms or different phrasings
  • Implementing sparse retrieval without stemming or normalization — 'running' and 'run' should match; apply linguistic normalization before indexing

Related Terms

Ready to build your AI chatbot?

Put these concepts into practice with 99helpers — no code required.

Start free trial →
What is Sparse Retrieval? Sparse Retrieval Definition & Guide | 99helpers | 99helpers.com