On this page · 13 sections

We have been building the same customer-support assistant across this series.

In the first article, we decided the model should not invent a refund policy from its training data. The application should retrieve the real policy and put it in the context.

In the second article, we said the context window is a budget, so retrieval has to be selective. Send the refund policy, not the whole help center.

Both articles quietly assumed something we haven’t explained yet: that the application can find the right document.

So let’s try. A customer types:

“How do I get my money back?”

Your help center contains this document:

“Customers can request a refund within 30 days of purchase.”

To a human, this is obviously the answer. To a keyword search engine, these two sentences have no meaningful terms in common. No “money”. No “back”. No “refund” in the question.

This article is about how we close that gap, and about the new problems that appear once we do.

Why Keyword Search Misses the Obvious Answer

Traditional search works by matching terms.

At index time, the engine breaks every document into words and builds an index from each word to the documents that contain it, much like the index at the back of a book. At query time, it breaks the query into words, looks them up, and ranks documents by how well the terms match.

This is fast, predictable, and excellent at a lot of things. If a customer searches for refund, keyword search will find the refund document immediately.

But customers don’t write in the vocabulary of your documentation. They say “money back”, “reimbursement”, “return my payment”, “charge me back”, “I want my $40 back”. The documentation says “refund”.

The classic fix is a synonym list:

refund ↔ money back ↔ reimbursement ↔ return payment ↔ ...

It works until it doesn’t. You are now maintaining a hand-written map of human language, one complaint at a time, and you will always be one phrasing behind your users.

The important question is not “which words did the user type?”

It is “what did the user mean?”

To answer that, we need a representation of text where meaning, not spelling, decides what counts as a match.

Try to Understand It This Way

Imagine a large room full of people at a conference.

Nobody assigned seats, but over the evening people drift toward others with similar interests. The distributed-systems people end up in one corner. The front-end people gather near the windows. Someone who works on databases and distributed systems stands somewhere between those two groups.

If you walk in and want to find someone who knows about message queues, you don’t need to know their name. You walk to the distributed-systems corner and talk to whoever is closest.

Now replace people with sentences.

Put every document from your help center somewhere in the room, so that texts about similar things stand close together. The refund policy stands near “billing issues”. The password-reset article stands near “login problems”, far away from both.

When the customer’s question arrives, you place it in the room using the same rules. “How do I get my money back?” lands near the refund policy, not because it shares words with it, but because it is about the same thing.

Search then becomes a simple question:

Which documents are standing closest to the question?

That is the core idea behind semantic search. An embedding is a text’s position in that room.

Two caveats keep this analogy honest:

  1. The real “room” doesn’t have two or three dimensions. It has hundreds or thousands.
  2. Nobody decided what each direction in the room means. The positions are learned by a model during training.

Keep both in mind. They explain most of what follows, including the failures.

What an Embedding Actually Is

In code, an embedding is not a map or a room. It is a list of floating-point numbers. Here is the refund policy run through the demo’s local model:

"Customers can request a refund within 30 days of purchase."
                          ↓
             embedding model (nomic-embed-text)
                          ↓
  [0.0389, 0.0448, -0.1941, -0.0197, ... , -0.0478]    ← 768 numbers

A few properties matter for engineering:

The length is fixed by the model. OpenAI’s text-embedding-3-small returns 1,536 numbers by default. The local nomic-embed-text model used in this article’s demo returns 768. A three-word query and a three-paragraph document produce vectors of the same length.

Individual numbers don’t mean anything you can read. It is tempting to look for “the refund dimension” or “the politeness dimension”. There isn’t one. Meaning is spread across all the dimensions together. What matters is how vectors relate to each other, not what any single number says.

Vectors are only comparable within one model. A vector from one embedding model and a vector from another live in different rooms with different coordinate systems. Comparing them is like comparing a GPS coordinate with a seat number.

Embedding models read tokens too. Everything from the previous article (opens in a new tab) still applies. Hosted embedding APIs typically bill per input token, and every embedding model has a maximum input length that varies by model. OpenAI documents 8,192 tokens for its text-embedding-3 models. The nomic-embed-text build used in this article’s demo reports a context length of 2,048 tokens.

