█

AI/TLDR

Buy me a coffee
Buy me a coffee

MiniRAG

Graph-based RAG built so small, open language models can do the retrieval work

RAG Frameworks & PlatformsOpen source
Latest
v0.0.2
Updated
27 Feb 2025
Language
Python
License
MIT
$git clone https://github.com/HKUDS/MiniRAG.git

What's new

v0.0.227 Feb 2025

Release adding the API server and PyPI packaging: MiniRAG became installable with pip install minirag-hku.

IN SHORT

What is MiniRAG?

MiniRAG is an open-source Python framework for retrieval-augmented generation (RAG) from HKUDS, accompanying the paper "MiniRAG: Towards Extremely Simple Retrieval-Augmented Generation" (arXiv 2501.06713). It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT. To get started: install from source.

Updated Markdown version ↗

Overview

MiniRAG is an open-source Python framework for retrieval-augmented generation (RAG) from HKUDS, accompanying the paper "MiniRAG: Towards Extremely Simple Retrieval-Augmented Generation" (arXiv 2501.06713). Its goal is narrow and practical: make RAG work well when the model doing the reading is a small language model (SLM) such as Phi-3.5-mini, Qwen2.5-3B or MiniCPM3-4B rather than a large hosted LLM. It is published on PyPI as minirag-hku and builds on the codebase of its sibling project LightRAG.

The design rests on two ideas. First, a semantic-aware heterogeneous graph index puts text chunks and named entities into one graph, with entity-entity and entity-chunk edges, so the index does not depend on a model's ability to write rich relationship descriptions. Second, a lightweight topology-enhanced retrieval step maps the query to likely answer types and entities, then walks the graph structure to find key relationships and the chunks attached to them, before handing the highest-scoring nodes and edges to the model to generate an answer.

MiniRAG framework diagram showing heterogeneous graph indexing, two-step lightweight graph-based knowledge retrieval, and answer generation from high-score nodes and edges
The MiniRAG pipeline: chunks and entities go into one graph, the query is mapped to entities and answer types, and topology-enhanced retrieval picks the paths the small model answers from.MiniRAG README ↗

According to the paper's abstract, this lets MiniRAG reach performance comparable to LLM-based methods even when using SLMs, while requiring only 25% of the storage space. The project also contributes LiHua-World, a benchmark of one year of chat records from a virtual user, with single-hop, multi-hop and summary questions for evaluating on-device RAG. Beyond the research scripts, the repository ships an optional FastAPI server (minirag-server) with document upload, query and Ollama-compatible chat endpoints, plus a Dockerfile and docker-compose file.

What it does

  • Heterogeneous graph indexing that links text chunks and named entities in one structure, reducing reliance on the model's semantic understanding
  • Topology-enhanced graph retrieval (the "mini" query mode) that finds answers by walking graph paths rather than asking the model to reason over long context
  • Pluggable storage backends in the minirag/kg package, including Neo4j, PostgreSQL, MongoDB, Redis, Milvus, Chroma, Weaviate, Oracle and NetworkX
  • LLM and embedding bindings for Hugging Face models, Ollama, OpenAI, Azure OpenAI, Bedrock, LMDeploy, Jina, Zhipu and more
  • Optional minirag-server REST API with /documents and /query endpoints, streaming, API-key protection and an Ollama-compatible interface for chat front ends such as Open WebUI
  • Ships the LiHua-World dataset and reproduce scripts for benchmarking lightweight RAG against NaiveRAG, GraphRAG and LightRAG

Getting started

The README recommends installing from source. You can then use MiniRAG as a Python library (see main.py), reproduce the paper's LiHua-World results, or run the optional API server against Ollama, OpenAI or another backend.

Install from source

Clone the repository and install it in editable mode. Add the [api] extra if you want the minirag-server REST API. The package is also on PyPI as minirag-hku.

bashbash
git clone https://github.com/HKUDS/MiniRAG.git
cd MiniRAG
pip install -e .
# with the API server:
pip install -e ".[api]"

Index and query with a small model

