Skip to main content

Office-document RAG

Retrieval-augmented Q&A over DOCX, PPTX and XLSX files, built from:

Stage Library Role
Parse Docling Converts Office files into a structured document: headings, paragraphs, lists, tables, images, speaker notes, sheets
Chunk Chonkie RecursiveChunker for prose, TableChunker for large tables (header repeated in every chunk)
Index + query RAG-Anything (on LightRAG) Multimodal knowledge graph + vector index; tables and images are analysed by the LLM / vision model
Models Claude (claude-opus-5-5) + local sentence-transformers embeddings LLM, vision and embeddings

Architecture

A rendered copy is at docs/architecture.png, for editors that don't render Mermaid.

flowchart TB
    subgraph SRC["Sources"]
        F["DOCX / PPTX / XLSX<br/>any European language"]
    end

    subgraph PARSE["1 · Parse — Docling"]
        DC["DocumentConverter"] --> DD["DoclingDocument<br/>reading order · BODY + NOTES layers"]
        DD --> W["Walker + normalize_text<br/>NFC · soft hyphens · no-break spaces"]
    end

    subgraph CHUNK["2 · Chunk — Chonkie"]
        RC["RecursiveChunker<br/>EUROPEAN_RULES"]
        TC["TableChunker<br/>row windows, header repeated"]
    end

    subgraph CL["3 · Content list — MinerU format"]
        TXT["text chunks<br/>breadcrumb + chunk separator"]
        TAB["table items"]
        IMG["image items<br/>PNG on disk"]
        EQ["equation items"]
    end

    subgraph RA["4 · Index — RAG-Anything + LightRAG"]
        LR["LightRAG text insert<br/>split only at chunk separators"]
        MP["Modal processors<br/>table · image · equation"]
        EX["Entity + relation extraction<br/>written in KG_LANGUAGE"]
    end

    subgraph MODELS["Models"]
        CL4["Claude claude-opus-5-5<br/>LLM + vision"]
        EMB["bge-m3<br/>local multilingual embeddings"]
    end

    subgraph STORE["5 · Storage — rag_storage/"]
        KV[("KV: docs · chunks · status")]
        VDB[("Vectors: chunks · entities · relations")]
        KG[("Knowledge graph")]
    end

    subgraph Q["6 · Query"]
        QU["Question, any language"] --> KW["Keyword extraction"]
        KW --> RET["Retrieve: vector search + graph traversal<br/>mode mix · hybrid · local · global · naive"]
        RET --> ANS["Answer in the question's language"]
    end

    F --> DC
    W -- "prose · lists · speaker notes" --> RC --> TXT
    W -- "table > 40 rows" --> TC --> TXT
    W -- "table ≤ 40 rows, or 20-row preview" --> TAB
    W -- pictures --> IMG
    W -- formulas --> EQ

    TXT --> LR --> EX
    TAB --> MP
    IMG --> MP
    EQ --> MP
    MP --> EX

    EX -. calls .-> CL4
    MP -. calls .-> CL4
    LR -. embeds .-> EMB

    LR --> KV
    LR --> VDB
    EX --> VDB
    EX --> KG

    KW -. calls .-> CL4
    RET --> VDB
    RET --> KG
    RET --> KV
    RET -. embeds .-> EMB
    ANS -. calls .-> CL4

Each Chonkie chunk ends with a ␞ separator, and LightRAG is told to split only on it, so LightRAG keeps Chonkie's chunk boundaries instead of re-chunking. Documents get IDs from a hash of their contents, so re-ingesting an unchanged file is a no-op.

Installation

pip install brag-rag        # or: uv tool install brag-rag

This installs the brag command and the brag Python package. Then put your API key in the environment, or in a .env file in the directory you run brag from (see .env.example):

export ANTHROPIC_API_KEY=sk-ant-...

The embedding model (BAAI/bge-m3 by default, about 2.3 GB) downloads on first use. Switching it later means deleting rag_storage/ and re-ingesting, because vector dimensions change.

From source

uv sync
cp .env.example .env   # then set ANTHROPIC_API_KEY
uv run brag --help

Usage

brag parse samples/sales.xlsx        # preview chunks; no API calls
brag ingest samples/ ~/Docs/q3.pptx   # files and/or folders (recursive)
brag query "Which region grew fastest?"
brag query "Summarise the Widget Pro launch" --mode hybrid
brag chat

Query modes: mix (graph + vector, default), hybrid, local, global, naive (vector only).

The index is stored in ./rag_storage and parsed images in ./output, relative to the current directory (set WORKING_DIR / OUTPUT_DIR to change this).

