Embeddings and Semantic Representations

Explore embeddings, vector similarity, and finding related content through a help document search example.

🎯 Introduction

Suppose your online store has a help article called “How to Request a Product Return” explaining the return process.

A customer searches, “I bought the wrong item. Can I send it back?”

They did not use “request a return,” but their question relates directly to that article.

How can the website recognize this relationship?

This article explains how embeddings help programs find text with similar meanings. By the end, you should be able to describe a simple semantic search.


🧱 Why Matching Words May Not Be Enough

Consider three help articles:

  • A: “How to Request a Product Return”
  • B: “When Will My Refund Arrive?”
  • C: “How to Change Your Shipping Address”

The customer searches, “I bought the wrong item. Can I send it back?”

A basic search could check whether input words appear in document titles. Searching for “change address,” for example, might find C.

But “bought the wrong item” and “send it back” differ from “request a product return.” The wording differs, but the intent is closely related.

Exact word matching could miss A.

We want the system to go beyond shared words and identify which document is most relevant to the question.

This describes only basic keyword matching. Real keyword search can also use tokenization, synonyms, and other improvements; it is not limited to exact text comparisons.


🧱 What Is an Embedding?

To compare meanings, a program needs a representation it can calculate with.

An embedding provides one: send text to a specialized embedding model, and it returns a list of numbers.

For example, “request a refund” might produce something like [0.81, 0.12, 0.33]. These are illustrative numbers, not actual model output.

This list is called a vector. For now, think of it as a list of numbers used in calculations, without learning formulas first.

The numbers are not manually assigned by programmers, nor does the first mean “refund” and the second “address.” A trained embedding model calculates them, and another model may produce different results.

This example has three numbers; real models usually produce longer lists. The number of entries is the vector's dimensionality, which we will not explore further here.

Why numbers? Suitably trained embedding models represent related meanings through comparable relationships between vectors. A program can then calculate which text is more likely to be relevant.

Next, we connect vector generation with comparison in a search example.


🧱 Comparing Text with Vectors

The customer's question and the help documents can now all be converted into vectors.

The program must determine which document vector is most similar to the question vector.

One common method is cosine similarity, which compares the mathematical directions of two vectors. For now, think of it as a similarity calculation: higher scores generally indicate closer directions.

You do not need to derive the formula. The key is: the model converts text into numbers, and the program calculates similarity using those numbers.

Similarity helps prioritize documents for review; it is not factual accuracy. Related text does not necessarily resolve the customer's question.


🧱 Searching with Embeddings

Return to the store example.

The diagram shows three stages: input a question and documents → generate vectors → compare similarity and rank.

How embeddings find relevant documents

Three search steps: enter text, convert it to vectors, and compare the results

1 Enter text

User question

I bought the wrong item. Can I send it back?

Document A

How to Request a Product Return

Document B

When Will My Refund Arrive?

Document C

How to Change Your Shipping Address

2 Convert to vectors

User question vector

[0.90, 0.10, 0.20]

Vector for document A

[0.85, 0.19, 0.30]

Vector for document B

[0.70, 0.45, 0.20]

Vector for document C

[0.05, 0.90, 0.20]

3 Compare and rank
1How to Request a Product Return0.99
2When Will My Refund Arrive?0.90
3How to Change Your Shipping Address0.20

Result: “How to Request a Product Return” ranks first. The system then retrieves the original text.

These hand-picked vectors produce the rounded scores shown here. The scores measure similarity for this example and do not indicate model output or answer accuracy.

The numbers are manually designed teaching examples that illustrate calculation and ranking, rather than actual embedding model output.

In a real application, the process has four steps:

  1. Prepare documents in advance: convert existing help documents into vectors and store them, recording which original document each vector represents. This avoids reprocessing every document for each search.
  2. Process the question: use the same embedding model to convert the search question into a vector.
  3. Compare similarity: compare that vector with document vectors and prioritize relevant documents.
  4. Retrieve the source: use the stored mapping to find “How to Request a Product Return” and display its content.

Embeddings help find information; they do not decide whether a return is allowed. That requires the actual policy and the customer's order details.

If none of the documents is relevant, the system should not assume the highest-ranked document answers the question.


Compare the approaches:

Search methodSuitable exampleCaveat
Keyword searchFind order A12345 by its identifierBasic matching may miss alternative wording
Semantic search“I bought the wrong item. Can I send it back?”Similar meaning does not establish eligibility under actual rules

Applications can combine both approaches. This is called hybrid retrieval; implementation is covered later.


❓ Knowledge Check

Q1: Does an embedding model directly tell customers whether they can return an item?

No. It primarily converts text into vectors to help find relevant documents. Return eligibility still depends on policy and order information.

Q2: Must we keep the original documents after storing vectors?

Yes. Vectors support retrieval, but customers still need the original content. The program must map vectors back to documents.

Q3: Does the highest-ranked document always answer the question?

No. It only ranks above the other candidates. If all candidates are irrelevant, the first may still be useless.


🧪 Exercise

Suppose a website has these help documents:

  • A: “How to Reset Your Login Password”
  • B: “Changing Your Delivery Address”
  • C: “Login Password Security Tips”

A user searches, “I forgot my password. How do I set a new one?”

Answer:

  1. Which document should be prioritized, and why?
  2. What could go wrong with exact word matching?
  3. If document vectors are already stored, what must the program do to retrieve the original document?
  4. If all documents are irrelevant, must the highest-scoring one be returned?

Success criteria: Prioritize A because it addresses password resets. Alternative wording can cause basic keyword matching to miss results. Convert the question to a vector, compare similarity, and retrieve the corresponding document. A top ranking does not guarantee an answer.


🎉 Congratulations! You understand why embeddings help search, the role of vectors, and how programs retrieve related documents. Next, we begin designing prompts.