Skip to content

chensyCN/LogicRAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LogicRAG: Structured RAG Guided by Query Logic Dependency Graph

LogicRAG enables structured retrieval without building knowledge graphs on corpora. By constructing query logic dependency graphs to guide structured retrieval adaptively, it enables test-time scaling of graphRAG on large/dynamic knowledge bases. This work has been accepted to AAAI'26, with an updated version available on Arxiv.

System Architecture

🌟 Key Features

  • ❶ Logic Dependency Analysis: Convert complex questions into logical dependency graphs for planning multi-step retrieval.
  • ❷ Graph Reasoning Linearization: Linearize complex graph reasoning into sequential subproblem solution while maintaining logic-coherence.
  • ❸ Efficiency: Efficient scheduling via graph pruning, and context-length optimization via rolling memory.
  • ❹ Interpretable Results: Provides clear reasoning paths and dependency analysis for better explainability.

🚀 Quick Start

Installation and Configuration

  • Install dependencies:
pip install -r requirements.txt
  • Set your OpenAI API key:
# Create a .env file in the root directory with:
OPENAI_API_KEY=your_api_key_here
  • Other configuration options can be modified in config/config.py

Running Evaluation on a Dataset

python run.py --model logic-rag --dataset path/to/dataset.json --corpus path/to/corpus.json --max-rounds 5 --top-k 3

Options:

  • --max-rounds: Maximum number of reasoning rounds (default: 3)
  • --top-k: Number of top contexts to retrieve (default: 5)
  • --limit: Number of questions to evaluate (default: 20)
    • Set to 0 to process all questions in the dataset

Running a Single Question

python run.py --model logic-rag --question "Your question here" --corpus path/to/corpus.json --max-rounds 5 --top-k 3

Example Usage

from src.models.logic_rag import LogicRAG

# Initialize RAG system
rag = LogicRAG('path/to/corpus.json')
rag.set_max_rounds(5)
rag.set_top_k(3)

# Ask a question
answer, contexts, rounds = rag.answer_question("What is the capital of France?")
print(f"Answer: {answer}")
print(f"Retrieved in {rounds} rounds")

🍀 Citation

If you find this work helpful, please cite our paper:

@inproceedings{logicrag,
title={You Don't Need Pre-built Graphs for {RAG}: Retrieval Augmented Generation with Adaptive Reasoning Structures},
author={Shengyuan Chen and Chuang Zhou and Zheng Yuan and Qinggang Zhang and Zeyang Cui and Hao Chen and Yilin
Xiao and Jiannong Cao and Xiao Huang},
booktitle={The Fortieth AAAI Conference on Artificial Intelligence},
year={2026}
}

About

Source code of LogicRAG at AAAI'26.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages