This is a starter project to help you get started with developing a RAG research agent using LangGraph in LangGraph Studio.
This project provides three runnable graphs implemented under src/graphs/:
- an "index" graph (
src/graphs/index_graph.py) - a "main" graph (
src/graphs/main_graph.py) - a "researcher" subgraph (part of the main graph) (
src/graphs/researcher_graph.py)
The index graph takes in document objects and indexes them.
[{ "page_content": "RAG Research Agent是一种结合检索增强生成(RAG)技术与智能Agent能力的研究型智能体系统。它不仅具备基础的检索与生成能力,还融合了自我反思、工具链式调用及多智能体协同等高级特性,突破了传统大模型'仅会聊天、检索'的局限。" }]The three graphs in this system have the following relationships:
-
Index Graph:
- Independent graph for indexing documents into a vector store
- Not directly connected to other graphs
- Used to populate the vector store that other graphs query
-
Main Graph:
- Main conversational agent
- Contains the Researcher Graph as a subgraph
- Uses the vector store populated by the Index Graph
-
Researcher Graph:
- Subgraph of the Main Graph
- Invoked by the 'conduct_research' node in the Main Graph
- Generates queries and retrieves documents from the same vector store
Data Flow:
Index Graph --> Vector Store <-- Researcher Graph <-- Main Graph
This template supports the following vector stores:
Elasticsearch is a distributed, RESTful search engine optimized for speed and relevance. For local development, we recommend using the official Docker image.
-
Pull the Elasticsearch Docker image:
docker pull docker.elastic.co/elasticsearch/elasticsearch:9.1.4
-
Start Elasticsearch in a Docker container:
docker run \ -p 127.0.0.1:9200:9200 \ -d \ --name elasticsearch \ -e ELASTIC_PASSWORD=your_password \ -e "discovery.type=single-node" \ -e "xpack.security.http.ssl.enabled=false" \ -e "xpack.license.self_generated.type=trial" \ docker.elastic.co/elasticsearch/elasticsearch:9.1.4
-
Set up your environment:
- Create a
.envfile in your project root if you haven't already. - Add the Elasticsearch configuration to your
.envfile:
ELASTICSEARCH_USER=elastic ELASTICSEARCH_PASSWORD=your_password ELASTICSEARCH_URL=http://localhost:9200 - Create a
MongoDB Atlas is a fully-managed cloud database that includes vector search capabilities for AI-powered applications.
- Create a free Atlas cluster:
- Go to the MongoDB Atlas website and sign up for a free account.
- After logging in, create a free cluster by following the on-screen instructions.
- Create a vector search index
- Follow the instructions at the Mongo docs
- By default, we use the collection
langgraph_retrieval_agent.default- create the index there - Add an indexed filter for path
user_id - IMPORTANT: select Atlas Vector Search NOT Atlas Search when creating the index Your final JSON editor configuration should look something like the following:
{
"fields": [
{
"numDimensions": 1024,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}
]
}The exact numDimensions may differ if you select a different embedding model.
- Set up your environment:
- In the Atlas dashboard, click on "Connect" for your cluster.
- Choose "Connect your application" and copy the provided connection string.
- Create a
.envfile in your project root if you haven't already. - Add your MongoDB Atlas connection string to the
.envfile:
MONGODB_URI="mongodb+srv://username:password@your-cluster-url.mongodb.net/?retryWrites=true&w=majority&appName=your-cluster-name"
Replace username, password, your-cluster-url, and your-cluster-name with your actual credentials and cluster information.
Milvus is a high-performance, open-source vector database designed for AI applications and similarity search.
-
Set up Milvus using Docker (for development) or use a managed Milvus service:
- For Docker setup, follow the official Milvus installation guide
- For Zilliz Cloud (managed Milvus service), sign up at Zilliz Cloud
-
Once you have your Milvus instance running, add the connection URI to your
.envfile:
MILVUS_URI=your_milvus_uri
For local development, this would typically be http://localhost:19530.
The defaults values for llm_model, embedding_model are shown below:
llm_model: ollama/qwen3:4b
embedding_model: ollama/bge-m3:latestFollow the instructions below to get set up, or pick one of the additional options.
To use OpenAI's chat models:
- Sign up for an OpenAI API key.
- Once you have your API key, add it to your
.envfile:
OPENAI_API_KEY=your-api-key
To use local models via Ollama:
- Install Ollama
- Pull the models you want to use:
ollama pull qwen3:4b ollama pull bge-m3:latest
- No API key is needed for local models.
pip install -e .For development, also install dev dependencies:
pip install -e ".[dev]"To run the examples in the template, use the following command:
python main.pyTo visualize the graphs in the template, run:
python src/visualize_graphs.pyThis will display the graphs in your terminal and save them as PNG files in the graphs/ directory.
To run the tests, use the following command:
make testTo run tests in watch mode:
make test_watchTo run tests with profiling:
make test_profileTo format the code, use:
make formatTo lint the code, use:
make lint.
├── src
│ ├── graphs
│ │ ├── __init__.py
│ │ ├── index_graph.py
│ │ ├── main_graph.py
│ │ └── researcher_graph.py
│ ├── shared
│ │ ├── __init__.py
│ │ ├── configuration_manager.py
│ │ ├── model_manager.py
│ │ ├── prompts.py
│ │ ├── retrieval.py
│ │ ├── retrieval_manager.py
│ │ ├── state.py
│ │ ├── text_encoder.py
│ │ └── utils.py
│ ├── __init__.py
│ ├── log_util.py
│ ├── sample_docs.json
│ └── visualize_graphs.py
├── tests
│ ├── integration_tests
│ │ ├── __init__.py
│ │ └── test_graph.py
│ ├── unit_tests
│ │ ├── __init__.py
│ │ └── test_configuration.py
│ └── __init__.py
├── Makefile
├── README.md
├── langgraph.json
├── main.py
└── pyproject.toml