Create a MiniRAG instance with a Hugging Face small model and embedding function, insert text, then query in "mini" mode. This is condensed from the repository's main.py.

pythonpython
from minirag import MiniRAG, QueryParam
from minirag.llm.hf import hf_model_complete, hf_embed
from minirag.utils import EmbeddingFunc
from transformers import AutoModel, AutoTokenizer

EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"

rag = MiniRAG(
    working_dir="./LiHua-World",
    llm_model_func=hf_model_complete,
    llm_model_max_token_size=200,
    llm_model_name="microsoft/Phi-3.5-mini-instruct",
    embedding_func=EmbeddingFunc(
        embedding_dim=384,
        max_token_size=1000,
        func=lambda texts: hf_embed(
            texts,
            tokenizer=AutoTokenizer.from_pretrained(EMBEDDING_MODEL),
            embed_model=AutoModel.from_pretrained(EMBEDDING_MODEL),
        ),
    ),
)

with open("notes.txt") as f:
    rag.insert(f.read())

print(rag.query("Your question here", param=QueryParam(mode="mini")))

Reproduce the LiHua-World benchmark

The LiHua-World data ships in ./dataset/LiHua-World/data/ as LiHuaWorld.zip. Put any other dataset under ./dataset, then run the indexing and QA scripts.

bashbash
python ./reproduce/Step_0_index.py
python ./reproduce/Step_1_QA.py

Run the API server

With the [api] extra installed and Ollama running, minirag-server starts on port 9721 using mistral-nemo:latest for generation and bge-m3:latest for embeddings by default. Switch backends with flags, then upload documents and query over HTTP.

bashbash
minirag-server
# or with OpenAI for both LLM and embeddings:
minirag-server --llm-binding openai --llm-model GPT-4o-mini --embedding-binding openai --embedding-model text-embedding-3-small

curl -X POST "http://localhost:9721/documents/file" -F "file=@/path/to/your/document.txt"
curl -X POST "http://localhost:9721/query" -H "Content-Type: application/json" -d '{"query": "Your question here", "mode": "hybrid"}'

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Run question answering over personal or company documents on a laptop or edge device with a 1.5B-4B parameter model instead of a hosted LLM
  • Cut index storage for a graph-RAG deployment where LightRAG- or GraphRAG-style indexes are too heavy
  • Benchmark small language models on multi-hop and summary questions with the bundled LiHua-World dataset
  • Expose a local RAG index to Open WebUI or other Ollama-compatible chat front ends through minirag-server

Version history

Every verified update to MiniRAG that AI/TLDR tracked, newest first — each links to our coverage and the official changeset.

  1. 2025-02-27v0.0.2

    Release adding the API server and PyPI packaging: MiniRAG became installable with pip install minirag-hku.

  2. 2025-01-16v0.0.1

    First tagged release of the MiniRAG code accompanying the paper.

How MiniRAG compares

MiniRAG alongside other open-source rag frameworks & platforms tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Dify★ 162kAn open-source platform with a visual workflow builder for creating LLM and RAG applications without writing much code.
graphify★ 155kTurns a folder of code, docs, PDFs and images into a local knowledge graph with tree-sitter AST parsing and Leiden communities — queryable by agents over MCP, no vector store.
RAGFlow★ 95kA RAG engine built around deep document understanding that turns complex files into a grounded, citation-backed question-answering layer.
Context7★ 65.7kContext7 pulls current, version-specific documentation and code examples for any library and feeds them into your LLM, available as a CLI skill or an MCP server.
Pathway★ 61.9kA Python framework with a Rust streaming engine that keeps ETL, real-time analytics and RAG pipelines continuously up to date as source data changes.
LightRAG★ 41kA graph-based RAG system that builds an entity-and-relationship knowledge graph for fast retrieval and easy incremental updates.
PageIndex★ 40.8kPageIndex turns long PDFs into a table-of-contents tree and uses LLM reasoning to retrieve relevant sections, with no vector database and no chunking.
MiniRAG★ 2kGraph-based RAG built so small, open language models can do the retrieval work