Skip to content
mentoor

Topic 4 of 5 · 3 min read

Where embedding similarity misleads

Goal: Spot a search failure caused by negation, exact identifiers or a mismatched embedding model and pick a fix such as adding keyword search.

Embedding similarity measures topical closeness, not truth or exact match, so it fails on negation, numbers, exact codes, rare jargon and mixed models. A high score can sit on a wrong result.

Check yourself · 1 of 3

Why can a search for 'safe for children' return a passage that says 'not safe for children'?

Choose one answer

Why it matters

A search that looks great in a demo can fail on the queries that matter most to users. Knowing the common failure patterns lets you test for them and pick a fix before people lose trust in the results.

The common failures

  1. Negation. "The drug is safe for children" and "The drug is not safe for children" are about the same topic and use almost the same words. Their vectors are often very close. A search for one can return the other.
  2. Numbers and units. "Dose of 5 mg" and "dose of 50 mg" look nearly the same to the model. "Rent under 1,000 a month" cannot be answered by similarity alone.
  3. Exact identifiers. Order numbers, error codes, product SKUs and function names carry no meaning to match. A query for "ERR-4471" may return other errors, not that one.
  4. Rare jargon and new terms. Company-specific acronyms or terms after the model's training may be placed badly. The model has not seen enough of them to know what they mean.
  5. Mixed or changed models. Vectors from different models, or from two versions of one model, are not comparable. If you upgrade the model, re-embed everything.
  6. Language and domain gaps. A model trained mostly on English web text may do worse on legal, medical or non-English text. Check a benchmark such as MTEB for your language and task.

Fixes

  • Hybrid search. Run keyword search and embedding search together and merge the results. Keywords catch exact codes, embeddings catch paraphrases.
  • Filters. Apply structured filters first, such as date, product or country, then rank by similarity.
  • A second look. Pass the top results to a chat model or a re-ranking model and ask which truly answer the question.
  • Test on your own queries. Build a list of 30 real questions with known right answers, and measure how often the right item appears in the top 5.

Before and after

Before: A support search for "ERR-4471 on startup" returns three articles on other startup errors, because the vectors are close in topic.

After: The system adds keyword matching on the code. The article that contains "ERR-4471" now ranks first, and embeddings still handle questions in plain words.

What goes wrong

  • Trusting a high score. A score of 0.9 on a negated sentence is still the wrong answer.
  • Upgrading the model silently. New queries and old stored vectors then live on different maps.
  • Never testing edge cases. Include negations, numbers and codes in your test list.

Examples

Search failures and fixes

Query What came back Cause Fix
Is the cream safe if pregnant? An article saying it is not safe Negation Re-rank with a chat model, show the passage
Invoice INV-20931 Other invoices Exact code Add keyword search
Apartments under 900 a month Apartments at 1,500 Numbers Use a price filter
Anything after a model upgrade Odd results Mixed models Re-embed all items

Optional code: simple hybrid merge

def hybrid(query, kw_hits, vec_hits, k=5):
    # reciprocal rank fusion: reward items ranked high in either list
    score = {}
    for hits in (kw_hits, vec_hits):
        for rank, doc_id in enumerate(hits):
            score[doc_id] = score.get(doc_id, 0) + 1 / (60 + rank)
    return sorted(score, key=score.get, reverse=True)[:k]

The constant 60 is a common default. Tune it on your own test queries.

Key points

  • Embedding similarity measures topical closeness, so a negated sentence can score as very similar to the original.
  • Numbers, units and exact codes are poorly handled and are better served by keyword search or filters.
  • Rare jargon and domain-specific text can be placed badly if the model has seen little of it.
  • Changing the embedding model means re-embedding every stored text, because old and new vectors do not match.
  • Hybrid search, filters, re-ranking and a list of real test queries are the usual fixes.

Common mistakes

  • Assuming a high similarity score means the passage answers the question.
  • Using embeddings alone for order numbers, error codes and product SKUs.
  • Changing the embedding model without re-embedding the stored texts.
  • Testing only with easy queries and never with negations, numbers or codes.

Check yourself · 2 of 3

A user searches for the error code ERR-4471 and gets articles about other errors. What is the best fix?

Choose one answer

Check yourself · 3 of 3

A team upgrades to a newer embedding model for new queries but keeps its old stored vectors. What happens?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic