What Is a Vector Database? (And When Postgres pgvector Is Enough)
A vector database stores embeddings and finds the closest matches to a query. Learn how vector search works, what HNSW indexes do, and when Postgres with pgvector is enough.

A vector database stores embeddings, which are lists of numbers that represent text, images, or other data, and answers one main question: which stored items are closest to this one? That is the retrieval step behind semantic search, recommendations, and many retrieval-augmented generation (RAG) systems.
The harder question for most teams is not what a vector database is. It is whether you need a separate one, or whether the PostgreSQL database you already run can do the job with the pgvector extension. This guide keeps the theory short and spends most of its time on that decision.
All pgvector details below were checked against the official pgvector README on 9 November 2026, when the latest release was 0.8.7.
What a vector database is
A vector database is a system built to store vectors and run similarity search over them quickly, usually alongside some metadata such as an ID, a tenant, or a date. Instead of asking “which rows have status = 'open'?”, you ask “which rows are most similar to this query vector?”
There are two broad ways to get that capability:
- A dedicated vector database, a system whose main job is vector storage and search. Pinecone and Weaviate, both cited later in this guide, are examples of the category. They are named here as examples, not as a ranking.
- A vector-capable general database, such as PostgreSQL with pgvector, where vectors sit in an ordinary table next to the rest of your data. Weaviate, itself a vector database vendor, describes this split as “vector database vs. vector-capable database.”
Both store vectors and find near neighbors. They differ in what else comes with them, and in what you have to operate.
What an embedding is
An embedding is a list of numbers produced by a machine learning model to represent a piece of data. Google’s Machine Learning Crash Course describes embeddings as lower-dimensional, dense representations that capture semantic relationships. Its example: a model should learn that a hot dog is more like a shawarma than a salad.
The practical consequence is simple. Items with similar meaning end up with vectors that are close together, so “find similar things” becomes “find nearby vectors.” The number of values in each vector is its dimension. That number is fixed by the embedding model you choose, and it matters later because pgvector’s index limits are expressed in dimensions.
How vector search works

