Vector Database Guide 2026: Pinecone vs Qdrant vs pgvector vs Weaviate
Choose the right vector database for your RAG application performance and cost
Vector Database Guide 2026: Pinecone vs Qdrant vs pgvector vs Weaviate
Choose the right vector database for your RAG application performance and cost
Complete 2026 comparison of Pinecone, Qdrant, pgvector, and Weaviate. Includes Python code examples, performance benchmarks at 1M vectors, filtering, and self-hosting setup.
Vector Database Guide 2026: Pinecone vs Qdrant vs pgvector vs Weaviate
Vector databases are the foundation of RAG systems. Choosing incorrectly can hurt performance or scalability significantly.
Quick Guide
Pinecone
python
from pinecone import Pinecone, ServerlessSpecpc = Pinecone(api_key='your-key')
pc.create_index(
name='rag-index', dimension=1536, metric='cosine',
spec=ServerlessSpec(cloud='aws', region='us-east-1')
)
index = pc.Index('rag-index')
Upsert vectors with metadata
index.upsert(vectors=[
{'id': f'doc_{i}', 'values': embeddings[i],
'metadata': {'text': chunks[i], 'source': 'doc.pdf'}}
for i in range(len(chunks))
], namespace='production')Filtered query
results = index.query(
vector=query_embedding, top_k=5,
filter={'source': {'$eq': 'annual_report.pdf'}},
include_metadata=True
)
for match in results.matches:
print(f'Score: {match.score:.3f} | {match.metadata["text"][:100]}')
Qdrant (Performance Leader)
python
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct, Filter, FieldCondition, MatchValueclient = QdrantClient(url='http://localhost:6333')
client.create_collection(
collection_name='rag_docs',
vectors_config=VectorParams(size=1536, distance=Distance.COSINE)
)
client.upsert(
collection_name='rag_docs',
points=[PointStruct(id=i, vector=embeddings[i],
payload={'text': chunks[i], 'category': categories[i]})
for i in range(len(chunks))]
)
Filtered search
results = client.search(
collection_name='rag_docs',
query_vector=query_embedding,
query_filter=Filter(must=[FieldCondition(key='category', match=MatchValue(value='legal'))]),
limit=5, with_payload=True
)
for result in results:
print(f'Score: {result.score:.3f} | {result.payload["text"][:100]}')
pgvector (PostgreSQL Integration)
python
import psycopg2
import numpy as npconn = psycopg2.connect('postgresql://user:pass@localhost/ragdb')
cur = conn.cursor()
cur.execute('CREATE EXTENSION IF NOT EXISTS vector')
cur.execute('''
CREATE TABLE IF NOT EXISTS documents (
id SERIAL PRIMARY KEY, content TEXT,
embedding vector(1536), source TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
)
''')
cur.execute('CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100)')
conn.commit()
Insert
cur.execute('INSERT INTO documents (content, embedding, source) VALUES (%s, %s, %s)',
(content, np.array(embedding).tolist(), source))
conn.commit()Search
cur.execute('''
SELECT content, source, 1 - (embedding <=> %s::vector) AS similarity
FROM documents
ORDER BY embedding <=> %s::vector
LIMIT 5
''', (query_embedding, query_embedding))
results = cur.fetchall()
Performance at 1M Vectors
Self-Hosting Qdrant
yaml
docker-compose.yml
services:
qdrant:
image: qdrant/qdrant:latest
ports: ['6333:6333', '6334:6334']
volumes: ['./qdrant_storage:/qdrant/storage']
Decision Guide
Conclusion
For new production applications: Qdrant for performance or Pinecone for simplicity. For teams already on PostgreSQL: pgvector eliminates an infrastructure component. Chroma is a great dev tool but not battle-tested at production scale.
相关工具
相关教程
Build complex multi-step AI workflows with state management using LangGraph
Chain-of-thought, tree-of-thoughts, self-consistency, and systematic evaluation methods
Deploy Llama 3 with 20x higher throughput than naive serving