Skip to main content

What Are Embeddings? Vectors and Vector Databases Explained

Embeddings turn text into number vectors that capture meaning. How a vector database works, how much storage it needs and where similarity search falls short.

FHFinn Hillebrandt
Last updated:
Technology
What Are Embeddings? Vectors and Vector Databases Explained

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.

exchange
Mini vector (made up)
(0.60, 0.90, 0.30)
Cosine similarity to “return”
0.95
billing address
Mini vector (made up)
(0.10, 0.90, 0.40)
Cosine similarity to “return”
0.71
cat
Mini vector (made up)
(0.10, 0.10, 0.95)
Cosine similarity to “return”
0.23
Own calculation, made-up values
gradually.ai

“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.

768
Storage per vector
3 KB
Storage for 4,500 sections
13.8 MB
1,536
Storage per vector
6 KB
Storage for 4,500 sections
27.6 MB
3,072
Storage per vector
12 KB
Storage for 4,500 sections
55.3 MB
Own calculation, 32-bit numbers
gradually.ai

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.

Frequently Asked Questions

Embeddings are lists of numbers (vectors) that describe the meaning of a text, image or sound. Content with similar meaning gets similar numbers, even when it uses different words. That lets software compare meaning even though it only calculates. They are the basis for semantic search, RAG, recommendations and grouping texts.

To embed means to place something inside something else. Here, a text is placed inside a space of numbers, called a vector space. The result, the list of numbers for that text, is its embedding. In German the English word is used as is, sometimes translated as “Einbettung”.

An embedding model turns a text into a vector and returns no text. An LLM predicts how a text continues, word by word, and so writes answers. Both are usually neural networks, but they have different jobs. In a RAG system they work together: the embedding model finds the matching passages, the LLM writes the answer.

Yes, on at least one level for sure. Every transformer-based language model first turns tokens into vectors internally, as the 2017 Transformer paper describes. Those are the embeddings inside the model. On top of that, embedding models are a separate building block: tools that search files or a knowledge base usually compare vectors computed by such a model. OpenAI does not publish how ChatGPT is built in detail.

There is no single answer, because it depends on your language, your texts and your budget. Check these criteria: does the model support your language and your jargon? How long can an input be? How many dimensions does the vector have, and what does storing them cost? What is the price per million tokens, and can you run the model yourself if the data must not leave your premises? The public MTEB leaderboard on Hugging Face is a good starting point. The underlying benchmark covers 8 task types, 58 datasets and 112 languages, according to its paper. What decides it is a test with 20 to 50 real questions from your own material.

They are used when you search by similarity instead of exact matches: semantic search across documents, a knowledge store for RAG, product recommendations, finding duplicates and grouping texts. Whether you need a dedicated database depends on the volume. For small collections, an extension of your existing database is often enough.

No. SQL is a query language, not a database. Relational databases such as PostgreSQL work with SQL and can store vectors and find similar entries through extensions like pgvector. So a database with SQL access can become a vector database, but SQL alone does not make it one.
Sources and References
FH

Finn Hillebrandt

AI Expert & Blogger

Finn Hillebrandt is the founder of Gradually AI, an SEO and AI expert. He helps online entrepreneurs simplify and automate their processes and marketing with AI. Finn shares his knowledge here on the blog in 50+ articles as well as through the AI Business Club.

Learn more about Finn and the team, follow Finn on LinkedIn, join his Facebook group for ChatGPT, OpenAI & AI Tools or do like 17,500+ others and subscribe to his AI Newsletter with tips, news and offers about AI tools and online business. Also visit his other blog, Blogmojo, which is about WordPress, blogging and SEO.