What Is a Vector Database?

Search for "cheap flights to Goa" in a normal database and you'll only find rows containing those exact words. A row that says "budget airfare to Goa" gets missed, even though it means the same thing.

A vector database fixes that. It stores data as lists of numbers that capture meaning, and it finds the items whose meaning is closest to your query. That's what powers semantic search, recommendations and most AI chatbots that answer from your own documents.

This guide explains how vector databases work, which one to pick, and when a regular Postgres database is enough.


🎯 Quick Answer (30-Second Read)

  • What it is: a database built to store embeddings (vectors of numbers) and find the most similar ones quickly.
  • How it works: turn text or images into vectors with an embedding model, store them, then search by similarity rather than exact match.
  • Why it's fast: it uses approximate nearest neighbour (ANN) indexes such as HNSW instead of comparing every vector.
  • Most common use: RAG, which gives an AI model the right passages from your own data before it answers.
  • Start simple: if you already use Postgres or Supabase, pgvector is usually enough. Move to a dedicated vector database when measurements show you need it.

How a Vector Database Works

flowchart LR A([📄 Your documents]) --> B[Split into chunks] B --> C[Embedding model
text → vector] C --> D[(Vector database
vectors + metadata)] Q([🔎 User question]) --> E[Same embedding model] E --> F{Similarity search
ANN index} D --> F F --> G([Top matching chunks]) style A fill:#0f172a,color:#ffffff,stroke:#334155 style Q fill:#0f172a,color:#ffffff,stroke:#334155 style D fill:#312e81,color:#ffffff,stroke:#6366f1 style F fill:#78350f,color:#ffffff,stroke:#f59e0b style G fill:#166534,color:#ffffff,stroke:#16a34a style B fill:#1e293b,color:#ffffff,stroke:#475569 style C fill:#1e293b,color:#ffffff,stroke:#475569 style E fill:#1e293b,color:#ffffff,stroke:#475569

1. Embeddings turn meaning into numbers

An embedding model converts a piece of text (or an image) into a vector: a long list of numbers, often hundreds or thousands of them. Texts with similar meaning get vectors that point in similar directions.

"Budget airfare to Goa" and "cheap flights to Goa" end up close together. "How to bake bread" ends up far away.

2. Similarity is just geometry

To compare two vectors, the database measures how close they are. The three common measures:

Metric What it measures Typical use
Cosine similarity Angle between vectors (direction) Text search; the most common default
Dot product Direction and length Models trained for it; fast to compute
Euclidean (L2) distance Straight-line distance Images and some recommendation models

A tiny example. Take two 2-number vectors, A = [1, 0] and B = [0.8, 0.6]. Their cosine similarity is (1×0.8 + 0×0.6) ÷ (1 × 1) = 0.8, which is fairly similar. Real embeddings work the same way, just with far more numbers.

3. Indexes make it fast

Comparing a query with every stored vector (exact search) is fine for a few thousand items, but it gets slow as data grows. Vector databases use approximate nearest neighbour (ANN) indexes, which trade a tiny bit of accuracy for big speed gains:

  • HNSW (Hierarchical Navigable Small World): builds a layered graph and hops toward the nearest neighbours. Fast, high recall, but memory-hungry. It's the most popular choice today.
  • IVF (inverted file index): groups vectors into clusters and only searches the closest clusters.
  • PQ (product quantization): compresses vectors to save memory, at some cost to accuracy.

The key trade-off is recall vs speed vs memory. Most databases let you tune it.


Why Not Just Use a Normal Database?

Regular databases are excellent at exact questions: "orders where status = 'paid'". Full-text search adds keyword matching. Neither understands that "car" and "automobile" mean the same thing.

Vector search finds meaning, but it can miss exact terms like product codes or names. That's why many production systems use hybrid search: keyword search and vector search together, with results merged.


Where Vector Databases Are Used

  • RAG (retrieval-augmented generation): fetch the most relevant passages from your docs and pass them to an AI model, so answers are grounded in your data. See RAG Explained.
  • Semantic search: search help centres, codebases or notes by meaning.
  • Recommendations: "similar products", "similar articles", "people also watched".
  • Duplicate detection: find near-identical tickets, questions or images.
  • Image and audio search: find visually or acoustically similar items.

Popular Vector Databases Compared

