Loading notes...
Loading notes...
RAG • Chapter 3
RAG engineering module on Vector Databases Architecture.
Vector databases are specialized storage systems designed to handle the high-dimensional vectors generated by embedding models. They allow for rapid similarity searches across millions or billions of records.
Advanced System Mechanics
Unlike relational databases that use B-Trees for exact matching, vector databases (like Pinecone, Milvus, ChromaDB, and Qdrant) use Approximate Nearest Neighbor (ANN) algorithms. The most common index type is HNSW (Hierarchical Navigable Small World) graphs, which sacrifice a tiny bit of accuracy for massive speed gains in calculating cosine similarity or Euclidean distance.
Implementation Blueprint
# Using ChromaDB (an open-source vector database)
import chromadb
chroma_client = chromadb.Client()
collection = chroma_client.create_collection(name="my_rag_data")
collection.add(
documents=["This is a document about RAG", "This is a document about cars"],
metadatas=[{"source": "wiki"}, {"source": "manual"}],
ids=["id1", "id2"]
)
results = collection.query(
query_texts=["Tell me about Retrieval Augmented Generation"],
n_results=1
)
print(results['documents'])