AI glossary

What is a vector database, and when do you need one?

A vector database stores data as embeddings, lists of numbers that capture meaning, and finds the items closest in meaning to a query. A normal database answers "which rows match this value?". A vector database answers "which items are most similar to this?". That makes it the search layer behind most AI assistants that answer from your own content. I use MongoDB Atlas Vector Search for the assistant on this website, and I will use that build as the worked example here.

Discuss your AI search

The short definition

A vector database is a store built for similarity search over embeddings. You put in vectors, each linked to the original text or record. You query with another vector. It returns the nearest neighbours, ranked by how close they are.

The term covers two kinds of product. Some are dedicated vector databases built only for this job. Others are general databases with vector search added, such as PostgreSQL with the pgvector extension or MongoDB Atlas with Atlas Vector Search. Both do the same core job.

Why does this matter? Words are a poor guide to meaning. A user may type "cancel my plan" when your help page says "end your subscription". Keyword search misses that match. Vector search finds it, because the two phrases mean the same thing. That one gap is why so many AI apps now need a vector database.

What is a vector database doing under the hood?

Embeddings

An embedding model turns a piece of text into a vector, for example 768 or 1,536 numbers. Texts with similar meaning end up close together in that space. "How do I reset my password?" and "I forgot my login" land near each other, even though they share almost no words. That is the whole trick: closeness in numbers stands in for closeness in meaning.

Similarity metrics

To rank results, the database measures the distance between the query vector and each stored vector. The common measures are cosine similarity (the angle between vectors), dot product and Euclidean distance. Use the measure your embedding model was designed for. Cosine is the usual default for text.

Approximate nearest neighbour indexes

Comparing a query with every stored vector works for a few thousand items. After that it gets slow. Vector databases use approximate nearest neighbour (ANN) indexes, such as HNSW graphs, to find very close matches quickly without checking everything. You trade a tiny amount of accuracy for a large gain in speed. Most databases let you tune that balance.

Metadata filters

Real queries need more than similarity. You want the nearest passages that are published, in English, and allowed for this user. Good vector databases combine the vector search with filters on metadata fields, so results respect access rules and context.

Vector database vs traditional database

Traditional databaseVector database
Query styleExact match, ranges, joinsNearest by meaning
Typical question"Orders from customer 42""Passages about refund rules"
IndexB-tree and similarANN indexes such as HNSW
ResultRows that matchItems ranked by similarity score
StrengthPrecise, structured dataFuzzy, natural language and media

They work best together. Keyword search still wins for exact terms like product codes and names, so many systems run hybrid search: vector and keyword results combined.

Where vector databases are used

  • Retrieval augmented generation. The most common use today. The database finds the passages a model should answer from. My page on retrieval augmented generation explains the full pipeline.
  • Semantic search. Search boxes that understand what users mean, not only the words they type.
  • Recommendations. "More like this" for products, articles or listings.
  • Deduplication and clustering. Finding near-duplicate tickets, documents or records.
  • Agent memory. Letting an agent recall relevant past notes or decisions.

A real example: my website assistant

The assistant on this site answers questions about my work from my own content. Its search layer is MongoDB Atlas Vector Search:

  1. Knowledge entries from my CMS and every published blog post are split into passages.
  2. Each passage is embedded with gemini-embedding-001 at 768 dimensions and stored next to its text in MongoDB Atlas.
  3. A visitor's question is embedded the same way, and Atlas Vector Search returns the 5 closest passages by cosine similarity.
  4. The model answers from those passages only.

I picked Atlas because the site's content already lived there. One database meant one backup and no extra service to run. A content hash also tells the sync which passages changed, so unchanged text is never embedded again. The full build is in my website RAG chatbot case study.

How to choose one

  • Start where your data lives. If you already run PostgreSQL or MongoDB, their vector features are often enough and save you a second system.
  • Check filtering. Make sure you can filter by the metadata you need, especially permissions, inside the vector query.
  • Think about scale honestly. Most business assistants hold thousands to a few million passages, which general databases handle well. Dedicated vector databases make more sense at very large scale or with heavy query loads.
  • Plan for re-embedding. If you change embedding models, every vector must be rebuilt. Keep the source text so you can.
  • Test retrieval, not just the database. Keep a set of real questions and check that the right passages come back.

For why embeddings and tokens behave as they do inside a model, see my post Inside the Black Box. If you are building search or an assistant over your own data, my RAG chatbot development service covers it end to end, or you can get in touch.

Frequently asked questions

Do I need a dedicated vector database for RAG?

Not always. Many teams use vector search inside a database they already run, such as PostgreSQL with pgvector or MongoDB Atlas Vector Search. A dedicated vector database is worth it when scale, query volume or special features justify running another system.

What is the difference between a vector database and a vector index?

A vector index is the data structure that makes similarity search fast, such as an HNSW graph. A vector database is the full system around it: storage, metadata, filters, updates, backups and access control.

What is an embedding in a vector database?

An embedding is a list of numbers produced by an embedding model that represents the meaning of a piece of text, an image or another item. Similar items get similar embeddings, which is what makes similarity search possible.

Can a vector database replace keyword search?

Usually not on its own. Vector search is strong on meaning but can miss exact terms like codes, names and numbers. Hybrid search, which combines vector and keyword results, often gives the best results.

Is MongoDB a vector database?

MongoDB Atlas includes Atlas Vector Search, which adds vector indexes and similarity queries to a general document database. I use it for the assistant on this site because the content already lived in MongoDB.

Let's talk about your project

Software Architect, AI Native. Google Certified Generative AI Leader with 14+ years of experience.

Discuss your AI search