Vector Databases
Searching millions of embeddings with brute-force comparison is too slow. Vector databases use approximate nearest neighbor (ANN) indexes (HNSW, IVF) for millisecond similarity search across billions of vectors — essential for production RAG systems.
A vector database is like a library organized by topic proximity rather than alphabetical order — books on similar subjects are shelved nearby, so finding related content is fast even in a massive collection.
Visual Workflows
Start here — study each diagram, then use + / − to zoom if needed.
Scroll inside the frame · use + / − to zoom
Key Takeaways
- 1.Vector databases are specialized storage systems optimized for storing, indexing, and querying high-dimensional embedding vectors at scale.
- 2.Vector DBs (Pinecone, Weaviate, ChromaDB, Qdrant, pgvector) store embedding vectors with metadata (source document, chunk index, timestamps).
- 3.They support: upsert (insert/update), query (nearest neighbors), filtering (metadata constraints), and hybrid search (vector + keyword).
- 4.ANN indexes trade perfect accuracy for speed.
- 5.Key parameters: dimension count, distance metric, index type.
Real Example
Scenario
Your company knowledge base has 50,000 document chunks embedded as 1536-dim vectors in Pinecone. A user query returns the 5 most relevant chunks in under 50ms, filtered to only include documents from the last year.
What you would do
In RAG Engineering, apply Vector Databases to this scenario: Your company knowledge base has 50,000 document chunks embedded as 1536-dim vectors in Pinecone. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Open the Code Walkthrough below and run it locally. Change one parameter related to Vector Databases (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Vector Databases happens in the code.
1import chromadb # import dependencies2
3client = chromadb.Client()4collection = client.create_collection("docs")5
6# Upsert documents with embeddings7collection.add(8 documents=["Refund policy: 30-day returns", "Shipping takes 3-5 days"],9 ids=["doc1", "doc2"],10 metadatas=[{"category": "policy"}, {"category": "shipping"}],11)12
13# Query14results = collection.query(15 query_texts=["How do I return an item?"], # return the result16 n_results=2,17 where={"category": "policy"},18)19print(results["documents"]) # show output for debuggingCheat Sheet
Quick recap
quick ref- •collection.add(docs, ids, metadatas)
- •collection.query(query_texts, n_results)
- •HNSW = fast ANN index
- •pgvector for small scale
- •Metadata filtering with where
- •Re-embed on model change
Common Mistakes
- ✕Brute-force search instead of using ANN indexes at scale
- ✕Mismatching embedding dimensions between model and DB
- ✕No metadata — can't filter results by date, category, or source
- ✕Not planning for re-indexing when embedding model changes