A vector database stores data as long lists of numbers called embeddings, and finds the items whose numbers sit closest to your question. That's how an AI app finds the paragraph about "cancelling a subscription" when the user typed "how do I stop paying".
A normal database matches exact values. A vector database matches meaning. That one difference is why every RAG chatbot, semantic search box and "similar products" widget needs one.
In this guide I'll explain embeddings in plain English, how similarity search works, what HNSW indexes do, and how a vector database fits into retrieval-augmented generation (RAG). I'll also show when plain Postgres with pgvector is enough, so you don't pay for a product you don't need.
Everything here comes from official docs and pricing pages, as of 11 November 2026. Some links are affiliate links. They don't change your price or what I recommend.

What is a vector database, in plain English?
A vector database is a database built to store embeddings and answer one question fast: which stored items are most similar to this one?
You give it a vector, for example the embedding of a user's question. It returns the nearest stored vectors, plus whatever you saved next to them: the original text, a source URL, a product ID.
Most vector databases also do the usual database jobs. They let you add, update and delete records, filter by metadata such as language or date, and keep separate collections for separate projects.
The key word is similar, not equal. A SQL query like WHERE title = 'refund policy' finds one exact row. A vector query finds the rows that mean roughly the same thing, even when they share no words at all.
What is an embedding (vector)?
An embedding is a list of numbers that an AI model produces to represent a piece of text, an image or another item. Items with similar meaning get similar numbers.
OpenAI's embeddings guide puts it simply: an embedding is a list of floating-point numbers, and the distance between two vectors measures how related they are. Small distances mean high relatedness.
The lists are long. OpenAI's text-embedding-3-small returns 1,536 numbers per input by default, and text-embedding-3-large returns 3,072. Each number is one dimension.
You can't picture 1,536 dimensions, but you can picture three. Imagine every sentence as a dot in a room. Sentences about refunds float in one corner, sentences about login problems in another. A question about "getting my money back" lands in the refunds corner, and the database returns its nearest neighbours.

Here's what getting an embedding looks like with OpenAI's API, adapted from its docs:
The response holds the vector, a long array of decimals. That array is what you store.
One rule matters more than any other: embed your documents and your questions with the same model. Vectors from different models live in different spaces, and comparing them returns nonsense.
How does a vector database find similar items?
It measures the distance between your query vector and the stored vectors, then returns the closest ones. This is called nearest-neighbour search.
There are a few common ways to measure that distance. pgvector, the Postgres extension, supports these operators:
| Measure | pgvector operator | What it compares |
|---|---|---|
| Cosine distance | <=> | The angle between two vectors, ignoring length |
| Euclidean (L2) distance | <-> | The straight-line gap between two points |
| Inner product | <#> | Direction and length together (pgvector returns it negative) |
| L1 distance | <+> | The sum of the gaps on each dimension |
Which one should you pick? Use what your embedding model recommends. OpenAI recommends cosine similarity, and notes that its embeddings are normalised to length 1, so cosine and Euclidean distance give identical rankings.
Why do vector databases use approximate search?
Because checking every vector is slow once you have millions of them. Approximate nearest-neighbour (ANN) indexes skip most of the work and still return almost the same top results.
pgvector spells out the trade-off clearly. Without an index it does exact nearest-neighbour search, which gives perfect recall. Add an approximate index and you trade some recall for speed, so a query can return slightly different results than before.
The two index types you'll meet most:
- HNSW (Hierarchical Navigable Small World) builds a layered graph. A search starts at a sparse top layer, hops towards the query, and drops down layers until it reaches close neighbours. The method comes from a 2016 paper by Yu. A. Malkov and D. A. Yashunin.
- IVFFlat splits vectors into lists, then searches only the lists closest to the query.
pgvector's docs say HNSW has a better speed-recall trade-off than IVFFlat but builds more slowly and uses more memory. IVFFlat builds faster and uses less memory, but its queries perform worse for the same recall.

For most projects under a few million vectors, HNSW is the safe default. Switch only when build time or memory becomes a real problem.
How does a vector database fit into RAG?
It's the memory of the pipeline. RAG retrieves relevant text from your own documents and hands it to an LLM with the question, so the answer is grounded in your data.
The vector database sits in the middle of that flow:
- Ingest: turn pages into clean text. My guide on how to scrape a website to markdown for LLMs covers this step.
- Chunk and embed: split the text into chunks and create an embedding for each one.
- Store: save every vector with its chunk text and source URL in the vector database.
- Retrieve: embed the user's question and fetch the top few nearest chunks.
- Generate: put those chunks into the prompt and let the model answer with citations.

