Skip to content

XMUDeepLIT/MemGraphRAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MemGraphRAG: Memory-based Multi-Agent System for Graph Retrieval-Augmented Generation

arXiv GitHub Stars License

A memory-enhanced GraphRAG framework that connects unstructured passages, extracted facts, and abstract schemas in a three-layer memory for reliable retrieval and generation.

πŸŽ‰ News

  • [2026-05-17] Our MemGraphRAG for memory-enhanced RAG is accepted by KDD'26.
  • [2026-04-07] Our ProbeRAG for RAG faithfulness is accepted by ACL'26.
  • [2026-04-07] Our BAPO for reliable agentic search is accepted by ACL'26.
  • [2026-04-07] Our LegalGraphRAG for reliable legal reasoning is accepted by ACL'26.
  • [2026-04-07] Our LogicPoison, a GraphRAG attack model, is accepted by ACL'26.
  • [2026-01-26] Our LinearRAG for efficient GraphRAG is accepted by ICLR’26.
  • [2026-01-26] Our GraphRAG Benchmark is accepted by ICLR’26.
  • [2025-11-08] Our LogicRAG is accepted by AAAI'26.
  • [2025-10-27] We release LinearRAG, a relation-free graph construction method for efficient GraphRAG.
  • [2025-06-06] We release the GraphRAG Benchmark for evaluating GraphRAG models.
  • [2025-05-14] We release the GraphRAG Benchmark dataset.
  • [2025-01-21] We release the GraphRAG survey.

πŸ“ƒ Please cite our paper if you find this repository helpful.

πŸ“« Contact: {xiangzhishang,wuchuanjie}@stu.xmu.edu.cn, qinggangzhang@jlu.edu.cn

🏴 Overview

MemGraphRAG Framework

MemGraphRAG organizes knowledge into three connected layers:

  • Schema layer: abstract ontology triples such as (head type, relation, tail type).
  • Fact layer: concrete relation triples extracted from the corpus.
  • Passage layer: original text chunks that support the facts.

Key Features

  • Three-layer memory: bidirectional links among schemas, facts, and source passages.
  • Ontology induction: abstracts facts into reusable schemas and filters low-frequency patterns.
  • Conflict-aware construction: detects hard conflicts with passage evidence and resolves connected conflict groups.
  • Memory-derived graph: creates type, entity, and passage nodes after conflict resolution.
  • Graph-enhanced retrieval: combines embedding similarity and Personalized PageRank.
  • Batch QA: records answers, retrieved documents, scores, latency, and token usage.

πŸ›  Quickstart Guide

1. Environment Setup

Python 3.10 or later is recommended. The online pipeline uses an OpenAI-compatible LLM endpoint and a local Hugging Face embedding model.

conda create -n memgraphrag python=3.10
conda activate memgraphrag

git clone https://github.com/XMUDeepLIT/MemGraphRAG.git
cd MemGraphRAG
pip install -r requirements.txt

For offline OpenIE, also install vllm or llama-factory. Optional embedding backends may require packages such as gritlm.

2. Configure Models and Credentials

export OPENAI_API_KEY="your-api-key"
export CUDA_VISIBLE_DEVICES="0"

LLM_NAME="gpt-4o-mini"
LLM_BASE_URL="https://your-openai-compatible-endpoint/v1"
EMBEDDING_MODEL="/path/to/bge-large-en-v1.5"

Use the same LLM_NAME and EMBEDDING_MODEL for indexing and retrieval because their values identify the saved graph and embedding stores.

3. Run Indexing

Run from the repository root. The corpus must be a UTF-8 plain-text file.

python code/index.py \
  --corpus datasets/corpus/corpus.txt \
  --save-dir outputs/corpus \
  --llm-name "$LLM_NAME" \
  --llm-base-url "$LLM_BASE_URL" \
  --embedding-model "$EMBEDDING_MODEL" \
  --tokenizer "$EMBEDDING_MODEL" \
  --chunk-size 256 \
  --chunk-overlap 32 \
  --artifact-mode default

Add --force-index-from-scratch and --force-openie-from-scratch to rebuild the corresponding caches.

