Skip to content

About

standalone Python CLI for benchmarking a running RAGFlow instance over raw HTTP APIs.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

ragflow-bench

ragflow-bench is a standalone Python CLI for benchmarking a running RAGFlow instance over raw HTTP APIs.

It is not part of the RAGFlow repository, does not import RAGFlow source code, and does not depend on RAGFlow internals. It treats RAGFlow as an external service reachable through HTTP.

What it does

  • benchmark retrieval and answer generation against a live RAGFlow deployment
  • support FRAMES, EnterpriseRAG-Bench, and future custom corpora
  • upload and parse benchmark documents through RAGFlow HTTP endpoints
  • write incremental JSONL results so partial runs survive failures
  • score deterministic metrics only: exact match, normalized exact match, source recall, and failure type

Requirements

  • Python 3.11+
  • a reachable RAGFlow instance
  • a valid RAGFlow API key
  • a valid RAGFlow chat model ID for chat-based runs

Default base URL:

http://127.0.0.1:80

Installation

pip install -e .

Environment variables

export RAGFLOW_BASE_URL="http://127.0.0.1:80"
export RAGFLOW_API_KEY="..."
export RAGFLOW_LLM_ID="..."
export MINIMAX_API_KEY="..."
export MINIMAX_BASE_URL="https://api.minimaxi.com/v1"
export MINIMAX_JUDGE_MODEL="MiniMax-M3"
export MINIMAX_JUDGE_TIMEOUT_SECONDS="120"
export MINIMAX_JUDGE_MAX_RETRIES="6"
export MINIMAX_JUDGE_BACKOFF_SECONDS="2.0"
export MINIMAX_JUDGE_MAX_BACKOFF_SECONDS="30.0"
export ZHIPU_API_KEY="..."
export MOONSHOT_API_KEY="..."

Rules:

  • RAGFLOW_BASE_URL defaults to http://127.0.0.1:80
  • RAGFLOW_API_KEY is required unless supplied directly in config
  • RAGFLOW_LLM_ID is required for chat creation and answer generation
  • Judge providers are minimax (default), zhipu, kimi, and custom. Each named provider has a China-mainland endpoint, API-key environment variable, and model preset; explicit judge config values override the preset.
  • minimax uses MINIMAX_API_KEY and MiniMax-M3; zhipu uses ZHIPU_API_KEY and glm-4.7; kimi uses MOONSHOT_API_KEY and kimi-k2.6.
  • Provider-specific *_JUDGE_TIMEOUT_SECONDS, *_JUDGE_MAX_RETRIES, *_JUDGE_BACKOFF_SECONDS, and *_JUDGE_MAX_BACKOFF_SECONDS variables control judge timeout and transient-failure retries. MiniMax keeps the existing MINIMAX_* names.
  • ragflow-bench auto-loads .env from the current working directory without overriding already-exported shell variables
  • .env and .env.* are ignored by git
  • .env.example contains placeholders only

CLI

ragflow-bench --help
ragflow-bench wizard
ragflow-bench doctor
ragflow-bench prepare-frames
ragflow-bench ingest --config configs/frames_smoke.yaml
ragflow-bench retrieve --config configs/frames_smoke.yaml
ragflow-bench run --config configs/frames_smoke.yaml
ragflow-bench run --config configs/frames_smoke.yaml --no-judge
ragflow-bench retry-failed --run-dir outputs/<run>
ragflow-bench artifacts --id 7832948739847349
ragflow-bench artifacts --id 7832948739847349 --restart --limit 100
ragflow-bench score --results outputs/<run>/results.jsonl
ragflow-bench judge --results outputs/<run>/results.jsonl --config configs/frames_oracle.yaml

Doctor

doctor verifies the live RAGFlow connection and probes the HTTP workflow:

  • base URL reachable
  • API key accepted
  • docs-backed health assumptions match the live server where possible
  • dataset creation works
  • document upload works
  • parsing can be started and polled
  • retrieval works
  • chat creation/session/completion work when RAGFLOW_LLM_ID is set

If RAGFLOW_LLM_ID is missing, doctor reports partial success and lists available models when possible.

When a config creates a new dataset, doctor also warns if dataset.embedding_model is omitted, because parsing/indexing will then depend on RAGFlow's server-side default dataset behavior.

Wizard usage

ragflow-bench wizard interactively writes a YAML config, prints the exact run command, and can optionally run it immediately.

Config usage

Configs live under configs/ and can be adapted for local corpora or FRAMES mappings.

