mosomo82/ReMindRAG_Week7

Python

0

75 commits

updated Mar 30, 2026

See the code

README

ReMindRAG: Low-Cost LLM-Guided Knowledge Graph Traversal for Efficient RAG

ReMindRAG CI

ReMindRAG Overall Workflow

ReMindRAG (Retrieve and Memorize)​​ enhances RAG systems by leveraging LLM-guided knowledge graph traversal for efficient, fine-grained retrieval.

Unlike traditional methods, it resolves long dependencies and multi-hop reasoning while minimizing computational overhead. By memorizing traversal paths without additional training, ReMindRAG boosts accuracy and reduces retrieval costs for similar queries. Experiments show superior performance in complex tasks—especially multi-hop reasoning and long-range dependencies—with improved robustness, adaptability, and cost efficiency compared to existing approaches.

CS 5542 — Lab 7 Reproducibility Submission Team: Tony Nguyen · Daniel Evans· Joel Vinas Repository: mosomo82/ReMindRAG_Week7 📺 Demo Video: Watch on YouTube


Quick Start — Single Command

Option A: Docker (no setup required)

docker build -t remindrag:latest .
docker run --rm remindrag:latest
# Expected: SUCCESS: RAG pipeline successfully retrieved chunks from the database.

Option B: Smoke Test (native Python)

pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu126
python tests/smoke_test.py
# Writes result to: artifacts/smoke_test_result.json

Option C: Makefile

make setup       # Install dependencies
make smoke       # Run smoke test
make test        # Run full 17-test audit suite
make streamlit   # Run the standalone Streamlit interface

See RUN.md for complete run instructions including evaluation scripts and WebUI.


Lab 7 Required Documents

DocumentPurpose
RUN.mdComplete run instructions — Docker, native, Makefile, eval
REPRO_AUDIT.md14-issue reproducibility audit with severity ratings and test evidence
RELATED_WORK_REPRO.mdReproduction attempt — what worked, what failed, gaps, improvements
reproduce.shCross-platform automation script (Linux/macOS)
reproduce.ps1PowerShell automation script (Windows)
MakefileConvenience targets: setup, smoke, test, docker, clean
config.yamlConfig-driven execution — all hyperparameters in one place
tests/smoke_test.pySmoke test — exits 0 on success, writes JSON artifact
tests/test_reproducibility.py17-test audit suite covering all 14 reproducibility fixes
artifacts/smoke_test_result.jsonSample output artifact
BENCHMARKING.mdPaper-vs-repro comparison, constrained LooGLE/HotpotQA results
REPRO_VERIFICATION.md26-test suite design, CI YAML, manual verification table
.env.templateSecure onboarding template for API keys

Reproducibility Fixes (17 Issues Resolved)

SeverityIssues Fixed
CRITICALMissing directory creation (model_cache/, chroma_data/, logs/, temp/), UTF-16 encoded requirements file, missing CUDA wheel index URL.
NEW: PyTorch +cu126 wheels crashed Streamlit Cloud deployments; fixed by dropping namespace to standard PyPI wheels.
HIGHHardcoded judge model, missing eval resume guard, daatabase_description typo, undocumented HuggingFace auth.
NEW: NaiveChunker crashed on Markdown tables (token sequence > 512); fixed by pre-splitting on newlines before NLTK sent_tokenize.
MEDIUMWindows path separators → os.path.join, CWD-relative imports → __file__-relative, missing --seed arg.
NEW: Added reproduce.ps1 for native Windows environment bootstrapping. Added einops dependency explicitly required for gated Nomic MoE models.

All fixes verified by automated test suite and Streamlit runtime validations.


Installation

Initialize Environment

conda create -n ReMindRag python==3.13.2
conda activate ReMindRag
pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu126

Note: The --extra-index-url flag is required because PyTorch CUDA 12.6 wheels (torch==2.6.0+cu126) are hosted on PyTorch's own server, not PyPI. For CPU-only, omit the flag or use +cpu suffix.

Note: The embedding model (nomic-ai/nomic-embed-text-v2-moe) requires trust_remote_code=True. This is set automatically inside the library. Set TRUST_REMOTE_CODE=1 if you encounter a hang in non-interactive shells.


Setup

1. API Key

Fill in api_key.json:

[{ "base_url": "https://api.openai.com/v1", "api_key": "sk-proj-..." }]

2. HuggingFace Token

# Persistent (recommended)
huggingface-cli login