Retrieval quality decides answer quality. If the right chunk never comes back from the database, no model can quote it. That's why chunk size, metadata and the embedding model matter more than which vector product you buy.
It's also why vector search alone has a blind spot: exact terms. Product codes, error codes and names can slip past a pure similarity search. Many teams run a keyword search next to the vector search and merge the results, which I explain in my RAG guide.
Do you need a dedicated vector database, or is pgvector enough?
For most small and mid-size projects, Postgres with pgvector is enough. A dedicated vector database earns its place when vectors are your main workload and you need scale or features Postgres doesn't give you.
Here's a minimal pgvector setup for chunks made with text-embedding-3-small:
That's the whole idea in one table. Your vectors sit next to the rest of your data, you keep normal SQL joins and backups, and there's no second system to run.
Know its limits, though. pgvector's HNSW and IVFFlat indexes support the vector type up to 2,000 dimensions, and the halfvec type up to 4,000. So a full 3,072-dimension text-embedding-3-large vector needs either fewer dimensions through the API's dimensions parameter, or halfvec.
Filtering also has a catch. pgvector applies WHERE conditions after the approximate index scan, so a narrow filter can return fewer rows than you asked for. Its docs suggest iterative index scans to fix this.
Which vector databases are popular, and what do they cost?
The main split is managed services versus open-source engines you can host yourself. Prices below come from each vendor's pricing page, as of 11 November 2026.
| Option | Type | Free option | Paid starting point |
|---|---|---|---|
| pgvector | Postgres extension, open source | Free to self-host | Your Postgres hosting cost |
| Pinecone | Managed service | Starter plan, up to 2 GB storage | Builder $20/month flat; Standard $50/month minimum usage |
| Qdrant | Open source (Apache-2.0), plus a cloud | Cloud free tier: 0.5 vCPU, 1 GB RAM, 4 GB disk | Standard tier billed hourly by usage |
| Weaviate | Open source, plus a cloud | Free to self-host | See Weaviate's pricing page |
| Chroma | Open source (Apache-2.0) | Free to self-host | Optional hosted cloud |
| Milvus | Open source (Apache-2.0) | Free to self-host | Optional managed versions |
A few notes to read the table properly:
- Pinecone is fully managed, so there's no server to run. Its Starter plan also caps you at 1M read units and 2M write units a month, and runs only in AWS us-east-1.
- Qdrant is written in Rust and is easy to run in Docker. Its free cloud cluster is fine for prototypes, but it has no high availability.
- Weaviate and Chroma are popular in Python AI stacks, and Milvus targets very large deployments.
- pgvector is the one to try first if your app already runs on Postgres.
Want to self-host Qdrant or Postgres with pgvector? A small VPS handles a prototype comfortably. I recommend a Hostinger KVM VPS for this kind of self-hosting, and my VPS security checklist covers the first steps after setup.
How do you use a vector database without writing code?
Use an automation tool that has vector store nodes built in. n8n has nodes for Pinecone, Qdrant, Supabase, PGVector, Weaviate, Chroma, Milvus, MongoDB Atlas, Redis and more, plus a Simple Vector Store that keeps vectors in memory for testing.
A typical no-code setup has two workflows. One loads documents, splits them, embeds them and inserts them into the store. The other takes a chat message, retrieves matching chunks and passes them to an AI agent as a tool. I build both, node by node, in my guide on how to build a RAG chatbot in n8n.
My guide on how to build an AI agent in n8n shows the agent side step by step.
What are vector databases used for besides RAG?
Anything that ranks items by meaning. OpenAI's embeddings guide lists the common jobs:
- Semantic search: results ranked by relevance to a query, not by keyword matches
- Recommendations: "more like this" for products, articles or videos
- Clustering: grouping support tickets or reviews by topic
- Classification: tagging text by comparing it to example labels
- Anomaly detection: spotting items far from everything else
AI agents use the same trick as long-term memory. An agent stores notes or past conversations as vectors, then retrieves the relevant ones when a new task starts. That's a different job from giving an agent live tools, which is what MCP (Model Context Protocol) handles.
What mistakes should you avoid?
Most vector search problems aren't database problems. They come from the data going in.
- Mixing embedding models. Re-embed everything if you switch models, because old and new vectors aren't comparable.
- Chunks that are too big or too small. Big chunks blur meaning, tiny ones lose context. Start with your tool's default and test with real questions.
- Storing vectors without metadata. Keep the source URL, title and date with every chunk, or you can't cite, filter or debug.
- Skipping evaluation. Write 20 real questions, check which chunks come back, and rerun them after every change.
- Trusting retrieved text blindly. Retrieved text can carry injected instructions, so treat it as untrusted input, as I explain in what prompt injection is.
Frequently asked questions
Building your first RAG app or semantic search? Start with pgvector on the Postgres you already have, and move to a dedicated vector database only when your tests say so.


