Skip to main content

Reasoning-aware context runtime for RAG — chunk, retrieve, and allocate the document context an LLM should see, with citations and a Decision Report. In-process, no vector DB.

Project description

RedHop

A reasoning-preserving context runtime for RAG.

Hand it a document and a question. RedHop chunks, retrieves, and allocates the context your model should actually see — then tells you what it kept, what it dropped, and why, with citations back to the source. No vector database, no LLM, all in-process.

import redhop

doc = redhop.Document.from_file("contract.pdf")
ctx = doc.context("What is the governing law?")

answer = llm.generate(ctx.text())   # any LLM provider — no lock-in
pip install redhop

One self-contained wheel — no Python dependencies. The default lexical tier needs no model at all; the semantic/rerank tiers download a small model on first use (cached).

The idea

Retrieval quality is not the same as reasoning quality. Transformers tolerate irrelevant context far better than they tolerate missing reasoning links — so the chunk a multi-hop answer depends on is often low-relevance to the query and gets silently pruned. RedHop's default keeps it, and makes the trade-off visible. It is not a retriever, vector database, agent framework, or workflow engine — it does one thing: turn a document and a query into the right prompt context, and explain the decision.

It explains every decision

Every call returns a Decision Report — what it kept, what it dropped, and why, including when it deliberately leaves a small context untouched.

print(ctx.report)
RedHop Decision Report
══════════════════════

Decision: Auto → pruning (intervened on a diluted context)

  Why:
    - large/diluted contexts dilute attention; pruning recovers signal density
  Result:
    - removed distractor chunks, kept all query-relevant evidence
    - preserved a second-hop link a plain relevance filter would drop

Diagnostics
───────────
  Chunks:             24 → 3
  Second-hop rescues: 1

Read the fields directly via ctx.report.auto_decision, total_tokens, retained_evidence_ratio, or call doc.analyze(query) for the report without assembling a context.

Cite the evidence

Every selected chunk remembers where it came from:

for c in ctx.citations:
    print(c["source"], c["page"], c["heading"])
    # contract.pdf  3     None      ->  "contract.pdf, p.3"
    # notes.md      None  "Refunds" ->  "notes.md -> Refunds"

Loading documents

On-ramp For
Document.from_text(text) text you already have
Document.from_chunks([...]) content you already chunked
Document.from_file("x.pdf") a file — PDF, DOCX, PPTX, XLSX, Markdown, or text/code
Document.from_bytes(data, source="x.pdf") bytes you fetched (S3 / GCS / HTTP / DB)
Document.from_folder("./docs", persist=True) a whole directory, with an optional incremental on-disk index

Retrieval tiers — no vector database

Start at the lexical default — it handles most document QA because the words in the question are usually the words in the answer — and climb only when the failure shape calls for it. All in-process, no ANN, no index server.

# Default — most docs (code, API refs, runbooks, financial reports, handbooks)
doc = redhop.Document.from_file("contract.pdf")
ctx = doc.context("What is the governing law?")

# Structured docs with parallel clauses (regional overrides, per-region sub-sections):
doc = redhop.Document.from_file("msa.pdf", retrieval="hybrid", model="bge-small")
ctx = doc.context("What law applies in the UK?", include_heading=True, neighbors=1)

# Synonym-mismatch corpora (HR FAQs, support tickets where users phrase
# things very differently from the docs). Cross-encoder adds 5–10× latency
# — verify it helps on your corpus before enabling.
doc = redhop.Document.from_file("support.md",
    retrieval="hybrid", model="bge-small", rerank="cross-encoder")

The 60-second decision guide with trade-offs and query-writing tips: CHOOSING_A_CONFIG.

Non-English content

Default is English Snowball. Swap with the language= kwarg — any of the 18 Snowball Porter2 languages (arabic, danish, dutch, english, finnish, french, german, greek, hungarian, italian, norwegian, portuguese, romanian, russian, spanish, swedish, tamil, turkish):

doc = redhop.Document.from_text(german_text, language="german")
# Now `Buch` finds chunks containing `Bücher` (and vice versa)

One analyzer drives both BM25 retrieval AND the grounding scorer, so they can't drift on what "the same term" means. Unknown names raise (we don't silently fall back to English). See the language guide for the full breakdown and the calibration disclaimer (we ship the stemmers; eval-corpus ranking quality on a real domain corpus is the user's call).

Assembly strategies

strategy= What it does
reasoning_preserving (default) keep query-relevant seeds and rescue low-relevance chunks linked to one; drop only unlinked junk
distractor_filtered drop everything below a query-grounding bar
max_density greedily pack the densest chunks into the budget
raw_topk keep retrieval order until the budget fills
auto size-gated: pass small contexts through, prune large/diluted ones

Already have chunks from your own retriever? Use redhop.build_context(query, retrieved_chunks=chunks, ...) for the low-level surface.

Documentation

Full docs, the comparison vs LangChain / LlamaIndex, and the evidence behind every default: https://redhopai.com

Apache-2.0. Also available for Node.js (npm install redhop) and Rust (cargo add redhop).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redhop-0.2.0.tar.gz (284.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

redhop-0.2.0-cp39-abi3-win_amd64.whl (12.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

redhop-0.2.0-cp39-abi3-manylinux_2_28_x86_64.whl (16.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

redhop-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl (16.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

redhop-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (13.9 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

redhop-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file redhop-0.2.0.tar.gz.

File metadata

  • Download URL: redhop-0.2.0.tar.gz
  • Upload date:
  • Size: 284.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redhop-0.2.0.tar.gz
Algorithm Hash digest
SHA256 26aacee571f191c4ea36a71873d627f5e6ff5364648442763b7771f862046092
MD5 3decf5279d3136370c42c9c4c11d2d61
BLAKE2b-256 966204dbdd58f4ee7c464be08b021fcc34b7dcdbc6378117d53b9df0397edd99

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0.tar.gz:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redhop-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: redhop-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 12.9 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redhop-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b2fd9837b6740abfdf5c9c43fb9ae03dba2379c0b355a213472d54ae76c8c788
MD5 8d798558d16efe0ac7151920eb5051f2
BLAKE2b-256 cf728dfd9a43486b7e7f06fbb3bf1a823b301a2b625b607a838bb27004d80d49

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redhop-0.2.0-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for redhop-0.2.0-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ce50854f4526feeb173f3f4a55f1ce7b22c3c8a772847296830a8604b050f36
MD5 81cea9ce59533f79904aaf4b567843ab
BLAKE2b-256 c63b4fe2c923d752c459adfdab7e7153d84e2b8a4bf0e77f7eefca6e2f4d5f2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redhop-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for redhop-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1d6ee3c17abffa11a5197bc7a691c6f47c670461da1280d4c5573f74964f6acc
MD5 18de6283bbfe8b327851ff6d4398c2f8
BLAKE2b-256 08b707f467cc9756f319dd63f4d28f12b265809c99ca9863ca34e436eb7a7992

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redhop-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redhop-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 286c581e497fedb52a5de37edf3c1d6001cc07b0829ed26cd73c871e069b6b68
MD5 3aa057c4da9e60c96c033540164e86ef
BLAKE2b-256 977169b1f1e8b238075454e7437fa6dd676bae9aa951480f145c78c56f626c51

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redhop-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for redhop-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 607876bee1a2ebc8c1dccee83f305d897e695c2bd83d815fead560169c5e4625
MD5 77adb3369ee9ac3bd3f010d9697f28aa
BLAKE2b-256 228e89aca4c07fc1aba1a994fd3524cadc3137f52d5dc27960cb2be1a13f5bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for redhop-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on vysakh0/redhop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page