From Python:

from dotenv import load_dotenv
from brag import RAGPipeline

load_dotenv()  # optional: the library reads settings from the environment only

pipeline = RAGPipeline()
await pipeline.ingest(["docs/"])
answer = await pipeline.query("What is the Q4 outlook?")
await pipeline.close()

Multilingual documents

Documents in any European language (Latin, Greek and Cyrillic scripts, plus Armenian and Georgian) can be mixed in one index. No language detection or per-language setup is needed.

  • Normalisation (multilingual.normalize_text): applies Unicode NFC, so decomposed accents such as u + ¨ become ü. It strips soft hyphens and zero-width characters, and turns no-break spaces (including French narrow ones before ? and !) into normal spaces. NFC also folds the Greek question mark into ;.
  • Chunk boundaries (multilingual.EUROPEAN_RULES): splits at paragraphs, then sentences, then clauses, then words, then characters. Sentence ends include . ! ? … ; and the Armenian ։, and also count when followed by a closing quote (" ” “ » « ’). Unlike Chonkie's defaults, the rules never split on ' or -, which would break French and Italian elisions (l'homme, dell'anno) and hyphenated compounds.
  • Embeddings: bge-m3 places all languages in one vector space, so an English question retrieves German, French, Greek or Polish passages.
  • Knowledge graph: entities and descriptions are written in one canonical language (KG_LANGUAGE, English by default). That way "Europäische Union" and "Union européenne" merge into a single entity. Proper nouns stay in their original language.
  • Answers come back in the language of the question.

Configuration

All settings are environment variables; see .env.example. The main ones:

  • LLM_MODEL, LLM_EFFORT: the Claude model and effort used for ingestion (entity extraction, table and image analysis) and for answers. Ingestion makes several LLM calls per chunk, so for large corpora a lower effort or a cheaper model is the main cost lever.
  • CHUNK_SIZE: Chonkie chunk size in o200k_base tokens. LightRAG's limit is set 256 tokens higher to leave room for the breadcrumb.
  • TABLE_MODAL_MAX_ROWS: the cutoff between analysing a table as one unit and row-chunking it.
  • KG_LANGUAGE: the language the knowledge graph is written in. Changing it after ingestion mixes languages in the graph, so re-index if you change it.

Requests use Claude's server-side refusal fallback (fallbacks="default"). If a safety classifier declines a request, it is retried on a fallback model.

Layout

src/brag/cli.py           `brag` command
src/brag/config.py        settings
src/brag/parsing.py       Docling → Chonkie → RAG-Anything content list
src/brag/multilingual.py  Unicode normalisation + European chunking rules
src/brag/models.py        Claude LLM/vision + local embedding functions
src/brag/pipeline.py      RAGAnything wiring, ingest, query
samples/                  example files in English, German, French, Greek and Polish

Releasing

  1. Bump __version__ in src/brag/__init__.py.
  2. Optional dry run: run the Publish workflow by hand from the Actions tab; it uploads to TestPyPI. TestPyPI rejects re-uploads of the same version, so bump the version before each dry run.
  3. Create a GitHub release tagged v<version> (e.g. v0.2.0).
  4. The publish workflow builds the sdist and wheel and uploads them to PyPI with trusted publishing.

To publish by hand instead: uv build && uv publish (needs a PyPI API token).

License

MIT

Metadata

Release files for brag-rag 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brag-rag 0.1.0
File Size Uploaded Provenance Actions
brag_rag-0.1.0.tar.gz 15.8 kB With provenance Details for brag_rag-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brag-rag 0.1.0
File Interpreter ABI Platform Actions
brag_rag-0.1.0-py3-none-any.whl Python 3 none any Details for brag_rag-0.1.0-py3-none-any.whl

Total release size: 34.5 kB

Release files / brag_rag-0.1.0.tar.gz

Download URL brag_rag-0.1.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
355372528eb811f6314dce4a61b6789a588677abba2874c28049d738332e86d4
BLAKE2b-256 checksum
How to use checksums
6348d6ed2fd5b249408d94028ffffb6b4a67cab4100a2f30e9c3ed5186a7c4e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / brag_rag-0.1.0-py3-none-any.whl

Download URL brag_rag-0.1.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f75cbf4fc36c2d118bff7f7786bb8d676ea5df4e5e201ed755b94b66a22e3fe0
BLAKE2b-256 checksum
How to use checksums
be9eb2b80b3ac4a09eaaa9bd76a01deec72309746ce3c6e7da1526a4d2d26f6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for brag-rag 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for brag_rag-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page