This repository provides an advanced Retrieval-Augmented Generation (RAG) solution for complex question answering. It uses sophisticated graph based algorithm to handle the tasks.
Jupyter Notebook
1,626
132 commits
updated Sep 21, 2026
An advanced Retrieval-Augmented Generation (RAG) solution designed to tackle complex questions that simple semantic similarity-based retrieval cannot solve. This project showcases a sophisticated deterministic graph acting as the "brain" of a highly controllable autonomous agent capable of answering non-trivial questions from your own data.

The full reference: a 400-page visual guide that goes deeper than any notebook can. The intuition behind every technique, side-by-side comparisons of when each one wins (and when it quietly fails), and diagrams that make the tricky parts finally click.
1,500+ copies sold ยท Hit #1 in Generative AI on Amazon at launch ยท โญ 4.6 stars
๐ PDF + EPUB ยท GitHub community price: 33% off with code RAGKING
Prompt to Production - my full course on building software with AI the way professionals do: the methods and paradigms behind reliable, efficient, modular production systems, taught systematically. 17 modules, each pairing a video lecture with a hands-on lab, from your first structured prompt to a working production system.
The course is live. Every module is out, lecture and lab.
Your coding agent starts every session knowing nothing about your project, so it guesses. Paste one line into the agent you already have open, and about fifteen minutes later your repository has a docs layer written from the code itself, plus a card scoring what your agent knew before and after.
We ran it on six repositories you already depend on. Each one was asked five questions about itself, cold, then again after the layer was written. The last column counts statements in that project's own documentation that its own code disproves:
| repo | before | after | own docs its code disproves |
|---|---|---|---|
| fastapi | 2 of 5 | 5 of 5 | 2 |
| flask | 3 of 5 | 5 of 5 | 6 |
| django | 3 of 5 | 4 of 5 | 1 |
| express | 2 of 5 | 4 of 5 | 4 |
| requests | 2 of 5 | 4 of 5 | 0 |
| langchain | 5 of 5 | 4 of 5 | 5 |
Flask's six include four documentation examples that raise TypeError when you run them. Langchain scored lower afterwards, because it already ships a 380-line agent instruction file and the cold read was grading theirs; that row is in the table anyway.
Clone any of those repos, paste the same line, and check the number yourself. No signup.
๐ Level up with my Agents Towards Production repository. It delivers horizontal, code-first tutorials that cover every tool and step in the lifecycle of building production-grade GenAI agents, guiding you from spark to scale with proven patterns and reusable blueprints for real-world launches, making it the smartest place to start if you're serious about shipping agents to production.
๐ Explore my comprehensive guide on RAG techniques to complement this advanced agent implementation with many other RAG techniques.
๐ค Explore my GenAI Agents Repository to complement this advanced agent implementation with many other AI Agents implementations and tutorials.
| ๐ Cutting-edge Updates | ๐ก Expert Insights | ๐ฏ Top 0.1% Content |
Join over 20,000 of AI enthusiasts getting unique cutting-edge insights and free tutorials! Plus, subscribers get exclusive early access and special 33% discounts to my book and the upcoming RAG Techniques course!
Prefer video? I break these ideas down into short, one-idea-per-episode explainers on YouTube. Watch on YouTube โ
Ragas metrics for comprehensive quality assessment.
The solution is evaluated using Ragas metrics:
The algorithm was tested using the first Harry Potter book, allowing for monitoring of the model's reliance on retrieved information versus pre-trained knowledge. This choice enables us to verify whether the model is using its pre-trained knowledge or strictly relying on the retrieved information from vector stores.
Q: How did the protagonist defeat the villain's assistant?
To solve this question, the following steps are necessary:
The agent's ability to break down and solve such complex queries demonstrates its sophisticated reasoning capabilities.
git clone https://github.com/NirDiamant/Controllable-RAG-Agent.git
cd Controllable-RAG-Agent
.env file in the root directory with your API key:
OPENAI_API_KEY=
GROQ_API_KEY=
you can look at the .env.example file for reference.docker-compose up --build
pip install -r requirements.txt
Explore the step-by-step tutorial: sophisticated_rag_agent_harry_potter.ipynb
Run real-time agent visualization (no docker):
streamlit run simulate_agent.py
Run real-time agent visualization (with docker):
open your browser and go to http://localhost:8501/
Ragas metrics like answer correctness, faithfulness, relevancy, recall, and similarity to ensure high-quality answers.Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.
Special thanks to Elad Levi for the valuable advice and ideas.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
โญ๏ธ If you find this repository helpful, please consider giving it a star!
Keywords: RAG, Retrieval-Augmented Generation, Agent, Langgraph, NLP, AI, Machine Learning, Information Retrieval, Natural Language Processing, LLM, Embeddings, Semantic Search
The Controllable RAG Agent is an advanced Retrieval-Augmented Generation (RAG) solution designed to tackle complex questions that simple semantic similarity-based retrieval cannot solve. It showcases a sophisticated deterministic graph acting as the "brain" of a highly controllable autonomous agent capable of answering non-trivial questions from your own data.
The Controllable RAG Agent handles questions requiring multi-hop reasoning and complex task decomposition.
The solution is evaluated using Ragas metrics:
For questions like "How did the protagonist defeat the villain's assistant?", the agent:
This demonstrates sophisticated reasoning beyond simple retrieval.
The agent is built on LangGraph and supports:
gpt-4o)functions_for_pipeline.py for fast inferencefunctions_for_pipeline.pypip install -r requirements.txtSee the comprehensive guide on RAG techniques for additional context.
Yes! The agent is designed to work with any PDF documents. Load your custom documents, and the agent will:
The agent ensures answers are solely based on provided data through:
Questions are anonymized by replacing named entities with variables. This helps:
Apache 2.0 License - open-source, free to use commercially.
Jupyter Notebook
88.2%
Python
11.8%
This repository provides an advanced Retrieval-Augmented Generation (RAG) solution for complex question answering. It uses sophisticated graph based algorithm to handle the tasks.
Jupyter Notebook
1,626
132 commits
updated Sep 21, 2026
An advanced Retrieval-Augmented Generation (RAG) solution designed to tackle complex questions that simple semantic similarity-based retrieval cannot solve. This project showcases a sophisticated deterministic graph acting as the "brain" of a highly controllable autonomous agent capable of answering non-trivial questions from your own data.

