Vector Databases
Store and query high-dimensional embeddings with Pinecone, Weaviate, or pgvector. Build semantic search and RAG retrieval pipelines.
Vector databases store high-dimensional embedding vectors and enable semantic similarity search. They are the retrieval backbone of RAG (Retrieval-Augmented Generation) systems, semantic search, recommendation engines, and duplicate detection at scale.
Choose pgvector for existing PostgreSQL systems (simplest operations). Choose Pinecone for managed, high-scale production. Choose Qdrant/Weaviate for self-hosted with advanced filtering. Generate embeddings once, store permanently, query many times.
Workflow
- Generate and normalize embeddingsThe quality of your embeddings determines the ceiling of your search quality; normalized vectors are required for cosine similarity.
- Set up pgvector for PostgreSQLpgvector adds vector search to existing PostgreSQL - no new infrastructure for teams already on Postgres.
- Use Pinecone for managed vector searchPinecone handles scaling, replication, and infrastructure - ideal for production with millions of vectors.
- Filter with metadataPure semantic search ignores business constraints; metadata filters combine semantic and structured search.
- Build a RAG retrieval pipelineRaw vector search retrieves chunks; RAG combines retrieval with generation for grounded, accurate answers.
Output Format
Embedding pipeline (batch + incremental), vector store with metadata, similarity search returning scored results, RAG pipeline with chunking, retrieval, and generation.
Examples
pgvector search: `SELECT id, content, 1 - (embedding <=> $1) AS similarity FROM documents WHERE metadata->>"tenant" = $2 ORDER BY embedding <=> $1 LIMIT 5`Pinecone upsert: `await index.upsert(chunks.map(c => ({ id: c.id, values: c.embedding, metadata: { text: c.text, source: c.source, page: c.page } })))`RAG prompt: `const context = results.map(r => r.metadata.text).join("
"); const prompt = `Context:
${context}
Question: ${question}
Answer based only on the context above.``Edge Cases & Gotchas
- Embedding model changes: if you switch models, you must re-embed the entire corpus (embeddings from different models are not comparable)
- Chunking strategy matters: too small = lost context; too large = diluted relevance; experiment with 256-512 tokens with overlap for most prose content
- Stale embeddings: when source content updates, re-embed and upsert - maintain a content hash to detect changes
When to Break These Rules
- For exact keyword search (log analysis, code search), traditional full-text search (Elasticsearch, PostgreSQL tsvector) is faster and more precise than vector search.
Reference Files
pgvector: https://github.com/pgvector/pgvectorPinecone docs: https://docs.pinecone.io/Qdrant: https://qdrant.tech/documentation/Chunking strategies: https://www.pinecone.io/learn/chunking-strategies/