Skip to main content
This lesson demonstrates that the Retrieval-Augmented Generation (RAG) workflow is identical whether your source is a PDF or a webpage. The only change required is swapping the document loader; everything else in the pipeline—splitting, embedding, vector store, retriever, prompt, and LLM—remains the same. Below is a clean, corrected example that uses a webpage as the source (a Verge article in this case). The code is organized to highlight each step of the RAG pipeline.
The key idea: switch the loader (for example, PyPDFLoader -> WebBaseLoader) to change your source from PDFs to webpages. The rest of the RAG pipeline—splitting, embeddings, vector store, retriever, prompt, and LLM—remains the same.
Workflow summary Best practices and tips
  • Use chunk sizes that balance context fidelity and embedding cost. Typical ranges: 200–1000 tokens depending on use case.
  • Persist your vector store (Chroma or other) between runs to avoid re-embedding the same documents.
  • Add a retrieval filter or metadata to narrow results if you’re working with many documents.
  • When querying the LLM, instruct it clearly to rely only on the provided context if factual accuracy is critical.
Links and references Try replacing the URL with your own webpages or switching to PyPDFLoader to use PDFs. You can also plug this retrieval step into higher-level prebuilt chains for summarization, QA, or citation-aware responses.

Watch Video

Practice Lab