█

AI/TLDR

Buy me a coffee
Buy me a coffee

TrustRAG

A configurable, modular Python RAG framework built around "reliable input, trusted output", with citations, reranking and a Gradio studio

RAG Frameworks & PlatformsOpen source
Language
Python
$conda create -n trustrag python=3.12.0
IN SHORT

What is TrustRAG?

TrustRAG is a configurable and modular retrieval-augmented generation (RAG) framework for Python, built by the GoMate team at the Key Laboratory of Network Data Science and Technology. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python. To get started: create an environment and install.

Overview

TrustRAG is a configurable and modular retrieval-augmented generation (RAG) framework for Python, built by the GoMate team at the Key Laboratory of Network Data Science and Technology. Its motto is "reliable input, trusted output": the goal is high-quality, trustworthy answers in retrieval-based question answering, and every stage of the pipeline is a separate module you can swap or tune for your own scenario.

The Chat tab of TrustRAG Studio: model, top-k and RAG mode settings on the left, a cited answer in the middle, and reformulated queries, selected evidence and a claim attribution panel on the right
TrustRAG Studio's chat view shows the answer with numbered citations next to the rewritten queries and the evidence each claim came from.TrustRAG README ↗

The package is organised as a set of modules that map onto the RAG chain: document parsing and chunking, query rewriting, retrieval, reranking, a judger for document selection, a refiner for summarising context, a generator, prompts, and citation of answers back to their evidence. You can import those pieces directly and wire your own pipeline, or start from the ready-made RagApplication class and its Gradio front end, TrustRAG Studio, which manages a knowledge base and chats over it.

Beyond plain retrieval QA, the project includes a RAPTOR recursive tree retriever, a multimodal RAG example built on GLM-4V-Flash, a web-search engine supporting DuckDuckGo and SearXNG, and a DeepResearch pipeline that splits a question into sub-queries and loops through search, read, reflect, coding and answer actions within a token budget and action-depth limit to produce a research report. The framework is described in the arXiv paper "TrustRAG: An Information Assistant with Retrieval Augmented Generation" (arXiv:2502.13719).

What it does

TrustRAG framework diagram: a RAG chain of query processing, query transformation, retrieval, rerank and judge, prompt engineering, generation, citation and post-processing, fed by an unstructured data pipeline of ingestion, parsing, chunking, indexing and a vector database
The framework diagram maps each stage of the RAG chain to the modules that implement it.TrustRAG README ↗
  • Modular parsing of text, docx, ppt, excel, html, pdf and md files, with MinerU-based PDF parsing and a TextChunker that uses the InfiniFlow huqie tokenizer
  • BM25, dense and hybrid retrievers with configurable weights, index building, incremental additions and saved indexes, plus a RAPTOR recursive tree retriever
  • Rerankers ranging from BGE cross-encoders to LLM-based pointwise, pairwise and setwise reranking, a HyDE query rewriter and a BGE judge for document relevance
  • Citation generation that links answer sentences back to the retrieved evidence
  • Vector database engines such as Milvus and Qdrant, and a web-search engine for DuckDuckGo and SearXNG
  • TrustRAG Studio, a Gradio app for uploading a corpus, setting chunk size and chatting in RAG or LLM-only mode, plus a Dockerfile for deployment

Getting started

TrustRAG installs from PyPI or from source. The README walks through building a pipeline in code (parse, chunk, index, retrieve, rerank, generate) and then launching the TrustRAG Studio web app over your own documents.

Create an environment and install

A conda environment is optional. Install the package from PyPI.

bashbash
conda create -n trustrag python=3.12.0
conda activate trustrag
pip install trustrag

Or install from source

Clone the repository to get the apps, examples and configs, then install it in editable mode.

bashbash
git clone https://github.com/gomate-community/TrustRAG.git
cd TrustRAG
pip install -e .

Configure a hybrid retriever

HybridRetrieverConfig combines a BM25 config and a dense-embedding config, each with its own weight, because the two scores are not on the same scale.

pythonpython
from trustrag.modules.retrieval.bm25s_retriever import BM25RetrieverConfig
from trustrag.modules.retrieval.dense_retriever import DenseRetrieverConfig
from trustrag.modules.retrieval.hybrid_retriever import HybridRetriever, HybridRetrieverConfig

bm25_config = BM25RetrieverConfig(
    method='lucene',
    index_path='indexs/description_bm25.index',
    k1=1.6,
    b=0.7
)
dense_config = DenseRetrieverConfig(
    model_name_or_path=embedding_model_path,
    dim=1024,
    index_path='indexs/dense_cache'
)
hybrid_config = HybridRetrieverConfig(
    bm25_config=bm25_config,
    dense_config=dense_config,
    bm25_weight=0.7,
    dense_weight=0.3
)
hybrid_retriever = HybridRetriever(config=hybrid_config)

Build the index and retrieve

Build the index from your chunked corpus and save it (or call load_index() on later runs), then query it.

pythonpython
hybrid_retriever.build_from_texts(corpus)
hybrid_retriever.save_index()

results = hybrid_retriever.retrieve("Alipay", top_k=10)
for result in results:
    print(f"Text: {result['text']}, Score: {result['score']}")

Rerank and generate an answer

Rerank the retrieved passages with a BGE reranker and pass them as context to the generator.

pythonpython
from trustrag.modules.reranker.bge_reranker import BgeReranker, BgeRerankerConfig
from trustrag.modules.generator.llm import GLM4Chat

bge_reranker = BgeReranker(BgeRerankerConfig(model_name_or_path='llms/bge-reranker-large'))
glm4_chat = GLM4Chat(llm_model_path)

search_docs = hybrid_retriever.retrieve(question, top_k=10)
search_docs = bge_reranker.rerank(query=question, documents=[doc['text'] for doc in search_docs])
content = '\n'.join([f'Information[{idx}]:' + doc['text'] for idx, doc in enumerate(search_docs)])
answer = glm4_chat.chat(prompt=question, content=content)

Launch TrustRAG Studio

Point the application config at your docs folder, embedding model and reranker, then start the Gradio app and open 127.0.0.1:7860 in a browser.

bashbash
python app.py
The Corpus tab of TrustRAG Studio with knowledge-base, chunk size and chunk overlap settings, a table of uploaded documents, and a file upload area
The Corpus tab manages the knowledge base: chunking settings, the document list and file uploads.TrustRAG README ↗

Run the DeepResearch pipeline

The DeepResearch module ships an .env.example for the LLM API and search settings; copy it, fill it in and run the pipeline.

bashbash
cd trustrag/modules/deepresearch
cp .env.example .env
python pipeline.py

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

When to use it

  • Build a question-answering assistant over a private document collection with answers cited back to their sources
  • Experiment with retrieval and reranking strategies (BM25, dense, hybrid, RAPTOR, LLM rerankers) by swapping one module at a time
  • Give non-developers a web UI to upload a knowledge base and chat over it in RAG or LLM-only mode
  • Generate research reports from web search with an iterative search, read and reflect loop

How TrustRAG compares

TrustRAG 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.
TrustRAG★ 1.3kA configurable, modular Python RAG framework built around "reliable input, trusted output", with citations, reranking and a Gradio studio