# Or per-session
export HF_TOKEN="hf_YourTokenHere"           # Linux/Mac
$env:HF_TOKEN = "hf_YourTokenHere"           # Windows PowerShell

3. Download Embedding Model

Download nomic-ai/nomic-embed-text-v2-moe into ./model_cache/.

For a lightweight smoke test, use sentence-transformers/all-MiniLM-L6-v2 (384-dim, no HF token needed).


Run Example

python example/example.py

Evaluation

Step 1: Download preprocessed LooGLE dataset from Google Drive and extract to eval/dataset_cache/LooGLE-rewrite-data/.

Step 2: Run evaluation:

python eval/eval_LooGLE.py \
  --title_index 0 --data_type longdep_qa \
  --question_type origin --seed 42 \
  --judge_model_name gpt-4o-mini

python eval/eval_Hotpot.py --seed 42 --judge_model_name gpt-4o-mini

--seed ensures deterministic results. --judge_model_name lets you use a cheaper judge (e.g. gpt-4o-mini instead of gpt-4o).


Parameter Configuration

All parameters can be set in config.yaml instead of CLI flags:

python eval/eval_LooGLE.py --config config.yaml
Initialization Parameters
ParameterTypeDefaultDescription
edge_weight_coefficientFloat0.1Adjusts reliance on edge embedding for strong links (range 0.1–0.2)
strong_connection_thresholdFloat0.55Practical range 0.5–0.75 balances retrieval cost and memory capacity
synonym_thresholdFloat0.7Merges entities when embedding similarity exceeds this value
database_descriptionStrNoneA brief one-sentence description of your data
save_dirStrNoneYour data storage path
logger_levelIntNoneLogger level (Level 5 = Trace, lowest)
log_pathStrNoneYour log storage path
Query Parameters
ParameterTypeDefaultDescription
max_jumpsInt10Controls nodes expanded during subgraph queries
max_split_question_numInt1Max sub-questions from semantic decomposition (set 1 to skip split)
search_key_numsInt2Number of seed nodes in query initialization
system_promptStrNoneSystem prompt (uses default if not set)
force_do_ragBoolFalseIf False, system decides automatically whether to do RAG
do_updateBoolTrueIf False, memory function is disabled for this query

Use Your Own Core Components

Use Your Own Language Model
from ReMindRag.llms import OpenaiAgent
agent = OpenaiAgent("your_api_key_url", "your_api_key", "your model name")

Subclass AgentBase in ReMindRag/llms/base.py for custom LLMs.

Use Your Own Embedding Model
from ReMindRag.embeddings import HgEmbedding
embedding = HgEmbedding("your model name", "your model cache dir")

Subclass EmbeddingBase in ReMindRag/embeddings/base.py for custom embeddings.

Use Your Own Chunker
from ReMindRag.chunking import NaiveChunker
chunker = NaiveChunker("your tokenizer name", "your tokenizer cache dir", max_token_length=200)

Subclass ChunkerBase in ReMindRag/chunking/base.py for custom chunking.


Code Structure

Code Structure
ReMindRAG/
├── ReMindRag/                    # Core library
│   ├── rag_main.py               # Main entry point
│   ├── chunking/                 # Text chunking strategies
│   ├── llms/                     # LLM agent interfaces
│   ├── embeddings/               # Embedding model interfaces
│   ├── database/                 # ChromaDB + entity extraction
│   ├── generator/                # Query preprocessing + KG traversal
│   ├── kg/                       # Knowledge graph visualization
│   ├── utils/                    # Utility components
│   └── webui/                    # Flask WebUI
├── eval/                         # Evaluation scripts (LooGLE, HotpotQA)
├── example/                      # Demo script + example data
├── tests/
│   ├── smoke_test.py             # Quick smoke test (no API key needed)
│   └── test_reproducibility.py  # 17-test audit suite
├── artifacts/
│   └── smoke_test_result.json   # Smoke test output artifact
├── logs/                         # Runtime logs
├── Dockerfile                    # Reproducible container build
├── .dockerignore                 # Excludes stale cache from image
├── config.yaml                   # Config-driven execution
├── reproduce.sh                  # Cross-platform automation script
├── Makefile                      # Convenience targets
├── requirements.txt              # Pinned dependencies (146 packages)
├── environment.yml               # Conda environment spec
├── RUN.md                        # Complete run instructions
├── REPRO_AUDIT.md                # 14-issue reproducibility audit
└── RELATED_WORK_REPRO.md         # Related work reproduction report

