An embedding is a list of numbers (a vector) that describes what a text means. Content with similar meaning gets similar numbers, content with a different meaning gets numbers far apart. That lets a computer compare meaning even though all it can do is calculate.
Picture a map where every sentence has a location. Sentences about returns and exchanges sit in the same neighborhood, a sentence about cats lies at the other end of town. Finding an answer becomes a question of which places are closest. An embedding is the address, and the vector database is the directory where you look up the nearest neighbors.
1. How text becomes numbers
An embedding model reads a text and returns a fixed number of values, for example 1,536. That length is called the dimensions. During training, the model learns to place texts with related content close together. From a great many texts, a map of meaning emerges.
The idea goes back to word2vec. In 2013, a team around Tomas Mikolov showed that word vectors encode relationships of meaning. The famous example from the paper: calculate vector(“King”) minus vector(“Man”) plus vector(“Woman”), and you end up at the vector closest to “Queen”. Today’s embedding models process whole sentences and paragraphs instead of single words, but the principle has stayed.
1.1 How “close” is measured
The distance between two vectors is usually measured with cosine similarity. It compares the direction of the two vectors, not their length. If they point the same way, the value is close to 1. If they are perpendicular, it is 0. OpenAI recommends this measure in its documentation, although the choice of distance function usually matters little.
1.2 A small worked example
Real embeddings have hundreds to thousands of dimensions. Three are enough to follow the math. The values in the table are made up and only show the principle.
- Mini vector (made up)
- (0.60, 0.90, 0.30)
- Cosine similarity to “return”
- 0.95
- Mini vector (made up)
- (0.10, 0.90, 0.40)
- Cosine similarity to “return”
- 0.71
- Mini vector (made up)
- (0.10, 0.10, 0.95)
- Cosine similarity to “return”
- 0.23
“Exchange” points almost the same way as “return”, “billing address” is a little off, “cat” is far away. A search uses exactly this ranking. One thing matters: in real models, no single dimension has a readable meaning. There is no column for “animal” or “complaint”. Only the combination of all numbers carries the meaning.
2. The vector database
A vector database stores embeddings together with the text or ID they were computed from. Its main job is similarity search: you pass in the vector of a question and get back the stored entries that lie closest to it.
Checking every entry exactly gets slow with millions of vectors. So vector databases usually rely on approximate nearest neighbor search. A widely used method is HNSW, introduced by Yury Malkov and Dmitry Yashunin in 2016. It arranges the vectors in a multilayer graph and hops from coarse to fine layers toward the target. The result is very fast, but it does not guarantee the single best match.
You do not necessarily need a separate product for this. pgvector, for example, is an extension for PostgreSQL. It stores vectors next to your other data in the same table and supports exact and approximate search, including HNSW and cosine distance. There are standalone vector databases as well. Which one fits depends on data volume, operations and the technology you already have.
3. What embeddings are used for
- Semantic search: The search finds “exchange” even when you type “return”.
- RAG: The system looks up the matching passages from your documents and hands them to the language model.
- Recommendations: Products or articles with related descriptions are suggested.
- Grouping: Texts with similar content can be bundled into topics.
- Finding duplicates: Near-identical entries sit close together in vector space.
In its documentation, OpenAI also names anomaly detection and classification as typical uses.
3.1 Embedding model or LLM?
Both are usually neural networks, but with different jobs. An LLM produces text. An embedding model produces vectors and writes nothing. Embeddings also appear inside an LLM: the 2017 Transformer paper describes how learned embeddings turn the input tokens into vectors the network keeps working with.
4. A worked example: storage for 3,000 pages
Let us pick up the knowledge base from the entry on RAG: 3,000 pages, split into sections of about 300 words. That makes roughly 4,500 sections, and each one gets a vector. Storage takes 4 bytes per dimension (a 32-bit number). How much that adds up to depends on the length of the vectors. OpenAI’s models return 1,536 dimensions by default for text-embedding-3-small and 3,072 for text-embedding-3-large.
- Storage per vector
- 3 KB
- Storage for 4,500 sections
- 13.8 MB
- Storage per vector
- 6 KB
- Storage for 4,500 sections
- 27.6 MB
- Storage per vector
- 12 KB
- Storage for 4,500 sections
- 55.3 MB
Even at 3,072 dimensions, this knowledge base stays small. Storage only becomes a problem with millions of sections. Shorter vectors save storage and cost some accuracy. With the OpenAI models, you can shorten the vectors with the “dimensions” parameter.
5. Limits and misconceptions
- Similar does not mean correct. The search finds texts that fit the question, not texts that are true. An outdated paragraph can be the best match.
- Language and jargon. A model only knows what it saw in training. Internal abbreviations or rare technical terms often land in the wrong place in vector space.
- Numbers and proper names. Two product numbers that differ in a single digit can end up close together in vector space. An embedding captures meaning, not exact character strings. That is why many systems combine vector and keyword search (hybrid search).
- Switching models means recomputing. Vectors from different models cannot be compared. If you change the embedding model, you have to embed all stored texts again.
- The vector does not replace the text. You store the original text as well, to display it and to re-embed it later.
- Approximate search is approximate. Methods like HNSW trade a little accuracy for speed.
6. What does this mean for you?
- Check whether you need a vector database. For small collections, an extension of your existing database or a provider’s file search is often enough.
- Test the model on your data. Collect 20 to 50 real questions with a known source passage. A leaderboard like MTEB shows a direction but does not replace your own test.
- Combine vector and keyword search if your texts contain product numbers, names or legal paragraphs.
- Plan for a model switch. Store the original text and the model name alongside, so you can embed again later.
- Settle data protection up front. To compute embeddings, your texts go to the embedding model, which with a cloud provider means its servers.
