SysArt
Book a briefing
SysArt

Explainer

What is a vector embedding?

Embeddings let software compare meaning instead of matching words. This explainer covers how they are made, how vector search uses them, how to choose an embedding model and how to secure them.

Last reviewed by SysArt AI Architecture Team6 min readHow we review

In short

A vector embedding is a list of numbers that represents the meaning of a piece of text, an image or other data. An embedding model produces it so that similar meanings land close together. Vector search compares a question's embedding with stored ones to find passages with similar meaning, which is how many RAG systems retrieve information.

DefinitionA vector embedding is a fixed-length list of numbers that a trained model produces to represent a piece of data, such as a sentence or a passage, so that items with similar meaning end up close together and their similarity can be measured mathematically.

Key takeaways

  • An embedding model turns text into a fixed-length vector; passages with similar meaning get vectors that are close together.
  • Vector search finds the stored vectors nearest to a query's vector, usually through an approximate index such as HNSW that trades a little recall for speed.
  • Keyword search and vector search fail in different ways, so enterprise retrieval usually combines them in hybrid search.
  • Vectors from different embedding models cannot be compared: changing the model means re-embedding the whole collection.
  • Text can be partly reconstructed from its embeddings, so protect and permission them like the source documents.

What is a vector embedding?

A vector embedding is a list of numbers, a vector, that represents the meaning of a piece of data such as a sentence, a passage or an image. A trained embedding model produces it so that items with similar meaning get vectors that lie close together.

Take two support questions: “How do I reset my password?” and “I forgot my login details”. They share almost no words, so a keyword search treats them as unrelated, but an embedding model can place them close together because they mean nearly the same thing. Every vector from a given model has the same number of dimensions, so software can compare any two of them with simple arithmetic.

The idea is not new. In 2013, Mikolov and colleagues showed that high-quality word vectors could be learned from a corpus of 1.6 billion words in about a day of training. Sentence-BERT, published in 2019, produced sentence embeddings that can be compared with cosine similarity, and cut the time needed to find the most similar pair among 10,000 sentences from about 65 hours with BERT to about 5 seconds. The gain comes from the structure: each text is encoded once, and comparing two vectors is cheap.

How are embeddings created?

An embedding model, a neural network trained so that related texts produce nearby vectors, encodes each text into a vector. Documents are encoded when they are indexed, and questions are encoded at search time with the same model.

Retrieval models are typically trained on pairs of texts that belong together, such as a question and the passage that answers it, and learn to place each pair close together and unrelated texts further apart. The dense passage retrieval paper, for example, learned its embeddings from questions and passages with a dual-encoder set-up. Three practical consequences follow:

  • Use the same model for documents and queries, or the pair of encoders the model was designed with.
  • Respect the input limit. Models accept a limited amount of text, so long documents are split into passages before encoding, as described in our explainer on retrieval-augmented generation.
  • Keep the model version with the vectors. Similarity is only meaningful between vectors produced by the same model.

How does vector search find similar text?

It encodes the question, then looks for the stored vectors closest to it according to a distance measure such as cosine distance. At scale it uses an approximate index that gives up a little recall for much faster search.

  • Distance measures. Cosine distance compares the direction of two vectors, inner product also takes their length into account, and Euclidean (L2) distance measures the straight-line gap between them. pgvector, for example, supports L2, inner product, cosine and L1 distance.
  • Exact or approximate search. Comparing a query with every stored vector gives perfect recall but slows down as the collection grows. Approximate nearest neighbour (ANN) indexes avoid this. HNSW, a graph-based index described by Malkov and Yashunin, starts its search in sparse upper layers and moves down to denser ones, which its authors report gives logarithmic complexity scaling. In pgvector, HNSW gives a better speed-recall trade-off than the IVFFlat index, at the cost of slower builds and more memory.
  • Filters. Metadata such as source, date and access rights narrows the search, so a user only gets passages they may read.

The index can live in a dedicated vector database, a search engine with vector support or an extension to a database you already run. Our enterprise RAG page discusses how to choose.

Vector search matches meaning, keyword search matches terms, and hybrid search combines the two, which is usually the safer choice for enterprise retrieval.

Keyword search (for example BM25)Vector searchHybrid search
What it matchesThe words in the query and their variantsMeaning, even when the wording differsBoth
Strong atProduct codes, names, error messages, legal referencesParaphrases and questions in natural languageQueries that mix exact terms with meaning
Weak atSynonyms and different wordingRare exact phrases and codes, and domains unlike the model’s training dataMore settings to tune, including how to merge the two
IndexAn inverted index of termsA vector index such as HNSWBoth, with the scores merged
Why a result matchedVisible: the matching termsA similarity score onlyBoth signals

The research supports combining them. The dense passage retrieval paper observed that BM25 is sensitive to highly selective keywords and phrases, while dense retrieval captures different wording and semantic relationships better but may not represent rare, salient phrases well. In the BEIR benchmark, which tests retrieval across varied domains, BM25 proved a robust baseline, dense retrievers often underperformed other approaches, and reranking and late-interaction models scored best on average, at a higher computational cost. Search engines such as OpenSearch merge keyword and vector results either by normalising the scores or by reciprocal rank fusion, which combines results by their rank in each list.