For new datasets, set dataset.embedding_model explicitly so RAGFlow uses the intended embedding model during parsing/indexing:

dataset:
  strategy: create_new_dataset_and_ingest_documents
  name: frames-oracle
  embedding_model: your-ragflow-embedding-model-id
  chunk_method: naive

If you reuse an existing dataset, ragflow-bench does not override that dataset's embedding model.

Every run writes:

  • results.jsonl
  • results.csv
  • summary.json
  • run_report.md
  • run_report_questions.md
  • config.resolved.yaml
  • document_registry.json when ingestion is used
  • traces/<question_id>.json when RAGFlow returns an included RAG trace

ragflow-bench run --config ... automatically runs the judge after the benchmark by default. Use --no-judge when you only need raw answers/traces, or when you plan to run compare-runs across async-vs-agent outputs and want to avoid paying for separate per-run judge passes.

Readable Markdown reports are generated after the raw run and refreshed after judge results are available. Generate or refresh them for an existing run with:

ragflow-bench report --run-dir outputs/<run>

run_report.md summarizes results, gold-answer judge scores, trace diagnostics, and the final trace optimization plan when available. run_report_questions.md is a compact per-question table with truncated question/answer/reason cells.

ragflow-bench retry-failed --run-dir outputs/<run> reruns rows with non-empty error using the saved resolved config, stores raw retry attempts under retries/, backs up current result artifacts under backups/, replaces matching question_id rows in-place, and rebuilds results.csv plus summary.json.

ragflow-bench artifacts --id <dataset-id> audits all documents in the selected dataset, checks parsing status and structure artifacts through RAGFlow's HTTP API, and prints a summary. It uses RAGFLOW_BASE_URL and RAGFLOW_API_KEY from the environment, and is read-only by default. Add --restart to restart failed, cancelled, and DONE documents without a non-empty structure artifact. Restarts are submitted in batches of 100; --limit N restricts the number of eligible documents submitted, while omitting --limit submits all eligible documents. The command re-audits immediately after submission and does not wait for parsing to finish.

Async chat vs RAG agent tracing

Chat runs can request the new RAGFlow trace payload for either execution path:

chat:
  execution_path: async_chat   # or rag_agent
  collect_rag_trace: true
  include_rag_trace: true
  disable_web: true

For execution_path: rag_agent, start the RAGFlow backend with RAGFLOW_ENABLE_RAG_AGENT=true. Trace collection is requested the same way for both paths. If a server does not return a trace, the row is kept and rag_trace_warning explains that the trace was absent.

To compare two identical runs that differ only by execution path, first generate a compare judge profile, then run both benchmarks without the automatic per-run judge pass, then run one isolated compare pass:

ragflow-bench wizard --compare-judge-profile \
  --output configs/compare_trace_judge.yaml

ragflow-bench run --config configs/<async-config>.yaml --no-judge
ragflow-bench run --config configs/<agent-config>.yaml --no-judge

ragflow-bench compare-runs \
  --async-run outputs/<async-run> \
  --agent-run outputs/<agent-run> \
  --config configs/compare_trace_judge.yaml \
  --output-dir outputs/compare_async_vs_agent_<timestamp>

The compare command makes two separate judge passes per matched question when enabled by the profile:

  1. Answer comparison scores both final answers against the gold answer and chooses async, agent, tie, both_perfect, or neither_scorable.
  2. Trace comparison loads each row's traces/<question_id>.json sidecar plus retrieval/final-context diagnostics and separately judges which run has better evidence retrieval, context selection, citation support, and trace completeness. Trace judgment does not change answer correctness.

Each compare invocation writes to its own output directory to avoid conflicts between repeated judge runs:

  • compare_answer_results.jsonl and .csv
  • compare_trace_results.jsonl and .csv
  • compare_summary.json
  • compare_config.resolved.yaml

compare_summary.json includes explicit async_correct_pct, agent_correct_pct, partial-or-better percentages, answer win percentages, and trace win/missing/excluded percentages. Legacy --out outputs/async_vs_agent_compare.jsonl is still accepted for scripts that expect a single combined JSONL output.

Generated compare judge profile shape:

judge:
  provider: minimax
  include_confidence: true
  max_completion_tokens: 8192
  timeout_seconds: 120
  max_retries: 3
  backoff_seconds: 10.0
  max_backoff_seconds: 30.0
