
TL;DR
An embedding is a vector, a list of numbers, that stands for a piece of content such as a text. Related content gets vectors that lie close together, and a vector database stores these vectors and finds the nearest ones to a query. Its main limit is speed against accuracy: approximate search trades some recall for speed.
- Purpose: Embeddings measure how related two pieces of content are, so that software can search by meaning.
- Parts: An embedding model turns content into a vector, and a vector database stores vectors and answers nearest neighbor queries.
- Size: OpenAI's text-embedding-3-small returns 1536 numbers by default, and Google's Gemini embedding models return 3072.
- Origin: Mikolov and co-authors proposed word vectors in January 2013, and Karpukhin and co-authors tested dense retrieval in 2020.
- Limit: The pgvector documentation says approximate search trades some recall for speed.
What an embedding is
OpenAI writes that its text embeddings “measure the relatedness of text strings”. An embedding “is a vector (list) of floating point numbers”.
The distance between two vectors carries the meaning. In OpenAI's words: “Small distances suggest high relatedness and large distances suggest low relatedness.”
OpenAI lists six uses: search, clustering, recommendations, anomaly detection, diversity measurement and classification.
Google's Gemini documentation adds that embeddings are not limited to text. The Gemini API offers models for “text, images, video, and other content”. Google says embeddings give “more accurate, context-aware results than keyword-based approaches”.
Where the idea comes from
The first step was word vectors. In January 2013, Tomas Mikolov and three co-authors proposed two model architectures “for computing continuous vector representations of words from very large data sets”.
They report that it takes “less than a day to learn high quality word vectors from a 1.6 billion words data set”. The paper also describes an earlier finding. Simple algebra on word vectors gave a result: vector(“King”) - vector(“Man”) + vector(“Woman”) “results in a vector that is closest to the vector representation of the word Queen”.
To find the closest word, the paper searches the vector space “measured by cosine distance”.
How you get an embedding
You send content to an embedding model. OpenAI's documentation says to send your text string to its embeddings API endpoint, along with “the embedding model name”. The response “contains the embedding vector (list of floating point numbers) along with some additional metadata”.
The vector has a fixed length. OpenAI states: “By default, the length of the embedding vector is 1536 for text-embedding-3-small or 3072 for text-embedding-3-large.” Its table lists a maximum input of 8192 for each model. Our explainer on tokens covers what that unit is: Tokens and Context Windows: What the Numbers Mean
Google's models also return 3072 numbers by default. The Gemini documentation says you can truncate this to a smaller size “to save storage space”. It recommends 768, 1536 or 3072 dimensions.
Not every model maker offers embeddings. Anthropic's documentation says: “Anthropic does not offer its own embedding model.” It points to Voyage AI as one provider and adds that you “should assess a variety of embeddings vendors to find the best fit”.
How similarity is measured
OpenAI recommends cosine similarity. It adds: “The choice of distance function typically doesn't matter much.”
OpenAI embeddings are normalized to length 1. That has two effects, according to the documentation. Cosine similarity can be computed with just a dot product, and cosine similarity and Euclidean distance give identical rankings.
Google makes a similar point about direction. Its documentation says normalized embeddings ensure that “semantic similarity is calculated via vector direction rather than magnitude”.
The pgvector documentation lists six distance types: L2 distance, inner product, cosine distance, L1 distance, Hamming distance and Jaccard distance.
What a vector database does
A search needs a way to compare one vector with many. OpenAI's answer: “For searching over many vectors quickly, we recommend using a vector database.”
pgvector is one example. It describes itself as “Open-source vector similarity search for Postgres”. The idea is to “Store your vectors with the rest of your data”.
A search can run in two ways. The pgvector documentation says: “By default, pgvector performs exact nearest neighbor search, which provides perfect recall.” You can add an index to use approximate nearest neighbor search, “which trades some recall for speed”.
The documentation warns that “you will see different results for queries after adding an approximate index”.
It supports two index types, HNSW and IVFFlat. An HNSW index “creates a multilayer graph”. The documentation says it has better query performance than IVFFlat, but slower build times and more memory use.
What the search papers report
The HNSW paper, submitted on March 30, 2016, presents an approach for approximate K-nearest neighbor search “based on navigable small world graphs with controllable hierarchy”. Its authors say the structure allows “a logarithmic complexity scaling”.
The FAISS paper, submitted on February 28, 2017, is about similarity search on graphics processors. The authors report a nearest neighbor implementation that is “8.5x faster than prior GPU state of the art”.
They also report that their implementation builds “a graph connecting 1 billion vectors in less than 12 hours on 4 Maxwell Titan X GPUs”. These are the authors' own measurements.
Embeddings in retrieval
Embeddings are also used to find passages. The DPR paper, submitted on April 10, 2020, shows that retrieval “can be practically implemented using dense representations alone”.
The authors say their dense retriever outperforms a strong Lucene-BM25 system “largely by 9%-19% absolute in terms of top-20 passage retrieval accuracy”. That is their result on their test sets.
The RAG paper, submitted on May 22, 2020, uses a vector index as memory. Its non-parametric memory is “a dense vector index of Wikipedia”.
Google's documentation calls RAG “a common use case for AI products”. Our explainer shows the full chain: What Is RAG? Retrieval-Augmented Generation Explained
OpenAI's search example shows the pattern. To find the most relevant documents, it uses “the cosine similarity between the embedding vectors of the query and each document”. In its code search example, the query is embedded with the same model that indexed the functions.
What embeddings do not do
The pgvector documentation shows one limit in the open. An approximate index can return different results than an exact search.
The documentation of the providers is open about choice. Anthropic names criteria such as inference performance and customization. It says larger or more domain-specific data “generally produces better in-domain embeddings”.
Benchmark figures come from the makers. OpenAI lists 62.3% on the MTEB evaluation for text-embedding-3-small. That is OpenAI's own listing.
What this article does not cover
We did not build an index and we did not run any search. We read the abstracts of the papers, not their full texts, except for the word vector paper.
We do not compare vector database products or their prices. Model names and defaults change, so check the provider's page before you build.
Sources
- OpenAI, Vector embeddings (API documentation): https://platform.openai.com/docs/guides/embeddings
- Google, Embeddings (Gemini API documentation): https://ai.google.dev/gemini-api/docs/embeddings
- Anthropic, Embeddings (Claude Platform Docs): https://docs.anthropic.com/en/docs/build-with-claude/embeddings
- pgvector, README (open-source vector similarity search for Postgres): https://github.com/pgvector/pgvector
- Mikolov et al., Efficient Estimation of Word Representations in Vector Space (arXiv:1301.3781): https://arxiv.org/abs/1301.3781
- Malkov and Yashunin, Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs (arXiv:1603.09320): https://arxiv.org/abs/1603.09320
- Johnson, Douze and Jégou, Billion-scale similarity search with GPUs (arXiv:1702.08734): https://arxiv.org/abs/1702.08734
- Karpukhin et al., Dense Passage Retrieval for Open-Domain Question Answering (arXiv:2004.04906): https://arxiv.org/abs/2004.04906
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv:2005.11401): https://arxiv.org/abs/2005.11401