outputs/corpus/
β”œβ”€β”€ openie_results_ner_<llm>.json
β”œβ”€β”€ initial_memory_with_schema.json
β”œβ”€β”€ memory.json
β”œβ”€β”€ graph_from_memory/
β”‚   β”œβ”€β”€ memory_graph.json
β”‚   └── memory_graph.graphml
└── <llm>_<embedding_model>/
    β”œβ”€β”€ graph.graphml
    β”œβ”€β”€ chunk_embeddings/
    β”œβ”€β”€ entity_embeddings/
    └── fact_embeddings/

4. Run Retrieval and Question Answering

python code/retrieval_dataset_test.py \
  --questions datasets/corpus/small-questions.json \
  --save-dir outputs/corpus \
  --output results/corpus/qa_results.json \
  --llm-name "$LLM_NAME" \
  --llm-base-url "$LLM_BASE_URL" \
  --embedding-model "$EMBEDDING_MODEL" \
  --question-type all \
  --sample-num 0 \
  --skip-fact-rerank true \
  --fact-similarity-threshold 0.4 \
  --use-raw-threshold-filter true

The result JSON contains the run summary, effective configuration, solutions, raw responses, metadata, retrieved passages.

code/run_index.sh and code/run_retrieval_test.sh are editable launch templates. Adjust their interpreter, paths, endpoint, model, and GPU settings before use.

πŸ“ Dataset Format

The QA runner accepts a flat list of question objects or questions grouped by type:

[
  {
    "source": "dataset-name",
    "questions": {
      "type1": [
        {
          "id": "type1_0",
          "question": "Your question",
          "answer": "Gold answer",
          "evidence": ["Optional supporting evidence"]
        }
      ]
    }
  }
]

Set --question-type type1 for one group or --question-type all for all groups. --sample-num 0 loads every question.

πŸ“¦ Code Structure

πŸ“¦ .
β”œβ”€β”€ πŸ“‚ code
β”‚   β”œβ”€β”€ πŸ“‚ src
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ embedding_model        # Embedding backends
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ evaluation             # Retrieval and QA metrics
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ information_extraction # Online and offline OpenIE
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ llm                    # OpenAI-compatible and vLLM backends
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ prompts                # Extraction, linking, QA, memory prompts
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ utils                  # Configuration and utilities
β”‚   β”‚   β”œβ”€β”€ MemGraphRAG.py            # Pipeline orchestration
β”‚   β”‚   β”œβ”€β”€ Memory.py                 # Three-layer memory
β”‚   β”‚   β”œβ”€β”€ embedding_store.py        # Persistent embedding stores
β”‚   β”‚   └── rerank.py                 # Fact reranking and filtering
β”‚   β”œβ”€β”€ index.py                      # Indexing CLI
β”‚   β”œβ”€β”€ retrieval_dataset_test.py     # Retrieval and QA CLI
β”‚   β”œβ”€β”€ run_index.sh                  # Indexing template
β”‚   └── run_retrieval_test.sh         # Retrieval template
β”œβ”€β”€ πŸ“‚ datasets                       # Example corpora and QA datasets
β”œβ”€β”€ πŸ“‚ outputs                        # Generated artifacts
└── πŸ“œ README.md

πŸ™ Acknowledgements

Our framework builds upon the excellent work HippoRAG. We also thank the open-source communities behind Hugging Face Transformers, OpenAI-compatible APIs, and igraph.

πŸ€ Citation

@article{wu2026memgraphrag,
  title={MemGraphRAG: Memory-based Multi-Agent System for Graph Retrieval-Augmented Generation},
  author={Wu, Chuanjie and Xiang, Zhishang and Tang, Yunbo and Chen, Zerui and Zhang, Qinggang and Su, Jinsong},
  journal={arXiv preprint arXiv:2606.00610},
  year={2026}
}

Links: arXiv

πŸ“„ License

This project is released under the MIT License.

About

[KDD 2026] MemGraphRAG: Memory-based Multi-Agent System for Graph Retrieval-Augmented Generation

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors