Skip to content

Local RAG researcher agent built using Langgraph, DeepSeek R1 and Ollama

Notifications You must be signed in to change notification settings

kaymen99/local-rag-researcher-deepseek

Repository files navigation

🚀 Local RAG Researcher with DeepSeek R1 & Langgraph

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.

Demo of Local RAG Researcher with LangGraph & DeepSeek

How It Works

  1. Generating Research Queries – The agent takes user input and formulates relevant research questions to find the most useful information.

  2. Retrieving Documents – It searches a local Chroma database to pull relevant documents related to the query.

  3. Evaluating Relevance – Each document is checked against the original query to ensure it contains meaningful and accurate information.

  4. Expanding Search if Needed – If the retrieved documents are not sufficient or relevant, the agent can search the web for additional sources.

  5. Summarizing Findings – After gathering all necessary information, the agent processes the data and extracts key insights.

  6. 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.

Key Features

  • 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.

System Flowchart

This is the detailed flow of the system:

Langgraph Local Deepseek RAG researcher

Tech Stack

  • 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.

How to Run

Prerequisites

Ensure you have the following installed:

  • Python 3.9+
  • Ollama
  • Tavily API key for web searchs
  • Necessary Python libraries (listed in requirements.txt)

Setup

Clone the Repository

git clone https://github.com/kaymen99/local-rag-researcher-deepseek
cd local-rag-researcher-deepseek

Create and Activate a Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

Install Required Packages

pip install -r requirements.txt

Set Up Environment Variables

Create a .env file in the root directory and add necessary credentials:

# Tavily API key for SearchTool (optional)
TAVILY_API_KEY="your-api-key"

Running the Application

Step 1: Install and Run Ollama

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

Step 2: Launch the Streamlit App

Run the following command to start the UI:

streamlit run app.py

Step 3: Visualize in LangGraph Studio (Optional)

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

Customization

Modify Report Structures

  • Add custom structures inside the report_structures folder.
  • Select the preferred structure in the UI.

Using an External LLM Provider

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:

  1. 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.
  2. 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

📚 Further Reading & Resources

  • 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

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Contact

If you have any questions or suggestions, feel free to contact me at [email protected].

Releases

No releases published

Packages

No packages published

Languages