Option Type Best for
pgvector Postgres extension (open source) Teams already on Postgres/Supabase who want vectors next to their app data
Pinecone Fully managed service Teams that want zero infrastructure work
Qdrant Open source (Rust), self-host or cloud Fast filtering on metadata, self-hosting
Weaviate Open source, self-host or cloud Built-in hybrid search and modules
Milvus Open source, self-host or cloud (Zilliz) Very large collections
Chroma Open source, lightweight Prototypes and local development

Elasticsearch and OpenSearch also support vector search, which helps if you already run them for keyword search.


Step-by-Step: Vector Search With pgvector (Supabase or Postgres)

  1. Enable the extension
create extension if not exists vector;
  1. Create a table with a vector column. Set the size to your embedding model's dimensions (1,536 here is just an example).
create table documents (
  id bigserial primary key,
  content text,
  embedding vector(1536)
);
  1. Add an HNSW index for cosine similarity
create index on documents using hnsw (embedding vector_cosine_ops);
  1. Insert rows. Generate each embedding with your embedding model in your app, then insert it with the text.

  2. Search by meaning. <=> is pgvector's cosine distance operator, so smaller means more similar.

select id, content
from documents
order by embedding <=> '[0.12, -0.03, ...]'  -- the query's embedding
limit 5;

pgvector also has <-> for Euclidean distance and <#> for (negative) inner product.


Do You Actually Need a Dedicated Vector Database?

Start with pgvector if:

  • you already use Postgres or Supabase
  • you want vectors, metadata and app data in one place, with normal SQL joins and permissions
  • your dataset and query volume are modest

Consider a dedicated vector database when:

  • measurements show index memory or query latency becoming a bottleneck
  • you need very high query volume, heavy metadata filtering at scale, or multi-tenant isolation
  • you'd rather not tune indexes yourself (managed services)

Moving later is normal. The embeddings stay the same, and only the storage changes.


Limitations and Trade-offs

  • Results are approximate. ANN indexes can occasionally miss a true nearest neighbour. Tune recall for your needs.
  • Garbage in, garbage out. Chunk size, chunk overlap and embedding model choice affect quality more than the database you pick.
  • Embeddings cost money and time. Every document must be embedded, and re-embedded if you switch models.
  • Vectors aren't keywords. Exact names and codes often need hybrid search.
  • Memory. HNSW indexes can need a lot of RAM at large scale.

Example Scenario

An illustrative example, not a real case study.

A SaaS team wants its support chatbot to answer from 2,000 help articles. They split each article into short chunks, embed them, and store them in pgvector inside their existing Supabase database. When a user asks a question, they embed the question, fetch the five closest chunks, and pass them to the AI model. Because everything lives in Postgres, they reuse the same row-level permissions so each customer only searches their own documents.


Frequently Asked Questions

What is the difference between an embedding and a vector database?
An embedding is the list of numbers a model produces for a piece of text or an image. A vector database is where you store many embeddings and search them by similarity. You need an embedding model to create vectors and a vector store (such as pgvector or Pinecone) to search them quickly.

Is pgvector good enough for production?
For many applications, yes. It supports HNSW and IVFFlat indexes, runs inside Postgres, and keeps vectors next to your app data with normal SQL, joins and permissions. Teams typically move to a dedicated vector database only when measurements show memory, latency or query-volume limits they can't tune away.

Do I need a vector database for RAG?
You need some way to find relevant passages quickly. For a small set of documents, simple exact search can work. As your content grows, a vector index (pgvector or a dedicated vector database) keeps retrieval fast. Many RAG systems also add keyword search for exact names and codes.

What is approximate nearest neighbour search?
Approximate nearest neighbour (ANN) search finds vectors that are very likely the closest to your query without comparing every stored vector. Indexes like HNSW and IVF make this fast at large scale, at the cost of occasionally missing the true closest match. You can usually tune that balance.

Which similarity metric should I use?
Use the metric your embedding model was designed for. Check its documentation. Cosine similarity is the most common default for text embeddings. Dot product and Euclidean distance are used by some models and for some image or recommendation tasks.


Conclusion

A vector database stores embeddings and finds the closest matches by meaning, using ANN indexes like HNSW to stay fast. It's the backbone of RAG, semantic search and recommendations.

For most teams, the practical path is: start with pgvector in the database you already have, measure, and move to a dedicated vector database only when the numbers say so.


Sources

Last verified: 14 October 2026.


Related reads: RAG Explained · Claude Models Explained · Redis Explained · PostgreSQL vs MySQL · How AI Agents Work

I write about AI infrastructure and how real products are built. Follow on LinkedIn or X, or invite me to speak.