Embeddings: find the right article with different words
A search for cheap flights can miss an article called affordable airfare. This pack explains how embeddings connect related wording and how to check your own search.
Why matching words can miss the answer
If a search only matches words in a title, two phrases with the same meaning can miss each other. The article exists; the query uses different wording. That is the problem illustrated in the reel. Real search systems vary, so do not assume every keyword search fails on synonyms.
An embedding is a list of numbers representing text. A vector is that list. A compatible model turns related text into vectors that tend to be similar. Vector search compares the query vector with stored vectors and returns similar candidates. It does not guarantee the intended answer.
Use one example you can inspect
Start with three short articles and a handful of questions. Decide which article should answer each question before running the search. Keep at least one question whose answer is absent. This catches a system that returns something plausible for every input.
Article A: affordable airfare and ways to lower travel costs
Article B: dog grooming and coat maintenance
Article C: flight cancellation policies and refund rules
Query: cheap flights
Expected: A
Query: can I get my airfare refunded?
Expected: C
Query: how do I renew my passport?
Expected: no relevant article
These are suggested test cases, not measured model outputs. The map shown in the reel is also an analogy. Do not label an illustrative distance or similarity score as a real measurement.
Store the article vectors first
Create embeddings for your content and save them beside the original text and a stable identifier. When a query arrives, create its embedding with the same compatible setup and compare it with the saved vectors. Follow the embedding model's instructions for queries versus documents.
Long articles may need to be split into smaller passages. Keep enough surrounding text for each passage to make sense. When the source changes, update its stored representation too.
Article record
ID:
Title:
Original text:
Passage number, if split:
Embedding model and settings:
Content version:
Date embedded:
The record matters when results go wrong. You want to know whether the search compared the current article or an old version. You also want to see the actual passage, not only its title.
Compare similarity carefully
Cosine similarity compares vector directions using the cosine of the angle between them. It is one possible comparison method, not a required concept for the short reel. The pgvector query documentation describes several supported distance functions for a database implementation.
The closest result can still be irrelevant if the collection contains no answer. A score is not a probability that the result is correct. Judge candidate results against your example questions and the actual source text before deciding how the app should display them.
Search review
Question:
Expected article or no-answer result:
Returned article:
Returned passage:
Why the passage answers the question:
What is missing:
Decision: useful / partial / irrelevant
Keep exact matching where it helps
Exact identifiers, reference numbers, and error messages often benefit from literal matching. Meaning-based retrieval is useful when people describe a concept in different words. A combined approach can be worth testing when your app receives both kinds of question.
Do not change every search feature because one synonym example worked. Test the kinds of requests your users actually make. Include short queries, ambiguous queries, misspellings, and absent answers. Keep the expected results visible while reviewing the output.
Build a search evaluation table for the example articles above.
Include synonym queries, exact titles, ambiguous wording, and absent answers.
For each query, state the expected result and a short reason.
Do not fabricate search scores or pretend you ran an embedding model.
Keep proposed tests separate from measured outcomes.
Run this on your codebase
Paste this into an assistant session in your project. It starts by understanding the search you already have, so the next change is based on evidence rather than the name of a technique.
Review how search works in this codebase without editing files.
1. Find the search entry point and the source of searchable content.
2. Explain the current matching method with file and function references.
3. Create ten representative queries, including synonyms and absent answers.
4. State the expected result for each query before proposing changes.
5. Identify where embeddings might help and where exact matching matters.
6. Explain how content updates would keep stored vectors current.
7. Propose one small experiment and a table for recording real outcomes.
Do not claim a search failure or improvement without running the relevant check.
Do not install packages, send private content to a provider, or change code.
Finish with the smallest useful next implementation step.