RAG and Vector Databases Tutorial
Welcome to Kenhuang Academy’s RAG (Retrieval-Augmented Generation) course. This tutorial is framework-agnostic: chunking, embeddings, vector stores, retrieve / rerank, and evaluation. The three runnable stores are Chroma, pgvector, and Qdrant.
LangChain, LlamaIndex, and Dify all implement the same pipeline. Those courses cover product APIs. Principles and storage belong here.
Table of Contents
Principles
- Introduction — Why retrieve; RAG vs fine-tuning vs long context
- Pipeline — documents → chunk → embed → vector store → retrieve → rerank → LLM
- Chunking — Size, overlap, headers, parent-child chunks
- Embeddings — OpenAI
text-embedding-3-smallor local Ollama / BGE (Chinese)
Vector stores
- Chroma — Local directory,
PersistentClient,add/query - pgvector — PostgreSQL extension, cosine query, existing databases
- Qdrant — Docker, HTTP 6333,
upsert/ search and filters
Quality
- Retrieval — top-k, hybrid search, optional rerank, metadata filters
- Evaluation — hit@k, faithfulness, “answer only from context”
- Practical Examples — Markdown FAQ, existing Postgres, Qdrant filter / hybrid
- Resources — Official docs and related courses on this site
Learning path
Get Chroma green first, then choose Postgres or a dedicated vector service. Do not install all three on day one.
Related courses on this site
Prerequisites
- Python 3.10+ (functions, lists, virtual environments)
- One Chat Completions call is enough; you do not need an agent framework yet
- At least one embedding path: an OpenAI API key, or local Ollama (CPU is fine; no GPU required)
- PostgreSQL for the pgvector chapter; Docker for Qdrant
- Windows: PowerShell; bash commands are listed too
You do not need to implement a Transformer, and you do not need a GPU.
Study tips
- Use facts the web cannot know (made-up policy numbers). Otherwise you cannot tell retrieval from memorization
- Index and query with the same embedding model; switching models means re-embedding the collection
- Fix retrieval (hit@k) before rewriting the generation prompt
- Take LangChain / LlamaIndex / Dify after this pipeline, so you are not stuck memorizing class names