Computers process text as numbers. Vector embeddings are one way of representing text numerically so that a computer can compare words, sentences, or whole passages by their meaning and use.
For example, someone searching for “food for a dog” might find an article about “dog nutrition.” The wording is different, but the subjects are closely related. Embeddings help a search system make that connection.
What is a vector?
A vector is an ordered list of numbers. The vector [0.2, -0.4, 0.7] contains three values, so it has three dimensions. You can think of these values as coordinates that locate a point in a space.
With two coordinates, we can draw a point on a flat chart. With three, we can place it in a three-dimensional space. Computers can perform the same kinds of comparisons with hundreds or thousands of coordinates, even though we cannot draw all those dimensions on a page.
An embedding represents an item as a point in such a space. In a text embedding, the values are produced by a model that has learned patterns in language. The relationships between those points can help us search, group, and compare text. Google: embeddings
Related text in an embedding space
Consider three groups of words: animals, fruit, and places. Words within each group share a relationship. Some pairs, such as “dog” and “wolf,” are more closely related within their group.
- Animals: cat, dog, lion, and wolf appear together. Wolf is placed near dog because both belong to the canine family.
- Fruit: apple, banana, and orange form a second group.
- Places: London, Paris, and Rome form a third group.
Embedding models usually use hundreds or thousands of dimensions. Relationships are represented through combinations of values across the vector.
What can have an embedding?
Text embeddings can represent a word, phrase, sentence, paragraph, or longer passage, within the model’s supported input length.
| Text unit | Example | Possible use |
|---|---|---|
| Word | “dog” | Explore relationships between words |
| Phrase | “dog nutrition” | Match a search to a topic |
| Sentence | “What do dogs eat?” | Find a relevant help passage |
| Paragraph | A section describing a dog’s diet | Make a document searchable |
Language models work with tokens, which can be whole words, parts of words, or punctuation. Some models produce a representation for each token. A sentence or document embedding model produces a vector for an entire text input, often by combining information from its token representations.
Context matters. In “sit on the river bank” and “transfer money to the bank,” the word “bank” has different meanings. A model that processes the surrounding sentence can represent that difference.
Images and audio can also have embeddings. Models trained to connect text and images can support searches such as finding a photo from a written description. These capabilities depend on the model’s training. Sentence Transformers: model families
How vector embeddings are generated
An embedding model takes an input and calculates its vector. With a pretrained model, this calculation is an example of AI inference.
For a given output configuration, the model returns a fixed number of components. A short sentence and a longer paragraph might therefore both produce a 384-dimensional vector.
Embeddings can be generated by a model running locally, through a hosted service, or through a database integration that supports embedding generation. The application can use the vectors immediately or store them for later searches.
How are embeddings compared?
Once text has been converted into vectors, software can calculate how similar those vectors are. Common methods include:
| Method | What it measures |
|---|---|
| Cosine similarity | How closely two vectors point in the same direction |
| Dot product | The sum of products of corresponding values; vector length can influence the score |
| Euclidean distance | The straight-line distance between two points |
With cosine similarity, higher scores mean more aligned directions. With Euclidean distance, smaller values mean closer points. The model’s documentation specifies which comparison methods suit its embeddings. Sentence Transformers: similarity measures
For search, the question and stored passages need compatible embeddings. This usually means using the same embedding model with its documented query and document settings. Two models can produce equally long vectors while placing text in different spaces. Sentence Transformers: semantic search
A similarity score helps rank results. Its scale depends on the model and comparison method. For example, a score of 0.8 should be interpreted as a similarity measurement rather than an 80% probability that an answer is correct.
How are embeddings used in AI?
Semantic search finds information by related meaning. A question about “food for a dog” can retrieve a passage about dog nutrition even when it uses different words.
Document retrieval finds passages to supply to an AI assistant. The assistant can use those passages when answering a question, a process called retrieval-augmented generation (RAG).
Grouping and recommendations use similarities to organize customer feedback, suggest related articles, or find products with similar descriptions.
From text embeddings to searchable documents
A document search system usually divides long files into smaller passages called chunks, creates an embedding for each chunk, and stores the vectors with the passage text or a reference to it. Source titles, section names, dates, and other metadata help the application select and display the right material.
For example, passages about puppies and adult dogs may be close in meaning, while describing different needs. The retrieved text and its context help establish whether a passage answers the question. Keeping the original passages available lets users and assistants read those details.
The next article explains how vector databases store and search these records.
Check your understanding
What does a 384-dimensional embedding contain?
It contains 384 numerical components. Together they represent the input in the model's embedding space.
Why might “dog nutrition” match “food for a dog”?
An embedding model can represent their related meanings with similar vectors, allowing a search system to find the connection despite the different wording.
Why should a search system keep the original text?
The original passage contains the information a reader needs, including details and conditions. Its embedding helps locate that passage.