What happens past that limit also varies, and this is the part that bites. Ollama’s /api/embed endpoint silently truncates by default. In the demo setup, an input several times longer than the limit came back successfully, but only its first 2,048 tokens had been read. With truncate: false, the same request fails with an error instead. Silent truncation is the dangerous case: nothing fails, and the end of your document is simply not in its vector.

The difference from an LLM is what comes back: not generated text, but a single vector. That is worth slowing down on, because it connects to the first article.

An LLM is a prediction engine that produces text one token at a time. An embedding model is usually built from similar Transformer machinery, but it is trained for a different job: read a piece of text and produce one vector that summarizes what it is about. There is no generation step and nothing to sample.

That makes embeddings far more repeatable than LLM output, but don’t treat them as bit-for-bit deterministic. In the demo setup, embedding the same text repeatedly, alone or inside a batch, produced identical vectors. That is a property of one model on one machine, not a guarantee. Different hardware, batching, or quantization can introduce tiny numerical differences, and a hosted model behind a familiar name can change if the provider updates it. Compare vectors with a tolerance, never with exact equality.

Under the hood: how a model learns where to put things

Early embeddings worked at the level of individual words. Methods like word2vec learned a vector per word from the contexts that word appeared in, so words used in similar contexts ended up with similar vectors. That was a big step, but a single vector per word can’t distinguish “bank” the river edge from “bank” the institution, and it doesn’t directly give you a vector for a whole question.

Modern text-embedding models produce a vector for an entire piece of text. A common design, though not the only one, looks like this:

  1. The text is tokenized, exactly as described in the previous article.
  2. A Transformer encoder processes the tokens. Attention lets each token’s representation take its surroundings into account, so “refund” in “refund policy” and “refund” in “we can’t refund this” are represented in context.
  3. The per-token representations are combined (pooled) into one fixed-length vector, for example by averaging them or by using a special token’s representation.

Implementations vary. Some recent embedding models are adapted from decoder-style LLMs rather than encoders, and pool differently, for example by taking the representation of the final token. Some also normalize the output or support shortened vectors. The step that stays the same is the output: one fixed-length vector per input.

The interesting part is training. A model learns what “close” should mean from examples of pairs that ought to be close: a question and its answer, a title and its article, two paraphrases. Many modern embedding models use a contrastive objective: pull matching pairs together in the space and push non-matching texts apart. Sentence-BERT is a well-known early example of training sentence embeddings this way.

This has a direct engineering consequence:

An embedding model’s idea of “similar” is whatever its training data taught it.

If the training pairs mostly taught it that texts about the same topic belong together, it will place “start a subscription” and “cancel a subscription” close together, because they are about the same topic. We will see exactly that later in this article.

Measuring “Close”: Cosine Similarity

Once every text is a vector, we need a way to score how close two vectors are.

The most common choice for text embeddings is cosine similarity. Rather than measuring the straight-line distance between two points, it measures the angle between two vectors.

Think of each vector as an arrow from the center of the room. Cosine similarity asks: are these two arrows pointing in the same direction?

  • 1 means they point in exactly the same direction.
  • 0 means they are perpendicular: no shared direction.
  • −1 means they point in opposite directions.

These are statements about geometry, not meaning. A score of 0 says two vectors are perpendicular in this model’s space. It doesn’t certify that the texts are unrelated, and −1 doesn’t mean “opposite meaning”. In practice, many text-embedding models rarely produce scores near zero, even for unrelated text. In the demo, an off-topic question about the weather in Paris still scored between 0.36 and 0.38 against every help-center document.

Why angle instead of distance? For most text-embedding models, the direction of the vector carries the meaning, and length carries little useful information. Comparing directions means two texts about the same thing can match even if their vectors have different lengths.

In code, it is a few lines, plus two checks that are easy to skip and painful to debug:

import math