compare_judge:
  passes:
    answer: true
    trace: true
  trace_inputs:
    include_trace_sidecar: true
    include_raw_retrieval_diagnostics: true
    include_final_context_chunks: true
    include_citation_chunk_ids: true
    include_retrieval_calls: true
    include_tool_calls: true
    include_timings: true
    include_costs: true
    include_raw_response: false
  limits:
    max_trace_chars_per_run: 20000
    max_chunks_per_section: 20
    max_tool_calls: 30
  output:
    default_dir: outputs/compare_async_vs_agent_<timestamp>

LLM judge scoring

Use the standalone judge command after a run to score free-form answers with the configured provider:

ragflow-bench judge --results outputs/<run>/results.jsonl --config configs/frames_oracle.yaml

Switch models just by changing the configured or overridden model name:

ragflow-bench judge --results outputs/<run>/results.jsonl --config configs/frames_oracle.yaml --model MiniMax-M3

The judge command writes:

  • judge_results.jsonl
  • judge_results.csv
  • judge_summary.json
  • refreshed run_report.md and run_report_questions.md

Judge config shape:

judge:
  provider: minimax
  max_completion_tokens: 8192
  timeout_seconds: 120
  max_retries: 6
  backoff_seconds: 2.0
  max_backoff_seconds: 30.0

Named providers need only the provider field unless overriding a preset:

judge:
  provider: zhipu # ZHIPU_API_KEY, glm-4.7, https://open.bigmodel.cn/api/paas/v4
judge:
  provider: kimi # MOONSHOT_API_KEY, kimi-k2.6, https://api.moonshot.cn/v1

Kimi uses its China-mainland API, enables its supported thinking mode, and omits temperature because Kimi K2.6 controls that parameter. For any other OpenAI-compatible service, select provider: custom and explicitly configure base_url, an API key or api_key_env_var, and a model.

The judge evaluates semantic correctness against the gold answer, so different wording can still be marked correct.

Judge retries only transient failures: HTTP 429, HTTP 5xx, and ReadTimeout. When the provider sends Retry-After, the judge honors it up to the configured max backoff. Authentication and malformed-response errors still fail fast.

FRAMES setup

FRAMES uses the Hugging Face dataset:

from datasets import load_dataset
load_dataset("google/frames-benchmark", split="test")

FRAMES questions and gold answers come from Hugging Face, but RAGFlow still needs a local corpus to ingest. Use:

ragflow-bench prepare-frames

By default this creates:

  • data/frames/frames_mapping.json
  • data/frames/corpus/
  • data/frames/prepare_report.json

The command reads the FRAMES question rows, extracts the referenced Wikipedia links, downloads parsed Wikipedia HTML through MediaWiki's HTTP API, converts it into table-preserving Markdown corpus files, deduplicates repeated pages, and writes the mapping file expected by the FRAMES adapter.

Then run either:

ragflow-bench ingest --config configs/frames_oracle.yaml
ragflow-bench run --config configs/frames_oracle.yaml

or retrieve directly, with behavior determined by dataset.strategy:

ragflow-bench retrieve --config configs/frames_smoke.yaml
  • reuse_existing_dataset → retrieve from the configured existing dataset
  • reuse_existing_dataset_and_ingest_documents → upload local corpus documents to the configured existing dataset, wait for parsing, then retrieve
  • create_new_dataset → create a fresh empty dataset, then retrieve
  • create_new_dataset_and_ingest_documents → create a fresh dataset, ingest local corpus documents, wait for parsing, then retrieve

BrowseComp-Plus setup

Prepare the Tevatron BrowseComp-Plus corpus as one Markdown file per document ID:

ragflow-bench prepare-browsecomp-plus

This downloads and decrypts the six dataset parquet shards locally, writes data/browsecomp-plus/corpus/<docid>.md, and creates questions.jsonl, documents_manifest.json, and prepare_report.json. gold_docs become expected_sources; evidence_docs remain as evidence_doc_ids for separate retrieval analysis. Use --question-limit and --document-limit for a smaller local run.

EnterpriseRAG-Bench setup

Prepare the Onyx EnterpriseRAG-Bench artifacts from Hugging Face:

ragflow-bench prepare-eragb

By default this creates:

  • data/eragb/corpus/
  • data/eragb/questions.jsonl
  • data/eragb/documents_manifest.json
  • data/eragb/prepare_report.json

The command downloads the questions/documents parquet files, converts document rows into local text files, and preserves Onyx doc_id values as document source_uri metadata for source-recall scoring. For small local tests, pass --document-limit and --question-limit.

