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.
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.
- LangChain documentation: https://langchain.readthedocs.io/
- Chroma vector database: https://www.trychroma.com/
- OpenAI embeddings: https://platform.openai.com/docs/guides/embeddings
- The Verge article used in this example: https://www.theverge.com/2024/4/18/24133808/meta-ai-assistant-llama-3-chatgpt-openai-rival
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.