def cosine_similarity(a: list[float], b: list[float]) -> float:
    # Different lengths usually mean vectors from two different models.
    # zip() would silently ignore the extra values, so fail loudly instead.
    if len(a) != len(b):
        raise ValueError(f"Dimension mismatch: {len(a)} vs {len(b)}")

    dot = sum(x * y for x, y in zip(a, b))
    norm_a = math.sqrt(sum(x * x for x in a))
    norm_b = math.sqrt(sum(y * y for y in b))

    # A zero vector has no direction, so the angle is undefined.
    if norm_a == 0 or norm_b == 0:
        raise ValueError("Cosine similarity is undefined for a zero vector")

    return dot / (norm_a * norm_b)

There is a useful shortcut here. Many providers return normalized vectors, meaning every vector has a length of exactly 1. When both vectors have length 1, the denominator above is 1, and cosine similarity is just the dot product. Vector databases rely on this a lot.

Don’t assume normalization, though. It is a property of the specific model and endpoint, not of embeddings in general:

  • OpenAI documents that its embeddings are normalized to length 1.
  • Ollama documents that its /api/embed endpoint returns normalized vectors, and in the demo setup every vector had a length of 1.0.
  • Ollama’s older /api/embeddings endpoint returned vectors from the same nomic-embed-text model with a length of about 22.

Use the dot-product shortcut on that last one and your scores are no longer cosine similarities. Documents with longer vectors get an unearned boost, and the ranking can change. Check your provider’s documentation, check a few vector lengths yourself, and if you shorten vectors yourself, re-normalize them.

Technical detail: the formula, with numbers you can check by hand

For vectors A and B:

cosine_similarity(A, B) = (A · B) / (|A| × |B|)

A · B = A₁B₁ + A₂B₂ + ... + AₙBₙ      (dot product)
|A|   = √(A₁² + A₂² + ... + Aₙ²)      (length, or "norm")

A two-dimensional example:

A = (3, 4)     |A| = 5
B = (6, 8)     |B| = 10
C = (4, -3)    |C| = 5

cos(A, B) = (3×6 + 4×8) / (5 × 10) = 50 / 50 = 1.0
cos(A, C) = (3×4 + 4×−3) / (5 × 5) = 0 / 25  = 0.0

B is twice as long as A but points the same way, so the similarity is 1.0. The straight-line (Euclidean) distance between A and B is 5, even though their direction is identical. That difference is why angle is usually the more useful signal for text.

When vectors are normalized to length 1, cosine similarity, dot product, and Euclidean distance all produce the same ranking. OpenAI’s documentation states this explicitly for its embeddings. Choosing between them then becomes mostly a performance and tooling decision, not a quality one.

Semantic Search, End to End

Now we have all the pieces. A semantic search system has two phases.

Index time happens ahead of time, whenever documents change:

  1. Take each document (or, for long documents, each chunk).
  2. Send it to the embedding model.
  3. Store the vector next to the original text and an ID.

Query time happens on every request:

  1. Embed the user’s question with the same model.
  2. Compare the query vector with the stored document vectors.
  3. Return the closest documents.

Here is that flow using OpenAI’s Python SDK. It is illustrative: it keeps everything in memory and compares the query with every document, which is fine for five documents and nothing more.

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from the environment
MODEL = "text-embedding-3-small"

documents = [
    "Customers can request a refund within 30 days of purchase.",
    "To cancel your subscription, go to Settings > Billing > Cancel.",
    "If you forgot your password, click 'Forgot Password' on the login page.",
    "Our support team is available 24/7 via live chat.",
    "Billing issues can be resolved by contacting our accounting department.",
]

def embed(texts: list[str]) -> list[list[float]]:
    # One batched request; the API returns one embedding per input.
    response = client.embeddings.create(model=MODEL, input=texts)
    return [item.embedding for item in response.data]

# Index time: embed the documents once. A real system would store these.
document_vectors = embed(documents)

# Query time: embed the question with the SAME model.
query_vector = embed(["How do I get my money back?"])[0]

ranked = sorted(
    zip(documents, document_vectors),
    key=lambda pair: cosine_similarity(query_vector, pair[1]),
    reverse=True,
)

