Jupyter notebook tutorial for a local Corrective RAG Agent. The goal is to provide accurate, relevant, and hallucination-free answers by combining the strengths of retrieval-based systems with generative AI and web search capabilities.
- Document retrieval and relevance grading
- Web search integration for enhanced information gathering
- Hallucination detection and correction mechanism
- Iterative answer improvement process
-
Question Input: User-provides question.
-
Retrieve Documents: Relevant documents retrieved based on the input question.
-
Grade Documents: Retrieved documents are graded for relevance and quality.
-
Relevance Check: The system checks if any retrieved document is relevant to the question.
- If Yes: Proceeds to generate an answer.
- If No: Initiates a web search for additional information.
-
Generate Answer: Using the relevant documents or web search results, the system generates an answer.
-
Hallucination Check: The generated answer is checked for potential hallucinations or inaccuracies.
- If No hallucinations detected: The answer is provided to the user.
- If Yes (hallucinations detected): The system asks if the answer addresses the question.
- If Yes: The final answer is provided.
- If No: The system initiates a web search for more accurate information.
-
Web Search: When needed, the system performs a web search to gather additional, up-to-date information to supplement or correct the answer.
To set up the Corrective RAG Agent, you need to:
- Install Ollama using the official download link or using the homebrew command:
brew install ollama- Install the required packages. Run the following command:
pip install -U langchain-nomic langchain_community tiktoken langchainhub chromadb langchain langgraph tavily-python gpt4all firecrawl-py