How do you choose an embedding model?

Test candidates on your own documents and questions. Public benchmarks help you shortlist, but no model is best at everything.

The Massive Text Embedding Benchmark (MTEB) covers 8 task types, 58 datasets and 112 languages, and its authors found that no particular embedding method dominates across all tasks. Shortlist on:

  • Languages. European deployments usually need strong performance in more than one language.
  • Domain. Legal, medical and technical text can behave differently from general web text.
  • Input length and vector size, which drive how documents are chunked, how much storage the index needs and how much memory it uses.
  • Speed, both for indexing large collections and for search latency.
  • Licence and deployability, including whether the model can run on your own infrastructure.

Then build a small retrieval test set: real questions, each with the passages that should be found, and measure how often each candidate returns them among the top results.

What happens when you change the embedding model?

You re-embed the whole collection. Each model defines its own vector space, so vectors from an old and a new model cannot be compared or mixed in one index.

A safe procedure has three steps:

  1. Build the new index alongside the old one.
  2. Run the retrieval test set against both.
  3. Switch over only when the new index performs at least as well, then retire the old one.

Changes to parsing or chunking follow the same procedure, because they change what each vector represents. Record which model and version produced each index, so that search results can be traced back.

How should you secure and govern embeddings?

Treat embeddings as being as sensitive as the text they came from, because the text can be partly reconstructed from them.

In a 2023 study, Morris and colleagues recovered 92% of 32-token text inputs exactly from their embeddings, and recovered full names from a dataset of clinical notes. OWASP lists embedding inversion among the vector and embedding weaknesses of LLM applications, alongside unauthorised access, leaks between users of shared stores and data poisoning. In practice:

  • Apply the source permissions to vectors and search results, and partition indexes between user groups.
  • Protect the store with the same encryption, access logging and retention rules as the source documents.
  • Delete with the source. When a document is removed, or personal data in it must be erased, delete its vectors too.
  • Validate sources before indexing them, to limit poisoning.
  • Encode close to the data. Running the embedding model on your own infrastructure, for example on the same platform used for LLM inference serving, keeps document text from leaving your boundary just to be encoded.

Our AI security work covers these controls, and the on-premises AI reference architecture shows where the embedding model and the index sit.

Frequently asked questions

What is a vector embedding in simple terms?

It is a list of numbers that stands for the meaning of a piece of text. An embedding model produces the list so that texts with similar meaning get similar numbers. Software can then measure how close two texts are in meaning, which is what semantic search and many retrieval-augmented generation systems rely on.

What is the difference between an embedding and a vector database?

An embedding is the vector itself, produced by an embedding model. A vector database, or a vector index inside another database or search engine, stores many embeddings with their metadata and quickly finds the ones nearest to a query. pgvector, for example, adds vector types, distance operators and HNSW and IVFFlat indexes to PostgreSQL.

What is cosine similarity?

Cosine similarity measures the angle between two vectors: vectors pointing in the same direction score 1, perpendicular ones score 0 and opposite ones score minus 1. It is a common way to compare text embeddings because it ignores the length of the vectors. Sentence-BERT, for example, was designed to produce sentence embeddings that can be compared with cosine similarity.

Do embeddings work across languages?

It depends on the model. Some embedding models are trained on many languages, others mainly on English, and quality varies by language and task. The MTEB benchmark covers 112 languages, and its authors found that no embedding method dominates across all tasks. Test candidates with questions and documents in the languages your users actually work in.

Can embeddings be reversed to recover the original text?

Partly, yes. In a 2023 study, Morris and colleagues recovered 92% of 32-token text inputs exactly from their embeddings, and recovered full names from a dataset of clinical notes. OWASP lists embedding inversion among vector and embedding weaknesses. Protect stored vectors with the same access controls, encryption and retention rules as the documents they came from.

Do we need to re-embed documents when we change the embedding model?

Yes. Each embedding model defines its own vector space, so vectors from an old and a new model cannot be compared. Build the new index alongside the old one, run your retrieval test set against both, and switch only when the new index performs at least as well. Changes to parsing or chunking follow the same procedure.

Should we use keyword search, vector search or both?

Usually both. Keyword search, such as BM25, is strong on exact terms like product codes and names; vector search finds passages that express the same meaning in different words. Hybrid search runs both and merges the results, by normalising scores or by reciprocal rank fusion, and a reranker can then reorder the best candidates.

Can embedding models run on-premises?

Yes. Open-weight embedding models can run on the same inference platform as your language models, as a separate deployment sized for their own load. Running them in-house keeps document text and questions inside your boundary, which matters because the vectors themselves can reveal much of the text they encode.

Get retrieval right before you scale it

Bring sample documents and real questions. We test embedding models and search set-ups against them and show which combination finds the right passages.