Official code for ''RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge''.
See the codeOfficial implementation of "RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge".
Temporal-GraphRAG (TG-RAG) addresses the temporal blindness in conventional RAG systems by modeling knowledge as a bi-level temporal graph. This enables precise time-aware retrieval and efficient incremental updates as corpora evolve.
Key Advantages:
git clone https://github.com/hanjiale/Temporal-GraphRAG.git
cd Temporal-GraphRAG
# Create virtual environment
python3.12 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
1. Set up API keys (required for LLM and embedding providers):
# Create .env file or set environment variables
export OPENAI_API_KEY="your-openai-key-here" # For OpenAI provider
export GOOGLE_API_KEY="your-google-key-here" # For Gemini provider (or use GEMINI_API_KEY)
2. Build and query:
# Build a graph from documents
python build_graph.py --output_dir ./graph_output --corpus_path ./my_documents/
# Query the graph
python query_graph.py --question "Your question here" --working_dir ./graph_output --mode global
Customize which entity types are extracted by editing tgrag/configs/prompts.yaml:
defaults:
entity_types:
- "financial concept"
- "business segment"
- "event"
- "company"
- "person"
- "product"
- "location"
The system will only extract entities matching these configured types.
Configure in tgrag/configs/config.yaml:
building:
provider: "gemini" # Options: openai, azure, bedrock, gemini, ollama
model: "gemini-2.5-flash-lite"
embedding_provider: "openai"
Supported Providers:
OPENAI_API_KEYaioboto3GOOGLE_API_KEY or GEMINI_API_KEYhttp://localhost:11434)Set API keys via environment variables or .env file:
export OPENAI_API_KEY="your-key-here"
export GOOGLE_API_KEY="your-key-here" # or GEMINI_API_KEY
The build_graph.py script automatically detects input type:
ECT-QA corpus (JSONL.gz):
python build_graph.py --output_dir ./graph_output --corpus_path ./ect-qa/corpus/base.jsonl.gz --num_docs 10
Single text file:
python build_graph.py --output_dir ./graph_output --corpus_path ./my_document.txt
Directory of text files (recursive):
python build_graph.py --output_dir ./graph_output --corpus_path ./my_documents/
Supported text formats: .txt, .md, .rst, .text, .log, and files without extensions.
# Local mode - for specific facts
python query_graph.py --question "What was Company X's revenue in Q3 2023?" --mode local
# Global mode - for trends and summarization
python query_graph.py --question "How did tech companies navigate 2023 challenges?" --mode global
# Naive mode - simple RAG
python query_graph.py --question "What is artificial intelligence?" --mode naive
from tgrag import create_temporal_graphrag_from_config
# Build the graph
graph_rag = create_temporal_graphrag_from_config(
config_path="tgrag/configs/config.yaml",
config_type="building"
)
# Insert documents
graph_rag.insert([{"title": "Doc 1", "doc": "content..."}])
# Query the graph
graph_rag = create_temporal_graphrag_from_config(
config_path="tgrag/configs/config.yaml",
config_type="querying"
)
answer = graph_rag.query("Your question here", mode="global")
High-quality benchmark for time-sensitive question answering:
The dataset is also available on Hugging Face: austinmyc/ECT-QA
You can load it using:
from datasets import load_dataset
# Load questions dataset
questions = load_dataset("austinmyc/ECT-QA", "questions")
# Load corpus dataset
corpus = load_dataset("austinmyc/ECT-QA", "corpus")
Temporal-GraphRAG/
โโโ tgrag/
โ โโโ configs/
โ โ โโโ config.yaml # Main configuration
โ โ โโโ prompts.yaml # prompts for indexing and querying
โ โโโ src/
โ โโโ temporal_graphrag.py
โ โโโ ...
โโโ ect-qa/ # ECT-QA dataset
โ โโโ corpus/
โ โ โโโ base.jsonl.gz # 2020 - 2023
โ โ โโโ new.jsonl.gz # 2024
โ โโโ questions/
โ โโโ local_base.jsonl
โ โโโ local_new.jsonl
โ โโโ global_base.jsonl
โ โโโ global_new.jsonl
โโโ graph_storage/
โ โโโ ... # Output graphs
โโโ build_graph.py # Script to build knowledge graph
โโโ query_graph.py # Script to query the graph
โโโ requirements.txt
โโโ README.md
โโโ LICENSE
โโโ .gitignore
@article{han2025rag,
title={RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge},
author={Han, Jiale and Cheung, Austin and Wei, Yubai and Yu, Zheng and Wang, Xusheng and Zhu, Bing and Yang, Yi},
journal={arXiv preprint arXiv:2510.13590},
year={2025}
}
Paper available at: arXiv:2510.13590
Official code for ''RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge''.
See the codeOfficial implementation of "RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge".
Temporal-GraphRAG (TG-RAG) addresses the temporal blindness in conventional RAG systems by modeling knowledge as a bi-level temporal graph. This enables precise time-aware retrieval and efficient incremental updates as corpora evolve.
Key Advantages:
git clone https://github.com/hanjiale/Temporal-GraphRAG.git
cd Temporal-GraphRAG
# Create virtual environment
python3.12 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
1. Set up API keys (required for LLM and embedding providers):
# Create .env file or set environment variables
export OPENAI_API_KEY="your-openai-key-here" # For OpenAI provider
export GOOGLE_API_KEY="your-google-key-here" # For Gemini provider (or use GEMINI_API_KEY)
2. Build and query:
# Build a graph from documents
python build_graph.py --output_dir ./graph_output --corpus_path ./my_documents/
# Query the graph
python query_graph.py --question "Your question here" --working_dir ./graph_output --mode global
Customize which entity types are extracted by editing tgrag/configs/prompts.yaml:
defaults:
entity_types:
- "financial concept"
- "business segment"
- "event"
- "company"
- "person"
- "product"
- "location"
The system will only extract entities matching these configured types.
Configure in tgrag/configs/config.yaml:
building:
provider: "gemini" # Options: openai, azure, bedrock, gemini, ollama
model: "gemini-2.5-flash-lite"
embedding_provider: "openai"
Supported Providers:
OPENAI_API_KEYaioboto3GOOGLE_API_KEY or GEMINI_API_KEYhttp://localhost:11434)Set API keys via environment variables or .env file:
export OPENAI_API_KEY="your-key-here"
export GOOGLE_API_KEY="your-key-here" # or GEMINI_API_KEY
The build_graph.py script automatically detects input type:
ECT-QA corpus (JSONL.gz):
python build_graph.py --output_dir ./graph_output --corpus_path ./ect-qa/corpus/base.jsonl.gz --num_docs 10
Single text file:
python build_graph.py --output_dir ./graph_output --corpus_path ./my_document.txt
Directory of text files (recursive):
python build_graph.py --output_dir ./graph_output --corpus_path ./my_documents/
Supported text formats: .txt, .md, .rst, .text, .log, and files without extensions.
# Local mode - for specific facts
python query_graph.py --question "What was Company X's revenue in Q3 2023?" --mode local
# Global mode - for trends and summarization
python query_graph.py --question "How did tech companies navigate 2023 challenges?" --mode global
# Naive mode - simple RAG
python query_graph.py --question "What is artificial intelligence?" --mode naive
from tgrag import create_temporal_graphrag_from_config
# Build the graph
graph_rag = create_temporal_graphrag_from_config(
config_path="tgrag/configs/config.yaml",
config_type="building"
)
# Insert documents
graph_rag.insert([{"title": "Doc 1", "doc": "content..."}])
# Query the graph
graph_rag = create_temporal_graphrag_from_config(
config_path="tgrag/configs/config.yaml",
config_type="querying"
)
answer = graph_rag.query("Your question here", mode="global")
High-quality benchmark for time-sensitive question answering:
The dataset is also available on Hugging Face: austinmyc/ECT-QA
You can load it using:
from datasets import load_dataset
# Load questions dataset
questions = load_dataset("austinmyc/ECT-QA", "questions")
# Load corpus dataset
corpus = load_dataset("austinmyc/ECT-QA", "corpus")
Temporal-GraphRAG/
โโโ tgrag/
โ โโโ configs/
โ โ โโโ config.yaml # Main configuration
โ โ โโโ prompts.yaml # prompts for indexing and querying
โ โโโ src/
โ โโโ temporal_graphrag.py
โ โโโ ...
โโโ ect-qa/ # ECT-QA dataset
โ โโโ corpus/
โ โ โโโ base.jsonl.gz # 2020 - 2023
โ โ โโโ new.jsonl.gz # 2024
โ โโโ questions/
โ โโโ local_base.jsonl
โ โโโ local_new.jsonl
โ โโโ global_base.jsonl
โ โโโ global_new.jsonl
โโโ graph_storage/
โ โโโ ... # Output graphs
โโโ build_graph.py # Script to build knowledge graph
โโโ query_graph.py # Script to query the graph
โโโ requirements.txt
โโโ README.md
โโโ LICENSE
โโโ .gitignore
@article{han2025rag,
title={RAG Meets Temporal Graphs: Time-Sensitive Modeling and Retrieval for Evolving Knowledge},
author={Han, Jiale and Cheung, Austin and Wei, Yubai and Yu, Zheng and Wang, Xusheng and Zhu, Bing and Yang, Yi},
journal={arXiv preprint arXiv:2510.13590},
year={2025}
}
Paper available at: arXiv:2510.13590