For lower file-count runs where exact source-reference accuracy is not required, use merged shard mode:

ragflow-bench prepare-eragb --merge-documents --filter-questions-with-missing-docs

Merged mode writes deterministic source-type shards, doc_id_to_shard.json, shard_manifest.json, and parser_config.merged.yaml. Shard text contains only a boundary delimiter plus original content to minimize retrieval bias; doc IDs, titles, and source types stay in sidecar manifests. It maps question references to shard URIs by default and labels reference_granularity as shard; do not compare shard recall with document-level leaderboard source recall.

EnterpriseRAG-Bench leaderboard-style score

For EnterpriseRAG-Bench judged runs, judge_summary.json includes an enterprise_rag_bench_leaderboard section with the public leaderboard-style score. This metric is ERAGB-only and is not used for FRAMES or custom benchmarks. It follows the public leaderboard description: per-question contribution is correctness times answer completeness, and local errored or judge-excluded rows are reported but omitted from the local denominator.

Recompute the ERAGB leaderboard-style summary manually and compare your run against the public leaderboard table:

LATEST_RUN="$(ls -td outputs/enterprise_rag_bench_full_* | head -1)"
ragflow-bench eragb-leaderboard-summary \
  --results "$LATEST_RUN/judge_results.jsonl" \
  --download-public-leaderboard \
  --out "$LATEST_RUN/eragb_leaderboard_summary.json"

If you already downloaded the public leaderboard CSV, use:

ragflow-bench eragb-leaderboard-summary \
  --results "$LATEST_RUN/judge_results.jsonl" \
  --leaderboard-csv data/leaderboard/leaderboard.csv \
  --out "$LATEST_RUN/eragb_leaderboard_summary.json"

Per-question public difficulty ranking

Download the public Onyx EnterpriseRAG-Bench leaderboard Space raw data from Hugging Face and generate empirical question difficulty:

ragflow-bench question-difficulty \
  --download-public-leaderboard \
  --out outputs/question_difficulty.jsonl

If you already downloaded the leaderboard Space raw data, point the command at the local directory containing results_*.json files:

ragflow-bench question-difficulty \
  --public-results-dir data/leaderboard/raw_data \
  --out outputs/question_difficulty.jsonl

Compare a local RAGFlow run against the public difficulty ranking. Prefer judge_results.jsonl when available because it contains semantic judge correctness; use results.jsonl when only deterministic exact-match fields are available:

LATEST_RUN="$(ls -td outputs/enterprise_rag_bench_full_* | head -1)"
ragflow-bench question-difficulty \
  --download-public-leaderboard \
  --local-results "$LATEST_RUN/judge_results.jsonl" \
  --out "$LATEST_RUN/question_difficulty.jsonl" \
  --summary-out "$LATEST_RUN/question_difficulty_summary.json"

For a manually downloaded leaderboard, replace --download-public-leaderboard with --public-results-dir data/leaderboard/raw_data. Partial local runs are compared only on tested question_ids. Local rows with errors are counted as ignored error questions and excluded from accuracy and bucket calculations. Missing many public-easy questions usually points to a retrieval, ingestion, prompt, or scoring issue; missing mostly public-hard questions is expected. Solving public-hard questions is a positive signal, and bucketed accuracy is more useful than overall score alone.

Inspect the easiest public questions missed and hardest public questions solved:

python3 - <<'PY'
import glob, json, os
run = os.environ.get("LATEST_RUN") or sorted(glob.glob("outputs/enterprise_rag_bench_full_*"))[-1]
summary = json.load(open(f"{run}/question_difficulty_summary.json"))
print("Easiest public questions missed:")
for row in summary["easy_public_missed"][:20]:
    print(row["question_id"], row["public_correct_rate"], row.get("question", ""))
print("\nHardest public questions solved:")
for row in summary["hard_public_solved"][:20]:
    print(row["question_id"], row["public_correct_rate"], row.get("question", ""))
PY

Known limitations

  • LLM-as-judge quality depends on the selected judge model and prompt; validate cheaper judge models before using them as final benchmark authority
  • live server behavior wins over docs when they disagree
  • chat validation still depends on the selected live RAGFLOW_LLM_ID
  • if parsing fails on a newly created dataset, verify dataset.embedding_model and the corresponding provider binding in the live RAGFlow server

Standalone guarantee

This project does not need to live inside the RAGFlow repository. It only speaks to RAGFlow through HTTP.

About

standalone Python CLI for benchmarking a running RAGFlow instance over raw HTTP APIs.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages