Pipeline
RAG has two stages: index (offline) and query (online). Indexing turns documents into searchable vectors. Querying embeds the question, retrieves chunks, optionally reranks, then calls the LLM.
The chain this course owns:
At query time the user question uses the same embed step, then retrieve. Do not embed with a chat model.
What each stage does
Indexing can be batched or run overnight. Queries must be fast: vector search is milliseconds; the LLM dominates latency.
Responsibilities
- documents — Markdown, extracted PDF text, database fields. Print plain text before you talk about retrieval.
- chunk — Semantically whole, length-bounded pieces. See Chunking.
- embed — Chunk → vector. See Embeddings.
- vector store — Persist and search: Chroma, pgvector, Qdrant.
- retrieve — Take k hits; add metadata filters or keyword hybrid if needed.
- optional rerank — A cross-encoder or a rule that promotes true matches. See Retrieval.
- LLM — Prompt: answer only from context; say you do not know if the context is silent.
Framework loaders / splitters / retrievers wrap these seven steps: LangChain RAG, LlamaIndex, Dify Knowledge Base.
Smallest runnable sketch (in-memory, no database)
Chunk → embed → search → prompt. Swap the fake embed for OpenAI or Ollama; later chapters replace store with disk or Postgres.
fake_embed must not ship. It only proves the data flow. Real vectors come from Embeddings.
Which hop fails first
Next steps
- Chunking
- Embeddings
- Chroma — first persistent pipeline