mosomo82/ReMindRAG_Week7

Python

0

75 commits

updated Mar 30, 2026

See the code

README

ReMindRAG: Low-Cost LLM-Guided Knowledge Graph Traversal for Efficient RAG

ReMindRAG CI

ReMindRAG Overall Workflow

ReMindRAG (Retrieve and Memorize)​​ enhances RAG systems by leveraging LLM-guided knowledge graph traversal for efficient, fine-grained retrieval.

Unlike traditional methods, it resolves long dependencies and multi-hop reasoning while minimizing computational overhead. By memorizing traversal paths without additional training, ReMindRAG boosts accuracy and reduces retrieval costs for similar queries. Experiments show superior performance in complex tasks—especially multi-hop reasoning and long-range dependencies—with improved robustness, adaptability, and cost efficiency compared to existing approaches.

CS 5542 — Lab 7 Reproducibility Submission Team: Tony Nguyen · Daniel Evans· Joel Vinas Repository: mosomo82/ReMindRAG_Week7 📺 Demo Video: Watch on YouTube


Quick Start — Single Command

Option A: Docker (no setup required)

docker build -t remindrag:latest .
docker run --rm remindrag:latest
# Expected: SUCCESS: RAG pipeline successfully retrieved chunks from the database.

Option B: Smoke Test (native Python)

pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu126
python tests/smoke_test.py
# Writes result to: artifacts/smoke_test_result.json

Option C: Makefile

make setup       # Install dependencies
make smoke       # Run smoke test
make test        # Run full 17-test audit suite
make streamlit   # Run the standalone Streamlit interface

See RUN.md for complete run instructions including evaluation scripts and WebUI.


Lab 7 Required Documents

DocumentPurpose
RUN.mdComplete run instructions — Docker, native, Makefile, eval
REPRO_AUDIT.md14-issue reproducibility audit with severity ratings and test evidence
RELATED_WORK_REPRO.mdReproduction attempt — what worked, what failed, gaps, improvements
reproduce.shCross-platform automation script (Linux/macOS)
reproduce.ps1PowerShell automation script (Windows)
MakefileConvenience targets: setup, smoke, test, docker, clean
config.yamlConfig-driven execution — all hyperparameters in one place
tests/smoke_test.pySmoke test — exits 0 on success, writes JSON artifact
tests/test_reproducibility.py17-test audit suite covering all 14 reproducibility fixes
artifacts/smoke_test_result.jsonSample output artifact
BENCHMARKING.mdPaper-vs-repro comparison, constrained LooGLE/HotpotQA results
REPRO_VERIFICATION.md26-test suite design, CI YAML, manual verification table
.env.templateSecure onboarding template for API keys

Reproducibility Fixes (17 Issues Resolved)

SeverityIssues Fixed
CRITICALMissing directory creation (model_cache/, chroma_data/, logs/, temp/), UTF-16 encoded requirements file, missing CUDA wheel index URL.
NEW: PyTorch +cu126 wheels crashed Streamlit Cloud deployments; fixed by dropping namespace to standard PyPI wheels.
HIGHHardcoded judge model, missing eval resume guard, daatabase_description typo, undocumented HuggingFace auth.
NEW: NaiveChunker crashed on Markdown tables (token sequence > 512); fixed by pre-splitting on newlines before NLTK sent_tokenize.
MEDIUMWindows path separators → os.path.join, CWD-relative imports → __file__-relative, missing --seed arg.
NEW: Added reproduce.ps1 for native Windows environment bootstrapping. Added einops dependency explicitly required for gated Nomic MoE models.

All fixes verified by automated test suite and Streamlit runtime validations.


Installation

Initialize Environment

conda create -n ReMindRag python==3.13.2
conda activate ReMindRag
pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu126

Note: The --extra-index-url flag is required because PyTorch CUDA 12.6 wheels (torch==2.6.0+cu126) are hosted on PyTorch's own server, not PyPI. For CPU-only, omit the flag or use +cpu suffix.

Note: The embedding model (nomic-ai/nomic-embed-text-v2-moe) requires trust_remote_code=True. This is set automatically inside the library. Set TRUST_REMOTE_CODE=1 if you encounter a hang in non-interactive shells.


Setup

1. API Key

Fill in api_key.json:

[{ "base_url": "https://api.openai.com/v1", "api_key": "sk-proj-..." }]

2. HuggingFace Token

# Persistent (recommended)
huggingface-cli login