The one rule you must not break:

Documents and queries must be embedded by the same model, with a compatible configuration.

“Compatible” is stricter than it sounds. It means the same model version and the same output dimensions if you shortened them. It also means the same preprocessing rules, applied every time.

It does not always mean identical input handling for both sides. Some models are asymmetric by design: they were trained to expect one task prefix on queries and a different one on documents. nomic-embed-text, for example, expects search_query: before every query and search_document: before every document. Using two different prefixes there is not a mismatch. It is the configuration the model was trained for.

What breaks things is inconsistency. Prefix your documents at index time, forget the query prefix at query time, and nothing errors. Your results just quietly get worse.

What Happens When You Actually Run It

Diagrams make semantic search look clean. Running it is more instructive.

The companion demo for this article runs keyword search and embedding search side by side over the five help-center documents above. Every score in this article comes from nomic-embed-text running locally through Ollama, with no task prefixes unless stated otherwise.

Implementation note: the exact setup behind every number
Runtime:     Ollama 0.40.1, local, via the /api/embed endpoint
Model:       nomic-embed-text:latest  (Ollama ID 0a109f422b47, 137M params, F16, 768 dimensions)
Prefixes:    none (the demo's default), unless stated otherwise
Similarity:  cosine, rounded to 4 decimal places
Command:     EMBEDDING_PROVIDER=ollama python search.py "<query>" ...

The Python and JavaScript versions produced identical output, and so did repeated runs. A different model, Ollama version, or build will give different numbers. That includes latest, which is a moving tag and can point to a different build in the future. The demo’s README records the full model and weights digests and the exact commands, so you can check whether you are running the same build. Expect the same shape of results, not necessarily the same digits.

Here is the output for our customer’s question:

Query: How do I get my money back?

Keyword search (shared words):
  No document shares a meaningful keyword with the query.

Semantic search (cosine similarity):
  0.5839 | Customers can request a refund within 30 days of purchase.
  0.5608 | To cancel your subscription, go to Settings > Billing > Cancel.
  0.5463 | Billing issues can be resolved by contacting our accounting department.
  0.5341 | If you forgot your password, click 'Forgot Password' on the login page.
  0.4138 | Our support team is available 24/7 via live chat.

The headline result is what we wanted. Keyword search found nothing, and semantic search put the refund policy first.

Here is where it gets interesting. Look at the scores.

The refund document wins with 0.58. The password reset document, which has nothing to do with money, scores 0.53. The winning margin over the second result is about 0.02.

That is the first practical lesson about similarity scores:

Similarity scores are relative, not absolute. A score of 0.58 does not mean “58% relevant”. Unrelated texts still score well above zero, and the useful signal is often the ordering, not the number.

The exact values also depend on configuration. Adding the task prefixes that Nomic’s model card recommends for this model changed every score, without changing the documents or the questions. Some went up and some went down. Scores from different models, or from the same model configured differently, are not comparable.

Technical detail: how the task prefixes changed the scores
                                        No prefixes          Nomic prefixes
"How do I get my money back?"
   refund policy (correct, ranked 1st)     0.5839               0.6372
   runner-up                               0.5608 (cancel)      0.6345 (billing)
"I want to stop paying for this every month"
   cancel subscription (correct, 1st)      0.5791               0.5364

For the money-back question, every score went up and the margin shrank to 0.003. For the stop-paying question, the top score went down. There is no simple “prefixes add 0.05” rule, and that is exactly why a threshold tuned in one configuration can’t be carried over to another.

The demo has the full output, and it runs locally without an API key if you use Ollama:

Where Semantic Search Goes Wrong

The demo makes semantic search look like a solved problem. Production does not.

Every failure below comes from the same five documents and the same model. These are not edge cases you need a million documents to hit. Each one also appeared with Nomic’s recommended prefixes switched on, so none of them is just a configuration mistake. Scores below are from the default no-prefix run, with the prefixed score in parentheses where it matters.

Similar is not the same as correct

Ask the demo:

“How do I start a subscription?”

There is no document about starting a subscription. Semantic search returns this as the top result:

0.6628 | To cancel your subscription, go to Settings > Billing > Cancel.

It is the opposite of what the user wants, and it scored higher than the correct refund match did for our original question: 0.66 vs 0.58 (0.70 vs 0.64 with prefixes).

This isn’t a bug in the model. Starting and cancelling a subscription are about the same topic: subscriptions, billing, account settings. Embeddings capture “what is this about?” far better than “what exactly is being asked?”. Negation, direction (“to” vs “from”), and small but critical qualifiers are where similarity is weakest.

It also kills the obvious fix. You might think: “I’ll only accept results above a threshold.” But which threshold? The right answer scored 0.58 in one query, and a wrong answer scored 0.66 in another. No fixed number separates them.

There is always a nearest neighbor

Now ask something completely unrelated:

“What is the weather in Paris?”

Semantic search still returns a ranked list. The top document is about billing, with a score of 0.38 (with prefixes, the live-chat document came first at 0.44).

Nearest-neighbor search always has a nearest neighbor. It has no built-in concept of “none of these are relevant”. If your application passes the top results straight into an LLM’s context, the model will receive billing documentation as “relevant context” for a weather question.

Relevance thresholds can help, but they have to be tuned per model on your own data, and as we just saw, they are a blunt tool. In practice they usually work together with other signals: rerankers, the LLM itself being allowed to say “I don’t have that information”, or routing off-topic questions elsewhere.

Relevant is not the same as the answer

Ask:

“Can I get a refund after 45 days?”

Retrieval works well here. The refund policy comes back first with 0.75 (0.77 with prefixes), the highest score of any query run for this article. But the policy says refunds are available within 30 days. The honest answer to the customer’s question is no.

Retrieval found the right document. It did not answer the question, and it was never going to. Semantic search finds text that is about the question. Deciding what that text means for this customer is a separate step, usually the job of the LLM reading the retrieved context and of whatever validation surrounds it.

This is the exact boundary between retrieval and generation, and it is where RAG systems live. Keep it in mind for later in the series.

Exact terms: where keyword search wins

Embeddings are good at meaning and comparatively weak at exactness. Think of queries like:

  • an order number: order 48291
  • an error code: E-4012
  • a product SKU or version: v2.3.1
  • a rare internal name the embedding model never saw during training

Embedding models can blur these into “a query about an order” or “a query about an error”, because the specific string carries little meaning the model has learned. The demo doesn’t include identifiers, so treat this as a well-known limitation to test with your own data rather than a measured result. Keyword search, meanwhile, matches them exactly. This is why many production systems use hybrid search: run keyword and semantic retrieval together and combine the results. We’ll look at that properly later in the series.

The model’s training defines the space

One more experiment. Ask the demo the money-back question in German:

“Wie bekomme ich mein Geld zurück?”

With this model, the refund document came back fourth out of five, both with and without prefixes.

The embedding space is only as good as what the model learned. A model trained mainly on one language, or on general web text rather than your domain, can place things badly in exactly the situations you care about. Multilingual embedding models exist for this reason, but “supports many languages” is a claim to test on your own queries, not to take on faith.

Ambiguity belongs in the same family. A one-word query like payment could mean “how do I pay”, “my payment failed”, or “change my payment method”. Its embedding sits somewhere between those meanings and may not land close to any one of them.

Engineering Decisions Before Production

If you are moving from a demo to a real system, these are the decisions that matter most.

1. Treat the embedding model as part of your data schema

Every stored vector is tied to the model and configuration that produced it. Change the model, the version, the dimensions, or the prefixes, and every existing vector is incompatible with new queries.

In practice that means:

  • Store the model name, an exact version or digest, the dimensions, and the query and document prefix rules alongside your vectors. A tag like latest is not a version: it can point to a different build tomorrow.
  • Plan for re-embedding the full corpus whenever you upgrade the model, as a migration, not a config change.
  • Never mix vectors from different models in the same index.

This is the embedding equivalent of a database schema migration, and it deserves the same care.

2. Decide what you embed, not just how

An embedding is one vector for the whole input. Embed a 200-page policy document as one vector and you get a blurry average of everything in it. The refund section is in there somewhere, diluted by shipping, warranty, and privacy.

This is why real systems split documents into smaller chunks and embed each chunk. How you chunk has a big effect on retrieval quality, and it gets its own article later in the series.

3. Dimensions are storage, memory, and speed

Vectors are not small. A 1,536-dimension vector stored as 32-bit floats is about 6 KB. A million of them is about 6 GB of raw vectors, before any index overhead.

Some models, including OpenAI’s text-embedding-3 models, let you request fewer dimensions through a dimensions parameter. That trades some retrieval quality for less storage and faster comparisons. Whether that trade is worth it depends on your data, which leads to the most important decision.

Want to go deeper? Why shortened embeddings still work

Truncating an ordinary embedding to its first 256 numbers would usually destroy it, because the information is spread across all the dimensions.

Some models are trained specifically so that truncation works. With Matryoshka Representation Learning, the model is trained so that the first dimensions carry the most important information, the next ones add finer detail, and so on, like nested dolls. A prefix of the vector is a usable lower-resolution embedding on its own.

OpenAI’s text-embedding-3 models support this through the dimensions parameter, and Nomic describes nomic-embed-text-v1.5 as supporting resizable embeddings the same way. Two practical notes:

  • Prefer asking the API for fewer dimensions over truncating vectors yourself. If you do truncate manually, re-normalize the result before using dot-product similarity.
  • Shorter vectors are a quality trade-off. Measure it on your own retrieval tasks rather than assuming it is free.

4. Index time and query time have different costs

At query time you embed one short question: cheap, but on the latency path of every request.

At index time you embed your whole corpus, and you pay again every time documents change or you switch models. For large corpora that means batching requests, handling rate limits and partial failures, and only re-embedding what actually changed. It looks like a data pipeline because it is one.

5. Evaluate on your own queries

Public benchmarks such as MTEB are useful for building a shortlist of models. They can’t tell you how a model handles your users’ vocabulary, your product names, and your languages.

The minimum useful evaluation is small:

  1. Collect a few dozen real user questions.
  2. For each one, write down which document should come back.
  3. Measure how often that document appears in the top results.

Step 3 has a name: Recall@K. For each question, ask whether the correct document appears anywhere in the top K results, then average over all your questions. (When a question has several relevant documents, Recall@K is the fraction of them found in the top K. With one correct document per question, as here, it is simply the hit rate.)

Here it is on the demo. Six of the queries we ran have a clear correct document: money back, stop paying, can’t log in, refund after 45 days, refund, and the German money-back question. The correct document ranked first for five of them. The German query found it only at rank 4.

Recall@1 = 5/6 ≈ 0.83
Recall@3 = 5/6 ≈ 0.83
Recall@5 = 6/6 = 1.00   ← meaningless here: the corpus only has 5 documents

The run with Nomic’s prefixes gives the same three numbers.

Treat this as a demonstration of the metric, not evidence that the retrieval works well. Six queries against five documents is far too small a sample to say anything about a model. Recall@5 is perfect only because returning five results means returning the entire corpus. A meaningful evaluation needs a realistic corpus and a larger labeled query set, ideally drawn from real user questions. With those you can track Recall@1, Recall@3, and Recall@5 together and watch how they move when something changes.

Even this toy example teaches two lessons.

First, choose K to match how you use the results. If your RAG pipeline puts the top three chunks into the context, Recall@3 is the number that matters. A K close to the size of your corpus is perfect by construction and tells you nothing.

Second, Recall@K only scores questions that have a right answer. “How do I start a subscription?” and “What is the weather in Paris?” have no correct document, so they can’t appear in this metric at all. Yet those are exactly the queries where the system confidently returned something wrong. That gives you two evaluation sets, not one:

  • Answerable questions, each labeled with its correct document, measured with retrieval metrics such as Recall@K.
  • Unanswerable questions, which should produce no result, measured against explicit rejection criteria: did the system abstain, fall below its threshold, or say it doesn’t know?

Run this evaluation whenever you change the model, the chunking, or the configuration. Without it, every retrieval change is a guess.

6. Comparing against everything doesn’t scale

The demo compares the query with every stored vector. With five documents, that’s nothing. With millions of vectors and many queries per second, comparing against everything becomes the bottleneck.

Solving that is the job of vector indexes and vector databases, which is where the next article picks up.

When to Use Embeddings, and When Not To

Reach for embedding-based search when:

  • Users and documents use different vocabulary. Support centers, internal knowledge bases, and documentation search are classic examples.
  • Queries are natural-language questions rather than exact lookups.
  • You need “more like this”. Similar tickets, related articles, duplicate detection, and clustering are all the same nearest-neighbor operation.
  • You are building the retrieval step of a RAG system.

Be careful, or combine it with something else, when:

  • Exact identifiers matter. Order numbers, error codes, SKUs, and names usually need keyword or hybrid search.
  • The answer depends on hard constraints. “Documents this customer is allowed to see”, “policies effective after January”, and “this tenant only” are filters, not similarity. Apply them explicitly.
  • Small differences change the meaning. Start vs cancel, allowed vs forbidden, before vs after. Similarity alone won’t reliably separate them. Rerankers and the LLM reading the context help.
  • The question is really a database query. “How many orders did I place last month?” belongs in SQL, not in vector search.
  • Your corpus is tiny and stable. Twenty well-written FAQ entries with good keyword search may be all you need.

What to Take Away

  • Embeddings turn text into vectors so that texts with similar meaning end up close together. That is what lets “money back” find “refund”.
  • Cosine similarity measures direction, not size. With normalized vectors it reduces to a dot product, and the common distance measures produce the same ranking. Check that your vectors really are normalized: it depends on the model and the endpoint.
  • Same model, compatible configuration, every time. Vectors from different models, versions, or dimensions are not comparable. Asymmetric models need their query and document prefixes applied consistently. Treat model changes as data migrations.
  • Scores are relative and model-specific. Don’t read 0.58 as “58% relevant”, and be suspicious of any single global threshold.
  • Similar is not correct, and relevant is not an answer. Embeddings retrieve what a text is about. They don’t understand negation, direction, or whether the document actually says yes.
  • Embeddings complement keyword search; they don’t replace it. Exact identifiers, filters, and structured questions still need other tools.
  • Evaluate with your own queries. A few dozen labeled questions and a Recall@K number will tell you more than any leaderboard. Add separate test cases for questions that should return nothing.

Think About These Use Cases

Each of these uses the same building blocks: embeddings, similarity, and the failure modes above. Try sketching how you would handle each one before reading further in the series.

  • Duplicate support tickets: A new ticket arrives. How would you use embeddings to find similar open tickets, and how would you stop “app crashes on login” from being merged with “app crashes on logout”?

  • Internal engineering docs: Your company’s documentation is full of internal service names the embedding model has never seen. How would you check whether semantic search actually works for your team before rolling it out?

  • E-commerce search: One shopper types “something warm for winter hiking”. Another types a product SKU. What should each query hit, and how would one search box serve both?

  • Multi-tenant knowledge base: Every customer has their own documents. Where does tenant isolation belong in a semantic search system, and why is “the vectors will naturally separate” not an answer?

  • Model upgrade: A newer embedding model scores better on a public benchmark. You have ten million stored vectors. How would you decide whether to switch, and how would you migrate without downtime?

If you want to talk one of these through, take it to GPT along with this article. Ask GPT ↗️

What’s Next?

Our support assistant can now find the refund policy, even when the customer never says “refund”.

But it finds it by comparing the question against every stored vector. That works for five documents. It does not work for five million documents and thousands of questions per minute.

In the next article, we’ll look at Vector Databases Explained: What Problem Are They Solving?: how vector indexes find nearest neighbors without checking everything, and what you give up in exchange.

← All articles