New Tool Radar

AI Concepts

How to Decide When Sparse Keyword Vectors Beat Dense Embeddings for Exact-Term Retrieval

Test both on questions with codes and names, keep dense search for meaning, and use sparse search when the exact term is the answer.

Schematic with three steps: Run the exact-term questions on both; Run the meaning questions on both; Pick the search per question type, or.

Dense vectors match meaning, so they find an answer phrased differently, but they can miss an exact term. Sparse vectors match exact tokens: Qdrant supports sparse vectors for exact token match, and Pinecone notes that sparse-vector search matches specific terms like product codes, error strings and names. The choice is not a matter of taste: questions with codes, names and identifiers need sparse search, while questions about ideas need dense search. Test both on your own questions.

What you need

  • Test questions split into exact-term questions and meaning questions
  • An index that can run both dense and sparse search
  • The known correct document for each test question

Step 1: Run the exact-term questions on both

Run the questions that contain a code, SKU, error string or proper name against dense-only search and sparse-only search, and record the rank of the correct document in each.

Step 2: Run the meaning questions on both

Do the same for questions that describe an idea without naming it, such as asking how to return an item without using the word refund. Dense search should win these; sparse search should lose them.

Step 3: Pick the search per question type, or blend them

Use sparse search where exact terms decide, dense search where meaning decides, and a hybrid blend when your questions mix both. One search type for everything will fail one half of your questions.

Worked example: synthetic sparse versus dense test on 4 questions

The table below is a synthetic example. It shows the expected result of comparing sparse and dense search; no search was run.

Question Dense rank Sparse rank
Error code TS-999 Not found 1
Product SKU A-42 Not found 2
How to return an item 1 Not found
Cheapest plan for a team 2 Not found

Expected result (UNTESTED). sparse search wins the two exact-term questions and dense search wins the two meaning questions. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Sparse search needs the exact term to appear in the document; a synonym will not match.
  • Dense search needs the idea to be in the embedding; a rare code may be invisible to it.
  • Sentence Transformers also offers sparse encoder models, so the same idea works with local models.
  • A hybrid blend costs two searches per query, so budget for the extra latency.

Sources

See all