Exact search vs approximate search
The simplest approach compares the query vector with every stored vector and returns the closest ones. pgvector does this by default. Its README says that without an index it “performs exact nearest neighbor search, which provides perfect recall.”
Comparing against everything gets slow as the table grows, so most systems add an approximate nearest neighbor (ANN) index. pgvector’s README says an approximate index “trades some recall for speed.” It also warns that, unlike typical indexes, “you will see different results for queries after adding an approximate index.” Recall here means the share of true nearest neighbors the search actually returns.
Similarity metrics
“Closest” needs a definition. pgvector supports these distance operators:
<->L2 (Euclidean) distance<#>negative inner product<=>cosine distance<+>L1 distance<~>Hamming distance (binary vectors)<%>Jaccard distance (binary vectors)
Use the metric your embedding model was designed for. The README notes that if vectors are normalized to length 1, inner product gives the best performance for exact search. It also explains that <#> returns the negative inner product, because Postgres only supports ascending-order index scans on operators.
HNSW and IVFFlat in brief
pgvector offers two approximate index types. The ideas behind them are not specific to Postgres, but the parameter names below are pgvector’s.
HNSW (Hierarchical Navigable Small World). The original paper by Malkov and Yashunin describes a multi-layer structure of proximity graphs. Each element appears up to a randomly chosen top layer, with higher layers holding fewer elements. A search starts at the sparse top layer and works down through denser layers toward the closest matches. The paper reports logarithmic complexity scaling. In pgvector, the README says HNSW has a better speed-recall trade-off than IVFFlat, but slower build times and more memory use. Because there is no training step, you can create an HNSW index on an empty table.
IVFFlat. pgvector’s README says an IVFFlat index “divides vectors into lists, and then searches a subset of those lists that are closest to the query vector.” It builds faster and uses less memory than HNSW, with a weaker speed-recall trade-off. The README’s advice is to create it only after the table has data, choose the number of lists based on the row count, and tune how many lists each query probes.
Both indexes come with a tuning knob that trades recall for speed at query time: hnsw.ef_search and ivfflat.probes. Higher values improve recall at the cost of speed. How much depends on your data, so measure it on your own workload rather than trusting anyone’s published figures.
Vector database vs relational database
A relational database is built around exact matches, ranges, joins, and transactions. PostgreSQL’s documentation describes its default B-tree index as handling “equality and range queries on data that can be sorted into some ordering.” That fits “orders from last week,” not “documents that mean roughly the same as this question.”
Vector search needs a different kind of index, ordered by distance to a query. Extensions like pgvector blur the line by adding vector types and ANN indexes to a relational database. The pgvector README pitches it as “Store your vectors with the rest of your data,” plus ACID compliance, point-in-time recovery, and JOINs.
What a dedicated system usually adds is a design centered on vector workloads. Vendors describe features such as filtering inside the index, built-in sharding, and managed scaling. Treat those as company claims to verify for your case. What it usually costs is a second system to run, secure, back up, and keep in sync with your main database.
pgvector: vectors inside Postgres
pgvector is an open-source PostgreSQL extension. The README for the current release, 0.8.7, says it supports Postgres 13+. The changelog for the unreleased 0.9.0 lists “Dropped support for Postgres 13 and 14,” so check the version you install. Here is a small illustrative schema using syntax from the README. The three-dimension vectors are only for readability: real embedding models produce hundreds or thousands of dimensions.
CREATE EXTENSION vector;
CREATE TABLE documents (
id bigserial PRIMARY KEY,
tenant_id int,
content text,
embedding vector(3)
);
Insert or update an embedding with a normal upsert, which uses PostgreSQL’s ON CONFLICT clause:
INSERT INTO documents (id, tenant_id, content, embedding)
VALUES (1, 42, 'Reset your password from the account page.', '[0.1,0.2,0.3]')
ON CONFLICT (id) DO UPDATE SET embedding = EXCLUDED.embedding;
Add an HNSW index for cosine distance, then query the nearest neighbors within one tenant:
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);
SELECT id, content
FROM documents
WHERE tenant_id = 42
ORDER BY embedding <=> '[0.1,0.2,0.25]'
LIMIT 5;
The README notes that a query needs ORDER BY a distance operator in ascending order plus a LIMIT to use the index.
pgvector limits worth knowing
These limits come straight from the pgvector README, checked on 9 November 2026:
| Type | Storage limit | Index limit (HNSW and IVFFlat) |
|---|---|---|
vector |
up to 16,000 dimensions | up to 2,000 dimensions |
halfvec |
up to 16,000 dimensions | up to 4,000 dimensions |
bit |
not stated as a dimension cap in the README | up to 64,000 dimensions |
sparsevec |
up to 16,000 non-zero elements | HNSW only, up to 1,000 non-zero elements |
If your embedding model outputs more than 2,000 dimensions, the README suggests half-precision indexing (up to 4,000 dimensions), binary quantization (up to 64,000), indexing subvectors for models that support it, or dimensionality reduction.
The filtering catch
This is the pgvector behavior most likely to surprise you. The README’s filtering section says that with approximate indexes, “filtering is applied after the index is scanned.” Its own example: if a condition matches 10% of rows, an HNSW scan with the default hnsw.ef_search of 40 returns only about 4 matching rows on average.

