Last verified

Retrieval & data AI glossary

What is a vector database?

A vector database stores embeddings — numeric representations of text, images or other data — and returns the entries closest to a query's embedding, so software can search by meaning instead of exact words.

At a glance

  • How it works: Each record is embedded once and indexed; a query is embedded the same way, and an approximate nearest-neighbour search returns the closest records in milliseconds.
  • Why it matters: It is the retrieval layer of most RAG systems: it picks the few passages a model reads instead of making it read everything.
  • What it costs: Two meters: embedding tokens — text-embedding-3-small lists $0.02 per million — and the database's own storage, write and read charges.
  • Related to: Embeddings, RAG, context window, prompt caching.

How a vector database works

Ordinary search matches words. A vector database matches meaning, by working with embeddings: lists of numbers an embedding model produces so that texts with similar meaning end up close together. The flow has two halves.

  • Indexing. Split your documents into passages, run each through an embedding model, and store the resulting vectors with metadata — source, date, permissions — and the passage itself or a pointer to it. The database organises the vectors into an index built for fast lookup.
  • Querying. Embed the user's question with the same model, ask the database for the nearest vectors, optionally filter by metadata (only this customer's files, only this year), and get back the top few passages, ranked by similarity.

Because closeness is measured in meaning, a question about “cancelling my plan” can find a passage titled “ending your subscription” that shares no keywords with it.

Vector database, vector index or ordinary database

Three things get called by this name. A vector index library, such as FAISS, does the fast similarity search and nothing else: you manage storage, updates and backups yourself, and changing the data can mean rebuilding the index. A vector database wraps that search in the duties of a database — inserting, updating and deleting records as they change, filtering on metadata, scaling, backups, access control and separating customers' data. And an ordinary database with vector search adds the capability to a system you already run: the open-source pgvector extension, for example, gives PostgreSQL vector columns, exact and approximate nearest-neighbour search and the usual transactions and joins alongside them.

The choice is mostly operational. If your data already lives in Postgres and fits on one machine, adding vectors there avoids a second system to keep in sync. A dedicated service earns its place at large scale, under heavy write traffic, or when you would rather not run the infrastructure.

Approximate search and its trade-off

Comparing a query with every stored vector gives an exact answer, but the work grows with the size of the collection. Vector databases instead use approximate nearest-neighbour indexes that check only a small, promising part of it:

  • HNSW builds a layered graph of neighbours and walks it toward the query — fast and accurate, at the price of memory and build time.
  • IVF groups vectors into clusters and searches only the clusters nearest the query — cheaper to build, somewhat slower to query.
  • Product quantization compresses vectors into short codes so far more of them fit in memory, trading a little precision.

All of them give up a small amount of recall — occasionally missing a true nearest neighbour — for a large gain in speed. Closeness itself is measured by cosine similarity, dot product or Euclidean distance; the right one is usually whichever the embedding model was trained for.

Where it fits in RAG — and why it saves tokens

In retrieval-augmented generation, the vector database decides what the language model gets to read. Instead of pasting a whole manual into every prompt, the application retrieves the handful of passages most related to the question and sends only those. That improves answers by keeping the model focused, and it changes the bill at least as much: the model's input shrinks from the size of the corpus to the size of a few passages.

The worked example puts numbers on it for a support assistant answering from a 150,000-token product manual, once with the whole manual in every prompt and once with five retrieved passages. The alternative to retrieval is not always that crude — a large context window with the manual held in the prompt cache narrows the gap — but cached tokens are still billed on every request.

Worked exampleA support assistant: the whole manual, or five retrieved passages

10,000 requests a month on Claude Sonnet 5.5, priced at its current list rates, checked on 2026-10-09.

Whole 150,000-token manual in every prompt
Input · 1.5B tokens @ $2.00/M$3,000
Output · 4M tokens @ $10.00/M$40.00
Blended · per 1M tokens billed$2.02
Per request$0.304
Per month$3,040
Whole manual, 95% cached −88%
Input · 95% served from cache · 1.5B tokens @ $0.22/M$330
Output · 4M tokens @ $10.00/M$40.00
Blended · per 1M tokens billed$0.246
Per request$0.037
Per month$370
Five retrieved 500-token passages −97%
Input · 30M tokens @ $2.00/M$60.00
Output · 4M tokens @ $10.00/M$40.00
Blended · per 1M tokens billed$2.94
Per request$0.010
Per month$100

10,000 questions a month with a 400-token answer. The retrieval scenario assumes five passages of about 500 tokens plus the question and instructions; embedding the queries and running the database are billed separately and are not included here.

Change the workload or the model in the LLM API cost calculator.

What a vector database costs

Three separate meters add up to the cost of semantic search:

  • Embedding tokens. Every passage is embedded once when indexed and again whenever it changes; every query is embedded once. Embedding models are among the cheapest per token in our index — the panel below shows current rates — so this is usually the smallest line, except when you re-embed a whole corpus after switching embedding models, which you must, because vectors from different models are not comparable.
  • The database itself. Managed services meter what you store and how hard you use it. Pinecone's serverless plans, for example, bill storage per gigabyte-month, writes and reads in metered units, and data transferred out, with a free starter tier capped in each of those and paid tiers that carry a monthly minimum. Self-hosting swaps those meters for the servers, memory and maintenance.
  • The tokens you retrieve. Retrieved passages become input to the language model on every question, so the number and length of passages you send is a pricing decision as much as a quality one.

In our indexEmbedding models in our index

Embedding models 4 Baichuan, OpenAI, Tencent (Hunyuan)
Cheapest $0.02 text-embedding-3-small
Priciest $0.13 text-embedding-3-large
ModelVendorPer 1M input tokens
text-embedding-3-smallOpenAI$0.02
Baichuan Text EmbeddingBaichuan$0.0744
Hunyuan EmbeddingTencent (Hunyuan)$0.104
text-embedding-3-largeOpenAI$0.13

Counted at build from our price index: current embedding models with a published rate, read between 2026-07-11 and 2026-08-31. How we collect prices.

Do you need one?

Not always. A few hundred documents can be embedded and searched in memory with a library, or skipped entirely by putting them in a cached prompt. A team already on Postgres can add pgvector before adopting anything new. A dedicated vector database pays off when the collection is large, changes constantly, needs filtering by user or permission, or has to answer many queries a second — the point at which running search yourself stops being a side task.

Frequently asked.

Short answers to the questions that come up next.

Q · 01 What is a vector database used for? +
Searching by meaning: finding the documents, passages, products or images most similar to a query. Its most common job today is retrieval for RAG, where it supplies a language model with the few passages relevant to a question.
Q · 02 Do I need a vector database for RAG? +
Not necessarily. Small collections can be searched in memory or put directly into a cached prompt, and an existing Postgres database can do vector search with pgvector. A dedicated vector database earns its place at large scale or with heavy filtering and updates.
Q · 03 What is the difference between a vector database and a vector index? +
A vector index, such as FAISS, only performs the similarity search. A vector database adds database duties around it — updates and deletes, metadata filtering, scaling, backups and access control.
Q · 04 How is a vector database priced? +
Managed services typically meter storage per gigabyte-month, writes and reads in usage units, and data transfer, often with a free tier and a monthly minimum on paid plans. On top come the embedding tokens to index and query, and the language-model tokens for whatever you retrieve.
Q · 05 Can PostgreSQL be a vector database? +
With the open-source pgvector extension, yes: it adds vector types, exact and approximate nearest-neighbour search with HNSW and IVFFlat indexes, and cosine, inner-product and Euclidean distance, alongside Postgres transactions and joins.