I built a local adaptive RAG research agent using LangGraph and a local DeepSeek R1 model running on Ollama. This agent act like a deep researcher, designed to gather, analyze, and summarize information based on user instructions.
-
Generating Research Queries – The agent takes user input and formulates relevant research questions to find the most useful information.
-
Retrieving Documents – It searches a local Chroma database to pull relevant documents related to the query.
-
Evaluating Relevance – Each document is checked against the original query to ensure it contains meaningful and accurate information.
-
Expanding Search if Needed – If the retrieved documents are not sufficient or relevant, the agent can search the web for additional sources.
-
Summarizing Findings – After gathering all necessary information, the agent processes the data and extracts key insights.
-
Final Report Generation – The summarized findings are sent to a writer agent, which structures the information into a detailed and well-formatted report based on a predefined format.
This system allows for an efficient and adaptive research process, ensuring high-quality and relevant outputs while minimizing unnecessary or low-value data.
- Dynamic Search Through Local Documents – Efficiently retrieves relevant information from your internal documents.
- Advanced Insight Extraction – Leverages the reasoning power of DeepSeek R1 model to evaluate, analyze, and extract the most valuable insights from documents.
- Real-Time Web Search – Expands research by accessing online sources using Tavily API when local documents are insufficient.
- Structured Report Generation – Produces well-formatted reports based on your predefined reporting templates.
This is the detailed flow of the system:
- Ollama: Runs the DeepSeek R1 model locally.
- LangGraph: Builds AI agents and defines the researcher's workflow.
- ChromaDB: Local vector database for RAG-based retrieval.
- Streamlit: Provides a UI for interacting with the researcher.
- Tavily: For searching the web.
Ensure you have the following installed:
- Python 3.9+
- Ollama
- Tavily API key for web searchs
- Necessary Python libraries (listed in
requirements.txt
)
git clone https://github.com/kaymen99/local-rag-researcher-deepseek
cd local-rag-researcher-deepseek
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
Create a .env
file in the root directory and add necessary credentials:
# Tavily API key for SearchTool (optional)
TAVILY_API_KEY="your-api-key"
Follow the official instructions to install Ollama, then pull the DeepSeek R1 model (this project uses the 7b model but you can choose any other models available):
ollama pull deepseek-r1:7b
Run the following command to start the UI:
streamlit run app.py
Since the researcher is built with LangGraph, you can use LangGraph Studio to inspect the agent's workflow. To do this, run the following commands:
pip install -U "langgraph-cli[inmem]"
langgraph dev
- Add custom structures inside the
report_structures
folder. - Select the preferred structure in the UI.
By default, the researcher runs locally using the DeepSeek R1 model on Ollama. However, if you prefer to use a cloud-based LLM provider instead (such as Cloud DeepSeek R1, OpenAI GPT-4o, or OpenAI o1), follow these steps:
-
Modify the Code:
- Go to
assistant/graph.py
. - Comment the code invoking Ollama model.
- Uncomment the section of code that enables external LLM calls.
invoke_llm
uses OpenRouter, which provides access to multiple LLMs. You can choose your preferred model from their list. 🚀- You can also modify the
invoke_llm
function to use a single LLM provider instead of OpenRouter if you want.
- Go to
-
Set Up API Keys:
-
Obtain OpenRouter API key from here.
-
Add these keys to your
.env
file in the following format:OPENROUTER_API_KEY=your_openai_key
-
-
Langchain: Building a fully local "deep researcher" with DeepSeek-R1see
-
Langchain: Building a fully local research assistant from scratch with Ollama see
-
LangGraph Template: Multi-Agent RAG Research see
-
LangGraph Adaptative RAG implementation see
Contributions are welcome! Please open an issue or submit a pull request for any changes.
If you have any questions or suggestions, feel free to contact me at [email protected].