pgvector documents several fixes:
-
Iterative index scans, available from 0.8.0. They keep scanning more of the index until there are enough results, up to
hnsw.max_scan_tuples(20,000 by default) orivfflat.max_probes. Strict ordering keeps results exactly sorted by distance, and relaxed ordering allows slight reordering for better recall. The settings arehnsw.iterative_scanandivfflat.iterative_scan; the README’s IVFFlat example usesrelaxed_order.SET hnsw.iterative_scan = strict_order; -
An ordinary index on the filter column, which the README says can give fast exact search when the filter matches a low percentage of rows.
-
Partial indexes when you filter by only a few distinct values.
-
Partitioning when you filter by many values. For multitenant apps, the README warns that sharing one approximate index across tenants lets one tenant’s vectors affect recall and speed for others, and it recommends list partitioning or separate tables for isolation.
Pinecone, a dedicated vector database vendor, makes the same point about post-filtering and says its own pg_pinecone extension filters inside the index. That is a company claim about its own product.
The decision guide: is pgvector enough?
This section is editorial guidance. It applies documented pgvector capabilities and limits to common situations. It is not a benchmark, and no option is right for every workload.
| Criterion | pgvector is likely enough when | Consider a dedicated vector database when |
|---|---|---|
| Existing Postgres footprint | You already run Postgres, and the vectors describe rows that live there. | You have no Postgres, or the vector workload would be the only reason to start running it. |
| Data size and growth | The data fits comfortably on one well-sized instance, or you can grow with more memory, read replicas, or partitions, as the README describes. | You expect to need horizontal sharding for vectors alone, and your team doesn’t want to run Postgres sharding tools such as Citus or PgDog, which the README mentions. |
| Embedding dimensions | Your model’s output is within pgvector’s index limits, or you accept halfvec indexing or quantization. | You need to index full-precision vectors above 2,000 dimensions and don’t want those workarounds. |
| Write and update patterns | Embeddings change along with the rows they describe, and you value updating both in one transaction. | Index builds, memory use, or HNSW vacuuming (which the README says “can take a while”) get in the way of your write rate. Confirm this with your own tests first. |
| Filtering and joins | Filters are simple, or partial indexes, partitioning, and iterative scans cover them. You want to join search results to other tables (users, permissions, products) in the same query. | Many queries combine highly selective, varied filters with ANN search, and you need a predictable number of results every time. Joins to your other data are rare or can happen in application code. |
| Latency expectations | You can tune ef_search or probes, read EXPLAIN (ANALYZE, BUFFERS), and accept the recall trade-off. |
Your target is strict, and your own tests show tuned pgvector cannot meet it on your data. |
| Ops and team skills | The team already tunes, monitors, and backs up Postgres. pgvector adds an extension to install and upgrade (ALTER EXTENSION vector UPDATE). |
Nobody wants to tune Postgres memory settings for index builds, and a managed service’s operating model suits the team better. |
| Cost of another system | You want one system to secure, back up, and monitor, and one source of truth. | The benefits outweigh a second system, a sync pipeline, and the work of keeping two data stores consistent. |
Table notes: the dimension limits, post-index filtering, iterative scans, partitioning advice, HNSW vacuuming, ALTER EXTENSION vector UPDATE, and the sharding options (replicas, Citus, PgDog) all come from the pgvector README, checked 9 November 2026. JOIN support and ACID transactions are listed in the same README’s feature summary. The README gives no row-count or latency threshold at which pgvector stops being suitable, so the “likely enough” and “consider” columns are our editorial reading, not documented cut-offs. The right-hand column describes situations, not products, and does not claim any dedicated system is faster.
A short decision flow
- Do you already run Postgres for this application? If not, compare options on equal terms, and pgvector is simply one of them.
- If you do, start with pgvector unless a criterion above clearly rules it out. A first test needs only the extension and a vector column.
- Test on your real data and real queries, including your actual filters and tenant patterns. Measure recall and speed yourself.
- Move to a dedicated system only for a reason you can name, such as scale you can’t reach on one cluster, filtering you can’t make reliable, or an operating model your team prefers.
Weaviate’s guidance says something similar: start with the simplest architecture that meets the workload, and validate it on representative data rather than a synthetic benchmark alone. Weaviate is itself a vector database vendor.
One cost is easy to underestimate. With a separate vector store, every change to embedded content has to be re-embedded and written to a second system, and those jobs can fail and need retrying. Make re-embedding jobs safe to run twice, for example by upserting on a stable ID.
Scenario: adding semantic search to an app that already runs Postgres
This is an illustrative walk-through, not a test we ran. Every step points to what the pgvector README documents. It contains no performance figures, because the README publishes none for a setup like this.
Starting point (hypothetical). A software company runs its help centre on PostgreSQL: about 50,000 help articles in one table, each tagged with a product and a language. Search today is keyword search. The team wants questions like “I can’t get into my account” to find the article titled “Reset your password.”
- Check the embedding model’s output size first. The README caps HNSW and IVFFlat indexes on the
vectortype at 2,000 dimensions. If the chosen model outputs more, the documented options are ahalfvecindex (up to 4,000), binary quantization (up to 64,000), subvector indexing, or dimensionality reduction. This is the first hard limit to clear, and it does not depend on how many articles there are. - Add a column instead of a new system. The README’s syntax is
ALTER TABLE items ADD COLUMN embedding vector(3);, with the real dimension in place of 3. Each article’s embedding now sits next to its title, product, and language. - Load first, index second. The README recommends
COPYfor bulk loading and adding indexes after the initial load. In production, it says to create indexes concurrently “to avoid blocking writes.” HNSW builds are “significantly faster” when the graph fits intomaintenance_work_mem, but the README also warns not to set that so high it exhausts server memory. - Handle the filters. Every search here is filtered by product and language. With an approximate index, the README says filtering happens after the index scan, so a selective filter can return fewer rows than
LIMITasks for. Its documented fixes: turn on iterative index scans (0.8.0 and later), use partial indexes if there are only a few languages, or partition by a column with many values. - Keep keyword search. Product names and error codes are exact strings that keyword search handles well. The README shows combining pgvector with PostgreSQL full-text search and merging the two result lists with Reciprocal Rank Fusion or a cross-encoder.
- Keep embeddings in step with edits. When an article changes, compute a new embedding and update the row in the same transaction as the text, using an
INSERT ... ON CONFLICTupsert orUPDATE. A separate vector store would need its own sync job for the same change. - Measure. Tune
hnsw.ef_searchagainst the team’s real queries. The README suggestsEXPLAIN (ANALYZE, BUFFERS)to debug performance and monitoring recall by comparing approximate results with exact search. Whether results are good enough is something only that measurement can answer.
Where this stops being enough, in documented terms. The 50,000 figure alone does not settle anything, because the README sets no row count at which pgvector stops being suitable. The documented pressure points are different ones:
- The model needs full-precision indexing above 2,000 dimensions, and halfvec or quantization is not acceptable.
- The help centre becomes a multi-tenant product. The README warns that a shared approximate index lets one tenant’s vectors affect recall and speed for others, and it recommends list partitioning or separate tables. If that is impractical at your tenant count, that is a real reason to look elsewhere.
- The data outgrows one instance plus replicas. The README’s answer is sharding with Citus, PgDog, or another approach. A team that doesn’t want to run that may prefer a managed vector service.
- Tuned queries, with iterative scans on, still miss the team’s own recall or latency target in their own tests.
Where vector databases fit in RAG
Retrieval-augmented generation pairs a language model with a retrieval step. The original RAG paper by Lewis et al. combined a generator with “a dense vector index of Wikipedia, accessed with a pre-trained neural retriever.” In a typical RAG system, documents are split into chunks and embedded, and at question time the closest chunks are retrieved and passed to the model as context. The vector store does the storing and the retrieving, which is the same job as the semantic search in the scenario above. Any system that can do reliable, filtered nearest-neighbor search can fill that role, including a hybrid of vector and full-text search.
FAQ
What is a vector database?
It is a system that stores vectors, usually embeddings from a machine learning model, and finds the stored items closest to a query vector. It powers semantic search, recommendations, and the retrieval step in RAG.
What is an embedding?
An embedding is a list of numbers that a model produces to represent text, an image, or other data. Items with similar meaning get vectors that sit close together, which is what makes similarity search work.
HNSW index explained: what does it do?
HNSW builds layered graphs that link each vector to nearby vectors. A search enters at a sparse top layer and moves down through denser layers toward the closest matches. It is approximate: it trades some recall for speed, and settings like pgvector’s hnsw.ef_search control that trade-off.
pgvector vs vector database: which should I use?
If you already run Postgres and your data, dimensions, and filters fit pgvector’s documented limits, pgvector is a reasonable place to start. That is our editorial view, and the decision guide above lays out the criteria. A dedicated vector database makes more sense when you can name a specific need pgvector doesn’t meet on your data.
Do I need a vector database for RAG?
You need a way to retrieve relevant chunks, and for many RAG designs that means vector search. You do not necessarily need a separate vector database. A vector-capable database such as Postgres with pgvector can fill the role, optionally combined with full-text search.
Vector database vs relational database: what’s the difference?
Relational databases are built around exact matches, ranges, joins, and transactions; vector databases around similarity. pgvector adds vector types and approximate indexes to Postgres.