Module 2 cheat sheet: RAG: Chat with Your Documents

Load → split → embed → store once; retrieve → generate for every question, with sources and an “I don’t know” rule.

All modules📖 Glossary

Key ideas

  • Document = page_content + metadata. Lab 06 →
  • RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100). Lab 07 →
  • Same embedding model for docs and questions. Lab 08 →
  • FAISS score = distance (lower better); cosine = similarity (higher better). Lab 09 →
  • Hybrid (BM25 + vector) for production. Lab 10 →
  • Answer only from context, return pages. Lab 11 →

The RAG chain

rag_chain = (
    {"context": retriever | format_docs,
     "question": RunnablePassthrough()}
    | prompt | llm | StrOutputParser()
)

Loaders

SourceLoader
.pdfPyPDFLoader (1 doc / page)
.csvCSVLoader (1 doc / row)
.txtTextLoader
webWebBaseLoader
folderDirectoryLoader

Retrievers

RetrieverUse when
similaritydefault
MMRrepetitive results
score thresholddrop unrelated
BM25codes, IDs, names
Ensembleproduction hybrid
MultiQueryvague questions
ParentDocumentsmall search, big context

Common mistakes

  • Chunks too small (no meaning) or too big (noisy).
  • Different embedding models for docs and questions.
  • Reading FAISS distance as similarity.
  • Default BM25 tokenizer missing codes like UPI-U30.
  • No “I don’t know” rule, no sources.

Created by Ajeetkumar · EasyLearnSpace