DEV Community

Deployed Lab
Deployed Lab

Posted on

"How do I get my money back?" Why your search says 0 results, and the map that fixes it

"How do I get my money back?" Why your search says 0 results, and the map that fixes it

A customer phones your support team and asks, "How do I get my money back?" The right page is sitting in your help centre, titled "Refund and cancellation terms". Your search returns 0 results.

Nothing is broken. The search did exactly what it was built to do: match the letters the customer typed. "Money back" and "refund" share no words, so a keyword search finds nothing. People ask in their own words, and a search that only matches letters will keep failing them in exactly this way.

The fix is to search by meaning instead of letters. That is what embeddings and vector databases do, and the idea is simpler than the names suggest.

A map where similar meanings sit close

Picture a city. Cafes cluster in one district and banks in another. If you stand in the cafe district, the nearest places are cafes. You can find a new cafe without knowing its name. You just walk to the cafe district.

Now picture a map where the places are sentences and the districts are topics. That is what an embedding gives you. An embedding model reads a sentence and turns it into a short list of numbers, a vector, which is the sentence's address on this map. Sentences with similar meaning get nearby addresses, even when they share no words at all. "Get my money back" lands next to "Refund policy" and "Cancel subscription", because the model learned from huge amounts of text that those sentences show up in similar situations.

Nobody types in a list of synonyms. The model learns the neighbourhoods from examples. Real embeddings have hundreds of numbers, so you cannot draw the map, but "near" and "far" mean the same thing.

How a search by meaning actually works

Think of a library card catalogue. The librarian files every card once, in advance. Then every time someone asks, the librarian goes straight to the right drawer. A meaning search works in the same two parts.

Part one happens in advance. Cut each document into chunks, short passages each about one topic. A whole manual is too blurry to match a question, so one clear topic per chunk. The embedding model gives each chunk its spot on the map. Save each vector with its text and labels: where it came from, its date, and who may read it. Part one is now done.

Part two happens on every question. The same model puts the question on the same map, and the vector database returns the closest few chunks. Those go to a language model, which writes the answer. The database is the store that keeps vectors together with their text and labels and can find the nearest ones fast.

The computer cannot look at a picture, so it needs a number for "near". The usual maths is simple distance. Take the question "get my money back" at address (8, 2). The refund page sits at (9, 1) and the password page at (1, 9). The gaps to the refund page are 1 and 1: squared and added, that is 2, and the square root is about 1.4. The gaps to the password page are 7 and 7: squared and added, 98, square root about 9.9. 1.4 beats 9.9, so the refund page wins, with no shared words. Real systems use hundreds of numbers, but the idea is the same. Most tools report the score the other way round, as cosine similarity, where bigger means closer, so check which way yours points.

Two traps that catch real teams

The first trap is permission. The map only knows what is similar. It has no idea who is asking, or who may read what. A support agent asks, "Who can see employee salaries?" The question lands right next to the HR salary pages, because they are very similar in meaning. The tool returns a page the agent is not allowed to read. Closeness is not permission. The fix is to store a label on every chunk saying who may read it, and drop the chunks the asker may not read before any results are shown.

The second trap is switching the embedding model. A manager reads about a newer model and asks you to "just switch it on". Each model draws its own map. An address from one map means nothing on another, so every chunk has to be run through the new model again. Say the customer has 1 million chunks of about 200 tokens each. That is about 200 million tokens. On a current small embedding model, OpenAI's text-embedding-3-small at $0.02 per million tokens as of November 2026, the embedding calls cost roughly $4. The money is trivial. The real cost is the work around it: re-indexing a live system, running the old and new maps side by side, and re-checking quality while both exist. Plan for that, not for the $4.

The map only knows similarity. Old policy versions sit close to new ones, because they say almost the same thing. A team that tested on a few clean documents watched it look great, then found old policy versions ranking first on the full document set. Date and version labels fixed it. A better model would not have. Test on your real, messy documents, not a clean sample.

A small firm with a few thousand documents that already runs Postgres should start with the pgvector extension. Fewer systems to approve, secure, and run. Move to a dedicated vector database only if speed or size demands it.

Top-k is how many nearest results you ask for, and an ANN index (often HNSW) makes search fast on big collections by skipping most vectors.

The full interactive chapter, with a map you can ask questions on and the distance maths worked out step by step, is free at https://deployedlab.dev/lessons/08-embeddings-vector-db. 11 chapters are free with no signup, and the full course is $5/month or $39/year at deployedlab.dev.

Top comments (0)