Stop Overthinking Vector Databases: A Builder’s Decision Framework
A practical way to choose a vector database. You learn what HNSW and IVF indexes trade off, answer three questions about your data, team and scale, match the answers to four common scenarios, set up Postgres with pgvector on Supabase with Python search code, and compare the pricing models before you commit.

This guide is for developers building RAG apps or AI agents who know they need a vector database but can't choose one. Pinecone, Weaviate, Qdrant, Milvus, Chroma, LanceDB, pgvector, MongoDB Atlas, Redis: every vendor says it's the fastest and easiest. You'll learn what you're actually choosing between, answer three questions that narrow the list, and set up Postgres with pgvector in Python.
Key takeaways
- If your app already runs on Postgres and your vectors belong to your app's rows, start with pgvector. One database is simpler than two.
- Choose by data shape, team capacity and scale, not by benchmarks on a billion vectors you'll never store.
- Check the pricing model before you commit: hourly infrastructure, per-request billing and plan minimums behave very differently at low traffic.
A vector database is a store for embeddings (lists of numbers that represent the meaning of text or images) that can quickly find the stored vectors closest to a query vector. Most projects aren't search engines at web scale. They're internal tools, micro-SaaS products and personal automations, and for those, a dull, well-understood choice usually wins.
This post is part 7 of the LLM & LangChain Fundamentals series. In part 6 you loaded PDFs, CSVs and web pages with LangChain document loaders. Now you need somewhere to store their embeddings.
Step 1: understand what you're buying
A vector database doesn't search text. It stores embeddings. Embeddings are arrays of floating-point numbers that represent the meaning of that text.
When you query it, you don't run WHERE text LIKE '%query%'. You compute a distance between vectors: cosine distance, Euclidean (L2) distance or inner product. OpenAI's embeddings guide recommends cosine similarity, and notes that its embeddings are normalized to length 1.
The bottleneck: indexing
Exact nearest neighbour search (kNN) compares the query with every stored vector. In other words, kNN is the brute-force baseline. It's perfectly accurate, but its cost grows in step with the number of vectors (O(N)). pgvector's README says it does exactly this by default, with "perfect recall."
To go faster, vector databases use approximate nearest neighbour (ANN) indexes. They trade a little recall for a lot of speed. pgvector's README describes the two you'll meet most:
| Index | How it works | Trade-off | Good fit |
|---|---|---|---|
| IVF (IVFFlat in pgvector) | Splits vectors into lists (clusters) and searches only the closest ones | Faster to build and uses less memory, but slower queries; needs data in the table before you create it | Large tables where build time or memory is tight |
| HNSW | Builds a multilayer graph: long jumps at the top, fine steps at the bottom | Better query performance, but slower to build and uses more memory; can be created on an empty table | Most apps that want fast queries |
Takeaway: if you host the database yourself, the choice is yours to make. HNSW gives faster queries but needs more memory and a longer build. IVFFlat builds faster with less memory but answers queries more slowly. With a managed service, the vendor handles most of this tuning, but you still pay for the memory and compute.
Step 2: answer three questions
Skip the feature charts for now. Answer three questions, and the options narrow fast.
Q1: Is your data relational?
Do your vectors sit next to structured data? Say each user searches only their own documents. Then every search needs a strict filter such as user_id = 123.
- Yes: use a database that does vectors and normal queries, so the filter and the search live in one place.
- No: you're building a pure semantic search or a large unstructured knowledge base. A dedicated vector database is fine.
One catch with filters: pgvector's README notes that with approximate indexes, "filtering is applied after the index is scanned," so a narrow filter can return fewer rows than you asked for. It recommends iterative index scans for that case.
Q2: What can your team run?
- Solo developer or small team: you probably can't run a Kubernetes cluster for a distributed database. Pick a managed service or something that runs inside a database you already have.
- Enterprise or platform team: you might run Qdrant or Weaviate in your own cloud account, for compliance or cost control.
Q3: How many vectors will you store?
These bands are rules of thumb, not benchmarks:
- Under about 100,000 vectors: almost anything works, even exact search with no index.
- About 100,000 to 10 million: the range most standard options handle well, including pgvector and Pinecone.
- Hundreds of millions or more: plan for distributed systems built for that scale, such as Milvus or a clustered Weaviate or Qdrant setup, and test on your own data.
Step 3: match your answers to a scenario
Here is how the answers map to four common scenarios.
Scenario A: the full-stack developer ("one database" rule)
Pick: Postgres with pgvector (for example on Supabase or Neon).
If Postgres already holds your users and app data, think hard before adding another system. pgvector lets you join vector results with normal tables, and your backups, migrations and permissions stay in one place. As a rule of thumb, it's fast enough for most apps in the middle band above.
Scenario B: speed and simplicity (managed, serverless)
Pick: Pinecone or Upstash Vector.
If you don't want to run a database at all and just want an API to send vectors to, a fully managed service fits. Pinecone's serverless indexes bill by reads, writes and storage. Upstash Vector bills per request. As a rule of thumb, per-request billing suits small apps with uneven traffic.
Scenario C: the feature-rich engineer
Pick: Weaviate or Qdrant.
Need hybrid search, which mixes keyword and vector results? Weaviate's docs describe hybrid search as fusing a vector search with a keyword (BM25F) search. Qdrant's docs show dense and sparse (keyword-style) queries fused into one result. Both offer more search features than plain storage.
Scenario D: local, testing or privacy
Pick: Chroma or LanceDB.
Building a prototype on your laptop, or an app that runs on the user's device? Chroma's docs say you can run it locally, and LanceDB describes its open-source edition as an "embedded retrieval library." Both work without a separate cloud service.
Step 4: set up pgvector on Supabase
Scenario A fits any app that already runs on Postgres, so here it is in code: Postgres with pgvector on Supabase, searched from Python.
Enable the extension
In the Supabase SQL editor, run this. It's the form Supabase's pgvector docs show, which keeps the extension in the extensions schema:
create extension if not exists vector with schema extensions;
On plain Postgres, create extension if not exists vector; is enough.
Because Supabase puts the extension in the extensions schema, Postgres finds the vector type only if that schema is on your search_path. Supabase's own example writes the type in full, as extensions.vector(...). If the table below fails with "type vector does not exist," write extensions.vector(1536) or add extensions to the search_path. The Python code looks the type up by name too, so the same applies there.
Create the table
Create a documents table that holds a chunk of text and its embedding. OpenAI's text-embedding-3-small returns 1,536 numbers per text by default, so the column has 1,536 dimensions:
create table documents (
id bigserial primary key,
content text not null,
metadata jsonb,
embedding vector(1536)
);
pgvector can index up to 2,000 dimensions for the vector type, so this fits.
Create the HNSW index
Add an HNSW index for cosine distance. Without an index, Postgres compares the query with every row:
create index on documents using hnsw (embedding vector_cosine_ops);
The operator class must match the operator you query with: vector_cosine_ops goes with <=>, pgvector's cosine distance operator.
Insert and search from Python
You need Python 3.10 or newer (all three packages require it on PyPI; the check below used Python 3.14). Install the packages. pgvector adds vector support to the psycopg driver:
pip install -U openai "psycopg[binary]" pgvector
Create search_docs.py:
# search_docs.py
import os
import psycopg
from openai import OpenAI
from pgvector import Vector
from pgvector.psycopg import register_vector
from psycopg.types.json import Jsonb
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "text-embedding-3-small")
def get_embedding(client, text):
response = client.embeddings.create(input=text, model=EMBEDDING_MODEL)
return Vector(response.data[0].embedding)
def add_document(client, db_url, content, metadata=None):
with psycopg.connect(db_url) as conn: # commits when the block ends
register_vector(conn)
conn.execute(
"INSERT INTO documents (content, metadata, embedding) VALUES (%s, %s, %s)",
(content, Jsonb(metadata or {}), get_embedding(client, content)),
)
def search_docs(client, db_url, query_text, limit=3):
query_vec = get_embedding(client, query_text)
with psycopg.connect(db_url) as conn:
register_vector(conn)
# <=> is cosine distance, so 1 - distance is cosine similarity
return conn.execute(
"""
SELECT content, 1 - (embedding <=> %s) AS similarity
FROM documents
ORDER BY embedding <=> %s
LIMIT %s
""",
(query_vec, query_vec, limit),
).fetchall()
if __name__ == "__main__":
# Needs OPENAI_API_KEY and DATABASE_URL (your Supabase connection string).
client = OpenAI()
db_url = os.environ["DATABASE_URL"]
add_document(client, db_url, "pgvector adds vector search to Postgres.", {"source": "notes"})
print(search_docs(client, db_url, "How do I search vectors in Postgres?"))
Checked against openai@3.41.0, psycopg@3.3.6 and pgvector@0.5.1 (the Python package), 2026-10-30. The Python ran against stubbed OpenAI and database clients; the SQL wasn't run against a live database for this update, so try it on a test project first.
The earlier version of this post used psycopg2 with a ::vector cast in the SQL, and it had no insert step. This version uses register_vector from the pgvector Python package, as its README shows, so Vector values go to Postgres as the vector type without a cast. The OpenAI client is created under the __main__ guard, so you can import the functions in tests without an API key.
Keep the embedding model fixed once you've stored vectors. Vectors from different models aren't comparable, so switching models means re-embedding every row.
Step 5: check the cost
Before you ship, do the math. Vector databases charge in different ways, and the differences matter most when traffic is low:
| Pricing model | Examples | How you pay | Watch out for |
|---|---|---|---|
| Usage-based | Pinecone serverless, Upstash Vector | Per read and write, or per request, plus storage | Paid plans can carry a monthly minimum (Pinecone lists them for its paid tiers) |
| Compute-based | Postgres with pgvector (Supabase, Neon) | The database's size and compute | HNSW indexes use memory; plan the instance size as the index grows |
| Self-hosted | Qdrant, Weaviate, Milvus on your servers | Your own machines and the people who run them | Operations time, backups and upgrades |
Both Pinecone and Upstash list free tiers on their pricing pages. Prices change, so check those pages before you decide. For a hobby project, a free tier or the Postgres you already pay for is usually enough.
Summary
There's no "best" vector database, only the one that fits your current constraints:
- Already on Postgres? Use pgvector.
- Want no infrastructure at all? Use a managed service such as Pinecone.
- Building locally? Use Chroma or LanceDB.
Pick one, get the code above working, and move on to the hard part: making retrieval good. The next part shows how to plug a vector store into LangChain for semantic search and long-term memory.
Frequently asked questions
Is pgvector good enough for production?
For many apps, yes, especially when vectors belong to rows you already keep in Postgres. It supports HNSW and IVFFlat indexes and all of Postgres's filtering and joins. At very large scale, or when you need features like built-in hybrid search, test it against a dedicated vector database on your own data.
What is the difference between HNSW and IVFFlat?
Both are approximate indexes. In pgvector's words, HNSW "has better query performance" but slower build times and more memory, while IVFFlat builds faster with less memory but queries more slowly. IVFFlat also needs data in the table before you create it; HNSW doesn't.
Do I need a vector database for a small RAG project?
Often not a separate one. Under roughly 100,000 vectors (a rule of thumb), exact search is often fast enough, and a local store like Chroma or the Postgres you already run will do. Add a dedicated service when scale, features or operations make it worth it.
Which distance metric should I use with OpenAI embeddings?
OpenAI recommends cosine similarity. Its embeddings are normalized to length 1, so cosine similarity and Euclidean distance rank results the same way. In pgvector, use the <=> operator with a vector_cosine_ops index.
Sources
Verified against the sources below on October 30, 2026. Products and docs change often: check the linked sources if something looks different.
All 14 parts in this series
- Part 01What Is LangChain? When to Use It and When to Write Your Own Code
- Part 02LangChain vs. LlamaIndex vs. Vanilla: The Builder's Stack Selection Matrix
- Part 03Structured JSON Output from LLMs: Schema Injection, Pydantic and Retry Loops
- Part 04Building Your First LLM Chain: A Developer's Guide to Sequential Logic
- Part 05Building Your First RAG Pipeline: A Developer’s Guide to Context-Aware AI
- Part 06Building Robust RAG Pipelines: A Deep Dive into LangChain Document Loaders
- Part 07Stop Overthinking Vector Databases: A Builder’s Decision Framework
- Part 08Building Long-Term Memory: Setting Up Vector Databases for Semantic Search in LangChain
- Part 09From Chatbot to Agent: The Engineer's Guide to LLM Memory Systems
- Part 10Building State: A Deep Dive into LangChain Memory for Conversational AI
- Part 11Beyond Built-ins: Architecting Custom Tools in LangChain
- Part 12Unmasking the Black Box: Mastering LangChain Callbacks for Debugging
- Part 13Architecting Autonomous Agents: A Builder’s Guide to Complex Workflows
- Part 14Best Practices for Deploying LangChain Apps to Production
AI Automation Engineer & Salesforce Developer
Salesforce developer since June 2018. I build AI agents, n8n workflows and Salesforce integrations, and write up what holds up in real use.



Comments
Loading comments...