The full reference: a 400-page visual guide that goes deeper than any notebook can. The intuition behind every technique, side-by-side comparisons of when each one wins (and when it quietly fails), and diagrams that make the tricky parts finally click.
1,500+ copies sold ยท Hit #1 in Generative AI on Amazon at launch ยท โญ 4.6 stars
๐ PDF + EPUB ยท GitHub community price: 33% off with code RAGKING
Prompt to Production - my full course on building software with AI the way professionals do: the methods and paradigms behind reliable, efficient, modular production systems, taught systematically. 17 modules, each pairing a video lecture with a hands-on lab, from your first structured prompt to a working production system.
The course is live. Every module is out, lecture and lab.
Your coding agent starts every session knowing nothing about your project, so it guesses. Paste one line into the agent you already have open, and about fifteen minutes later your repository has a docs layer written from the code itself, plus a card scoring what your agent knew before and after.
We ran it on six repositories you already depend on. Each one was asked five questions about itself, cold, then again after the layer was written. The last column counts statements in that project's own documentation that its own code disproves:
| repo | before | after | own docs its code disproves |
|---|---|---|---|
| fastapi | 2 of 5 | 5 of 5 | 2 |
| flask | 3 of 5 | 5 of 5 | 6 |
| django | 3 of 5 | 4 of 5 | 1 |
| express | 2 of 5 | 4 of 5 | 4 |
| requests | 2 of 5 | 4 of 5 | 0 |
| langchain | 5 of 5 | 4 of 5 | 5 |
Flask's six include four documentation examples that raise TypeError when you run them. Langchain scored lower afterwards, because it already ships a 380-line agent instruction file and the cold read was grading theirs; that row is in the table anyway.
Clone any of those repos, paste the same line, and check the number yourself. No signup.
๐ Level up with my Agents Towards Production repository. It delivers horizontal, code-first tutorials that cover every tool and step in the lifecycle of building production-grade GenAI agents, guiding you from spark to scale with proven patterns and reusable blueprints for real-world launches, making it the smartest place to start if you're serious about shipping agents to production.
๐ Explore my comprehensive guide on RAG techniques to complement this advanced agent implementation with many other RAG techniques.
๐ค Explore my GenAI Agents Repository to complement this advanced agent implementation with many other AI Agents implementations and tutorials.
| ๐ Cutting-edge Updates | ๐ก Expert Insights | ๐ฏ Top 0.1% Content |
Join over 20,000 of AI enthusiasts getting unique cutting-edge insights and free tutorials! Plus, subscribers get exclusive early access and special 33% discounts to my book and the upcoming RAG Techniques course!
Prefer video? I break these ideas down into short, one-idea-per-episode explainers on YouTube. Watch on YouTube โ
Ragas metrics for comprehensive quality assessment.
The solution is evaluated using Ragas metrics:
The algorithm was tested using the first Harry Potter book, allowing for monitoring of the model's reliance on retrieved information versus pre-trained knowledge. This choice enables us to verify whether the model is using its pre-trained knowledge or strictly relying on the retrieved information from vector stores.
Q: How did the protagonist defeat the villain's assistant?
To solve this question, the following steps are necessary:
The agent's ability to break down and solve such complex queries demonstrates its sophisticated reasoning capabilities.
git clone https://github.com/NirDiamant/Controllable-RAG-Agent.git
cd Controllable-RAG-Agent
.env file in the root directory with your API key:
OPENAI_API_KEY=
GROQ_API_KEY=
you can look at the .env.example file for reference.docker-compose up --build
pip install -r requirements.txt
Explore the step-by-step tutorial: sophisticated_rag_agent_harry_potter.ipynb
Run real-time agent visualization (no docker):
streamlit run simulate_agent.py
Run real-time agent visualization (with docker):
open your browser and go to http://localhost:8501/
Ragas metrics like answer correctness, faithfulness, relevancy, recall, and similarity to ensure high-quality answers.Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.
Special thanks to Elad Levi for the valuable advice and ideas.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
โญ๏ธ If you find this repository helpful, please consider giving it a star!
Keywords: RAG, Retrieval-Augmented Generation, Agent, Langgraph, NLP, AI, Machine Learning, Information Retrieval, Natural Language Processing, LLM, Embeddings, Semantic Search
The Controllable RAG Agent is an advanced Retrieval-Augmented Generation (RAG) solution designed to tackle complex questions that simple semantic similarity-based retrieval cannot solve. It showcases a sophisticated deterministic graph acting as the "brain" of a highly controllable autonomous agent capable of answering non-trivial questions from your own data.
The Controllable RAG Agent handles questions requiring multi-hop reasoning and complex task decomposition.
The solution is evaluated using Ragas metrics:
For questions like "How did the protagonist defeat the villain's assistant?", the agent:
This demonstrates sophisticated reasoning beyond simple retrieval.
The agent is built on LangGraph and supports:
gpt-4o)functions_for_pipeline.py for fast inferencefunctions_for_pipeline.pypip install -r requirements.txtSee the comprehensive guide on RAG techniques for additional context.
Yes! The agent is designed to work with any PDF documents. Load your custom documents, and the agent will:
The agent ensures answers are solely based on provided data through:
Questions are anonymized by replacing named entities with variables. This helps:
Apache 2.0 License - open-source, free to use commercially.
Jupyter Notebook
88.2%
Python
11.8%