You will be able to explain what an embedding is and how similarity search uses it.
Keyword search matches words, so it fails when a question and its answer mean the same thing but use different words. Retrieval needs a search that matches meaning, and embeddings provide it.
Daniel is building search over a staff handbook. He first tried the search built into his file storage. A staff member typed: "Can I get reimbursed for a Grab ride home after overtime?" The search returned nothing, although the policy was in the handbook. It read "transport claims for employees working beyond 10pm" and never used the words reimbursed, Grab, ride or overtime. Both texts were about the same thing, but keyword search compares words, and they had none in common.
An embedding is a list of numbers that represents the meaning of a piece of text. You get one by sending text to an embedding model, which is a different kind of model from the one that writes replies. Most major providers offer an embedding model through their API, and there are open-source embedding models you can run on your own machine.
You can send in a sentence, a paragraph or a short passage. What comes back is a long list of numbers, often hundreds or thousands of them, called a vector. You can't point to one number in the list and name what it means. The useful part is how one vector compares with another.
Embedding models are trained on enormous amounts of text so that texts with similar meaning produce similar vectors. Two texts that share almost no words but cover the same subject get vectors that sit close together, and unrelated text gets a vector far away. Daniel's Grab question and the transport policy come out close. "The office pantry is restocked on Mondays" comes out far from both of them.
A simple way to think about this is a map with a dot for every piece of text, where dots with similar meaning sit near each other. On a map of Daniel's handbook, leave policies would cluster in one area, claims in another and IT rules in a third. A question about a taxi home would land in the claims area beside the transport policy, even with no shared words. That picture has two directions. Real embeddings have hundreds or thousands of directions, which nobody can picture, but distance and direction are calculated the same way.
Different phrasings of one idea land close together, so "Childcare leave", "time off to look after my kid" and "days off for parents" end up as neighbours. Many embedding models also place text near its translation, which lets a question asked in Chinese find a passage written in English. Check your model's documentation before you depend on cross-language matching.
Embedding search comes in two parts: work you do ahead of time, and work that runs each time a question comes in.
Ahead of time, you embed every passage in your document set and store each vector together with its passage text. Daniel embedded the whole handbook once and stored the vectors. Whenever a document changes, he embeds it again. Lesson 3.3, "Split, store and search your documents", covers where the vectors are stored.
When a question comes in, you embed it with the same model, compare its vector with every stored vector, and return the passages whose vectors are closest. Closeness is most often measured with cosine similarity, which compares the direction two vectors point and ignores their length. Vectors pointing exactly the same way score 1. Vectors at right angles score 0, meaning they have nothing in common. In practice related passages score noticeably higher than unrelated ones, and you keep the top few. The exact scores vary from model to model, so judge them against each other and avoid fixed cut-offs you have read about elsewhere.
You won't need to write the comparison code. Vector databases and search libraries handle it quickly, even across millions of passages.
Your questions and your documents must be embedded with the same embedding model, without exception. Each model builds its own map, so a vector from one model compared with a vector from another gives a meaningless result, much as comparing a postcode with a phone number would: both are numbers, but setting one against the other tells you nothing. Vectors from two models may not even have the same length.
If you move to a newer embedding model, re-embed every stored passage, including passages that haven't changed. Write down which model you used next to the stored vectors so that you, or whoever works on the system after you, can check.
Embeddings have limits. They handle exact strings poorly when those strings carry little meaning by themselves, such as product codes, invoice numbers, people's names and specific figures. To cover these, run plain keyword search alongside embedding search. Lesson 3.3 shows how to set that up.
The best way to build intuition is to see the scores for yourself. In the activity below you embed a few sentences and questions and look at which ones come out closest.
Use an embedding API to embed ten short sentences and three questions. Then check which sentences come out closest to each question.
Junxiong-WFG Organisation is an authorised representative of AIA Financial Advisers Private Limited (Reg. No. 201715016G).