# Or per-session
export HF_TOKEN="hf_YourTokenHere"           # Linux/Mac
$env:HF_TOKEN = "hf_YourTokenHere"           # Windows PowerShell

3. Download Embedding Model

Download nomic-ai/nomic-embed-text-v2-moe into ./model_cache/.

For a lightweight smoke test, use sentence-transformers/all-MiniLM-L6-v2 (384-dim, no HF token needed).


Run Example

python example/example.py

Evaluation

Step 1: Download preprocessed LooGLE dataset from Google Drive and extract to eval/dataset_cache/LooGLE-rewrite-data/.

Step 2: Run evaluation:

python eval/eval_LooGLE.py \
  --title_index 0 --data_type longdep_qa \
  --question_type origin --seed 42 \
  --judge_model_name gpt-4o-mini

python eval/eval_Hotpot.py --seed 42 --judge_model_name gpt-4o-mini

--seed ensures deterministic results. --judge_model_name lets you use a cheaper judge (e.g. gpt-4o-mini instead of gpt-4o).


Parameter Configuration

All parameters can be set in config.yaml instead of CLI flags:

python eval/eval_LooGLE.py --config config.yaml
Initialization Parameters
ParameterTypeDefaultDescription
edge_weight_coefficientFloat0.1Adjusts reliance on edge embedding for strong links (range 0.1–0.2)
strong_connection_thresholdFloat0.55Practical range 0.5–0.75 balances retrieval cost and memory capacity
synonym_thresholdFloat0.7Merges entities when embedding similarity exceeds this value
database_descriptionStrNoneA brief one-sentence description of your data
save_dirStrNoneYour data storage path
logger_levelIntNoneLogger level (Level 5 = Trace, lowest)
log_pathStrNoneYour log storage path
Query Parameters
ParameterTypeDefaultDescription
max_jumpsInt10Controls nodes expanded during subgraph queries
max_split_question_numInt1Max sub-questions from semantic decomposition (set 1 to skip split)
search_key_numsInt2Number of seed nodes in query initialization
system_promptStrNoneSystem prompt (uses default if not set)
force_do_ragBoolFalseIf False, system decides automatically whether to do RAG
do_updateBoolTrueIf False, memory function is disabled for this query

Use Your Own Core Components

Use Your Own Language Model
from ReMindRag.llms import OpenaiAgent
agent = OpenaiAgent("your_api_key_url", "your_api_key", "your model name")

Subclass AgentBase in ReMindRag/llms/base.py for custom LLMs.

Use Your Own Embedding Model
from ReMindRag.embeddings import HgEmbedding
embedding = HgEmbedding("your model name", "your model cache dir")

Subclass EmbeddingBase in ReMindRag/embeddings/base.py for custom embeddings.

Use Your Own Chunker
from ReMindRag.chunking import NaiveChunker
chunker = NaiveChunker("your tokenizer name", "your tokenizer cache dir", max_token_length=200)

Subclass ChunkerBase in ReMindRag/chunking/base.py for custom chunking.


Code Structure

Code Structure
ReMindRAG/
├── ReMindRag/                    # Core library
│   ├── rag_main.py               # Main entry point
│   ├── chunking/                 # Text chunking strategies
│   ├── llms/                     # LLM agent interfaces
│   ├── embeddings/               # Embedding model interfaces
│   ├── database/                 # ChromaDB + entity extraction
│   ├── generator/                # Query preprocessing + KG traversal
│   ├── kg/                       # Knowledge graph visualization
│   ├── utils/                    # Utility components
│   └── webui/                    # Flask WebUI
├── eval/                         # Evaluation scripts (LooGLE, HotpotQA)
├── example/                      # Demo script + example data
├── tests/
│   ├── smoke_test.py             # Quick smoke test (no API key needed)
│   └── test_reproducibility.py  # 17-test audit suite
├── artifacts/
│   └── smoke_test_result.json   # Smoke test output artifact
├── logs/                         # Runtime logs
├── Dockerfile                    # Reproducible container build
├── .dockerignore                 # Excludes stale cache from image
├── config.yaml                   # Config-driven execution
├── reproduce.sh                  # Cross-platform automation script
├── Makefile                      # Convenience targets
├── requirements.txt              # Pinned dependencies (146 packages)
├── environment.yml               # Conda environment spec
├── RUN.md                        # Complete run instructions
├── REPRO_AUDIT.md                # 14-issue reproducibility audit
└── RELATED_WORK_REPRO.md         # Related work reproduction report