Skip to content
mentoor

Topic 3 of 5 · 3 min read

Search, clustering and recommendations with embeddings

Goal: Choose whether embeddings, keyword search or a direct LLM call fits a given task, and say why.

Embeddings are the right tool when you need to find or group text by meaning across many items, and the wrong tool when you need an exact match or a written answer. Pick the tool by the job.

Check yourself · 1 of 3

Which task is the best fit for embeddings?

Choose one answer

Why it matters

Embeddings are cheap and fast compared with asking a chat model about every item. A chat model reads and writes text, which costs more and takes longer. An embedding model only turns text into numbers once, and then comparing them is quick. Using the right tool saves money and gives better results.

What embeddings do well

  1. Semantic search. Find help articles, tickets or notes that match the meaning of a question, not just its words.
  2. Duplicate and near-duplicate detection. Spot two support tickets that describe the same problem in different words.
  3. Clustering. Group thousands of survey comments into themes without reading them all first.
  4. Recommendations. Suggest "more like this" articles or products, by finding the nearest items to one a user liked.
  5. Classification. Compare a text with a few labelled examples and give it the label of the nearest group.
  6. Retrieval for RAG. Retrieval-augmented generation first fetches the most relevant passages from your documents, then gives them to a chat model such as Claude, ChatGPT or Gemini so it can answer using them. Embeddings power the fetching step. The chat model does the writing.

When to choose something else

  • Keyword search fits exact lookups: an order number, an error code, a person's surname.
  • A direct LLM call fits tasks that need reading and reasoning: summarise this contract, extract the dates, rewrite this email. An embedding cannot do that.
  • A database filter fits structured questions, such as "orders from March over 100 dollars".

Many good systems combine these. Keyword and embedding search together, then a chat model to write the answer.

Before and after

Before: A team sends all 20,000 support tickets to a chat model one at a time to find duplicates. It is slow and expensive.

After: The team embeds each ticket once, finds pairs with very high similarity, and only sends those few pairs to a chat model to confirm.

What goes wrong

  • Using embeddings to answer questions. They only find text. If you need an answer written, pass the found text to a chat model.
  • Skipping evaluation. Check on 20 or 30 real queries whether the right items come back before you ship.
  • Embedding huge documents as one vector. A whole book as one vector blurs many topics together. Split into passages, often a few paragraphs each, and embed each one.

Examples

Choosing the tool

Task Best fit
Find help articles that match a customer's question Embeddings
Find the ticket with reference TK-48213 Keyword search
Summarise one long contract Direct LLM call
Group 5,000 survey comments into themes Embeddings, then clustering

The pattern: many items and fuzzy meaning points to embeddings. One exact item points to keywords. Reading and reasoning points to an LLM.

A small RAG plan

  1. Split the company handbook into passages of a few paragraphs.
  2. Embed each passage and store it.
  3. When an employee asks a question, embed the question.
  4. Fetch the top 4 passages by similarity.
  5. Give the question and those passages to a chat model, and ask it to answer only from them and to say when the passages do not contain the answer.
  6. Show the answer with links to the passages.

Key points

  • Embeddings find and group text by meaning; they do not write answers.
  • Common uses are semantic search, duplicate detection, clustering, recommendations, classification and retrieval for RAG.
  • In RAG, embeddings fetch the relevant passages and a chat model writes the answer from them.
  • Exact identifiers fit keyword search, and reading or reasoning tasks fit a direct LLM call.
  • Long documents should be split into passages before embedding, so each vector stays focused.

Common mistakes

  • Expecting an embedding model to produce an answer instead of finding text.
  • Embedding a whole long document as one vector and losing the detail.
  • Using embeddings for exact identifiers where keyword search is simpler and more reliable.
  • Shipping a search without testing it on real queries.

Check yourself · 2 of 3

In a RAG chatbot, what is the role of embeddings?

Choose one answer

Check yourself · 3 of 3

A team has 5,000 survey comments and wants to see the main themes without reading each one. What is the best approach?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic