Retrieval-Augmented Generation grounds LLM answers in your own data. The system has two distinct paths: an offline indexing pipeline (ingest once) and an online query pipeline (run per user question). Week 05 notebooks cover the ingestion phase — loaders, Documents, and splitters — with no API keys required.
langchain_community.document_loaders
— e.g. TextLoader,
PyPDFLoader,
Docx2txtLoader,
CSVLoader,
JSONLoader,
SQLDatabase
— each returns Document objects with metadata.
from langchain_text_splitters import RecursiveCharacterTextSplitter —
chunk_size≈200–1000 and overlap≈10–20% (see notebook 1). Metadata (source, page) is copied to every child chunk.
text-embedding-3-small,
nomic-embed-text, or
BGE map semantically similar text to nearby points in vector space.
doc_type == "policy").
Typical k = 3–8 chunks.
Deep Dive
RAG is not a replacement for fine-tuning — they solve different problems. Most production systems combine both.
Implementation
Each architecture component maps to a concrete library in a modern Python RAG app.
| Phase | Component | LangChain / Ecosystem |
|---|---|---|
| Ingestion | Load & parse files | langchain_community.document_loaders · notebooks 1–6 |
| Ingestion | Split into chunks | langchain_text_splitters · notebooks 1–2 |
| Ingestion | Embed text | langchain_openai.OpenAIEmbeddings (next module) |
| Ingestion | Store vectors | Chroma, PineconeVectorStore, PGVector |
| Query | Retrieve top-k | vectorstore.as_retriever(search_kwargs={"k": 4}) |
| Query | Build prompt | ChatPromptTemplate + context injection |
| Generation | Generate answer | ChatOpenAI, ChatAnthropic, etc. |
| All-in-one | Chain orchestration | create_retrieval_chain() or LCEL | pipe syntax |
Week 05 Lab
The interactive diagram above shows the full RAG system. Your notebooks implement
steps 1–2 (load + split). Steps 3–12 (embed, store, retrieve, generate) come in later weeks.
Each notebook includes a Google Colab %pip install cell — no .env file needed.
| Step in diagram | Notebook | Output |
|---|---|---|
| Raw Data → Loaders | 1-dataingestion … 6-databaseparsing | List[Document] |
| Document Splitter | 1-dataingestion, 2-dataparsingpdf | Chunked Documents with metadata |
| Embedding → Vector DB | future module | Requires API key / local embed model |
| Query → LLM | future module | create_retrieval_chain |
Deep dive on the Document model: LangChain Document Components → · Storage layer: Vector Store vs Database → · System design: RAG & Agents (Part 2) →