redhop 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. redhop-0.1.2/Cargo.toml +88 -0
  2. redhop-0.1.2/LICENSE +202 -0
  3. redhop-0.1.2/PKG-INFO +140 -0
  4. redhop-0.1.2/README.md +119 -0
  5. redhop-0.1.2/crates/redhop/Cargo.toml +72 -0
  6. redhop-0.1.2/crates/redhop/LICENSE +202 -0
  7. redhop-0.1.2/crates/redhop/README.md +174 -0
  8. redhop-0.1.2/crates/redhop/src/chunking/adaptive.rs +294 -0
  9. redhop-0.1.2/crates/redhop/src/chunking/fixed.rs +148 -0
  10. redhop-0.1.2/crates/redhop/src/chunking/mod.rs +35 -0
  11. redhop-0.1.2/crates/redhop/src/chunking/sentence.rs +214 -0
  12. redhop-0.1.2/crates/redhop/src/chunking/tokenizer.rs +96 -0
  13. redhop-0.1.2/crates/redhop/src/context/mod.rs +1775 -0
  14. redhop-0.1.2/crates/redhop/src/core/error.rs +71 -0
  15. redhop-0.1.2/crates/redhop/src/core/mod.rs +40 -0
  16. redhop-0.1.2/crates/redhop/src/core/state.rs +546 -0
  17. redhop-0.1.2/crates/redhop/src/core/traits.rs +211 -0
  18. redhop-0.1.2/crates/redhop/src/core/types.rs +448 -0
  19. redhop-0.1.2/crates/redhop/src/document/mod.rs +954 -0
  20. redhop-0.1.2/crates/redhop/src/embeddings/cache.rs +224 -0
  21. redhop-0.1.2/crates/redhop/src/embeddings/config.rs +104 -0
  22. redhop-0.1.2/crates/redhop/src/embeddings/hashing.rs +137 -0
  23. redhop-0.1.2/crates/redhop/src/embeddings/mod.rs +61 -0
  24. redhop-0.1.2/crates/redhop/src/embeddings/onnx.rs +269 -0
  25. redhop-0.1.2/crates/redhop/src/embeddings/pooling.rs +161 -0
  26. redhop-0.1.2/crates/redhop/src/embeddings/registry.rs +258 -0
  27. redhop-0.1.2/crates/redhop/src/files/docx.rs +95 -0
  28. redhop-0.1.2/crates/redhop/src/files/mod.rs +269 -0
  29. redhop-0.1.2/crates/redhop/src/files/pdf.rs +32 -0
  30. redhop-0.1.2/crates/redhop/src/files/pptx.rs +90 -0
  31. redhop-0.1.2/crates/redhop/src/files/text.rs +288 -0
  32. redhop-0.1.2/crates/redhop/src/files/xlsx.rs +41 -0
  33. redhop-0.1.2/crates/redhop/src/lib.rs +91 -0
  34. redhop-0.1.2/crates/redhop/src/load.rs +552 -0
  35. redhop-0.1.2/crates/redhop/src/reranking/cross_encoder.rs +258 -0
  36. redhop-0.1.2/crates/redhop/src/reranking/evidence_density.rs +141 -0
  37. redhop-0.1.2/crates/redhop/src/reranking/lexical.rs +132 -0
  38. redhop-0.1.2/crates/redhop/src/reranking/mod.rs +38 -0
  39. redhop-0.1.2/crates/redhop/src/reranking/score_fusion.rs +71 -0
  40. redhop-0.1.2/crates/redhop/src/retrieval/bm25.rs +250 -0
  41. redhop-0.1.2/crates/redhop/src/retrieval/dense.rs +138 -0
  42. redhop-0.1.2/crates/redhop/src/retrieval/fusion.rs +209 -0
  43. redhop-0.1.2/crates/redhop/src/retrieval/hybrid.rs +178 -0
  44. redhop-0.1.2/crates/redhop/src/retrieval/local_rerank.rs +440 -0
  45. redhop-0.1.2/crates/redhop/src/retrieval/mod.rs +32 -0
  46. redhop-0.1.2/crates/redhop/src/storage/chunk_store.rs +72 -0
  47. redhop-0.1.2/crates/redhop/src/storage/flat.rs +126 -0
  48. redhop-0.1.2/crates/redhop/src/storage/mod.rs +27 -0
  49. redhop-0.1.2/crates/redhop/tests/files_extract.rs +210 -0
  50. redhop-0.1.2/crates/redhop/tests/fixtures/sample.docx +0 -0
  51. redhop-0.1.2/crates/redhop/tests/fixtures/sample.pdf +103 -0
  52. redhop-0.1.2/crates/redhop/tests/fixtures/sample.pptx +0 -0
  53. redhop-0.1.2/crates/redhop/tests/fixtures/sample.xlsx +0 -0
  54. redhop-0.1.2/crates/redhop/tests/smoke.rs +80 -0
  55. redhop-0.1.2/pyproject.toml +63 -0
  56. redhop-0.1.2/python/.gitignore +10 -0
  57. redhop-0.1.2/python/Cargo.lock +3972 -0
  58. redhop-0.1.2/python/Cargo.toml +48 -0
  59. redhop-0.1.2/python/LICENSE +202 -0
  60. redhop-0.1.2/python/README.md +119 -0
  61. redhop-0.1.2/python/eval/score_dilution.py +229 -0
  62. redhop-0.1.2/python/eval/score_local_rerank.py +129 -0
  63. redhop-0.1.2/python/eval/score_reasoning_qa.py +277 -0
  64. redhop-0.1.2/python/eval/score_semantic_natural.py +165 -0
  65. redhop-0.1.2/python/eval/static_rerank.py +144 -0
  66. redhop-0.1.2/python/examples/_sample.py +50 -0
  67. redhop-0.1.2/python/examples/basic_rag.py +73 -0
  68. redhop-0.1.2/python/examples/compare_strategies.py +70 -0
  69. redhop-0.1.2/python/examples/dashboard.py +121 -0
  70. redhop-0.1.2/python/examples/economics_demo.py +51 -0
  71. redhop-0.1.2/python/examples/quickstart.py +65 -0
  72. redhop-0.1.2/python/src/lib.rs +1645 -0
  73. redhop-0.1.2/python/tests/test_api.py +89 -0
  74. redhop-0.1.2/python/tests/test_loader_errors.py +64 -0
  75. redhop-0.1.2/python/tests/test_loaders.py +354 -0
  76. redhop-0.1.2/python/tests/test_rerank.py +110 -0
  77. redhop-0.1.2/redhop/__init__.py +184 -0
@@ -0,0 +1,88 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = [
4
+ "crates/redhop",
5
+ "crates/calibration",
6
+ "crates/diagnostics",
7
+ "crates/observability",
8
+ "crates/orchestration",
9
+ "crates/pipeline",
10
+ "crates/benchmarks",
11
+ "crates/examples",
12
+ "crates/cli",
13
+ ]
14
+
15
+ [workspace.lints.rust]
16
+ rust_2018_idioms = { level = "warn", priority = -1 }
17
+ unused = "warn"
18
+
19
+ [workspace.lints.clippy]
20
+ # Opinionated baseline: the standard clippy groups are warnings, enforced as
21
+ # errors in CI (`cargo clippy -- -D warnings`). priority -1 lets the specific
22
+ # allows below win.
23
+ all = { level = "warn", priority = -1 }
24
+ # Deliberately permitted: index-based loops are clearer than iterator chains in
25
+ # numeric / parallel-array kernels (pooling, centroids, bootstrap), and this is
26
+ # a style call, not a correctness one.
27
+ needless_range_loop = "allow"
28
+
29
+ [workspace.package]
30
+ version = "0.1.2"
31
+ edition = "2021"
32
+ rust-version = "1.75"
33
+ license = "Apache-2.0"
34
+ authors = ["Vysakh Sreenivasan", "RedHop Contributors"]
35
+ repository = "https://github.com/vysakh0/redhop"
36
+ homepage = "https://github.com/vysakh0/redhop"
37
+ description = "RedHop — a reasoning-aware retrieval & context runtime for RAG: chunk, retrieve, and allocate the document context an LLM should see, with citations and a Decision Report."
38
+ keywords = ["rag", "retrieval", "llm", "context", "nlp"]
39
+ categories = ["text-processing", "science"]
40
+
41
+ [workspace.dependencies]
42
+ # The single published crate. Internal workspace members (cli, calibration,
43
+ # diagnostics, observability, orchestration, pipeline, benchmarks) depend on
44
+ # `redhop` directly — there is no more `redhop-core` / `redhop-context` / …
45
+ # as separate crates; those are now modules: `redhop::core`, `redhop::context`, …
46
+ redhop = { path = "crates/redhop" }
47
+ # Internal (publish = false). Dev / research / orchestration code that stays
48
+ # in the workspace but is not part of the published Rust API.
49
+ redhop-diagnostics = { path = "crates/diagnostics" }
50
+ redhop-observability = { path = "crates/observability" }
51
+ redhop-orchestration = { path = "crates/orchestration" }
52
+ redhop-pipeline = { path = "crates/pipeline" }
53
+ redhop-calibration = { path = "crates/calibration" }
54
+
55
+ # Core runtime / concurrency
56
+ tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "sync"] }
57
+ rayon = "1.10"
58
+ futures = "0.3"
59
+
60
+ # Serialization / error handling
61
+ serde = { version = "1", features = ["derive"] }
62
+ serde_json = "1"
63
+ anyhow = "1"
64
+ thiserror = "1"
65
+
66
+ # Observability
67
+ tracing = "0.1"
68
+ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
69
+
70
+ # Text / tokenization
71
+ unicode-segmentation = "1.11"
72
+ regex = "1.10"
73
+
74
+ # Optional heavyweight backends (gated behind features in their crates)
75
+ tantivy = "0.22"
76
+
77
+ # Bench / test
78
+ criterion = { version = "0.5", features = ["html_reports"] }
79
+
80
+ [profile.release]
81
+ lto = "thin"
82
+ codegen-units = 1
83
+ opt-level = 3
84
+ debug = false
85
+
86
+ [profile.bench]
87
+ lto = "thin"
88
+ codegen-units = 1
redhop-0.1.2/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
redhop-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: redhop
3
+ Version: 0.1.2
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: Apache Software License
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Rust
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Classifier: Topic :: Text Processing :: Linguistic
11
+ License-File: LICENSE
12
+ Summary: 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.
13
+ Keywords: rag,retrieval,llm,context,nlp
14
+ Author: Vysakh Sreenivasan, RedHop Contributors
15
+ License: Apache-2.0
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
+ Project-URL: Homepage, https://github.com/vysakh0/redhop
19
+ Project-URL: Repository, https://github.com/vysakh0/redhop
20
+
21
+ # RedHop
22
+
23
+ **A reasoning-aware context runtime for RAG.**
24
+
25
+ Hand it a document and a question. RedHop chunks, retrieves, and allocates the
26
+ context your model should actually see — then tells you what it kept, what it dropped,
27
+ and why, with citations back to the source. No vector database, no LLM, all in-process.
28
+
29
+ ```python
30
+ import redhop
31
+
32
+ doc = redhop.Document.from_file("contract.pdf")
33
+ ctx = doc.context("What is the governing law?")
34
+
35
+ answer = llm.generate(ctx.text()) # any LLM provider — no lock-in
36
+ ```
37
+
38
+ ```bash
39
+ pip install redhop
40
+ ```
41
+
42
+ One self-contained wheel — no Python dependencies. The default lexical tier needs no
43
+ model at all; the semantic/rerank tiers download a small model on first use (cached).
44
+
45
+ ## The idea
46
+
47
+ **Retrieval quality is not the same as reasoning quality.** Transformers tolerate
48
+ irrelevant context far better than they tolerate *missing reasoning links* — so the
49
+ chunk a multi-hop answer depends on is often low-relevance to the query and gets
50
+ silently pruned. RedHop's default keeps it, and makes the trade-off visible. It is
51
+ **not** a retriever, vector database, agent framework, or workflow engine — it does one
52
+ thing: turn a document and a query into the right prompt context, and explain the
53
+ decision.
54
+
55
+ ## It explains every decision
56
+
57
+ Every call returns a **Decision Report** — what it kept, what it dropped, and *why*,
58
+ including when it deliberately leaves a small context untouched.
59
+
60
+ ```python
61
+ print(ctx.report)
62
+ ```
63
+
64
+ ```text
65
+ RedHop Decision Report
66
+ ══════════════════════
67
+
68
+ Decision: Auto → pruning (intervened on a diluted context)
69
+
70
+ Why:
71
+ - large/diluted contexts dilute attention; pruning recovers signal density
72
+ Result:
73
+ - removed distractor chunks, kept all query-relevant evidence
74
+ - preserved a second-hop link a plain relevance filter would drop
75
+
76
+ Diagnostics
77
+ ───────────
78
+ Chunks: 24 → 3
79
+ Second-hop rescues: 1
80
+ ```
81
+
82
+ Read the fields directly via `ctx.report.auto_decision`, `total_tokens`,
83
+ `retained_evidence_ratio`, or call `doc.analyze(query)` for the report **without**
84
+ assembling a context.
85
+
86
+ ## Cite the evidence
87
+
88
+ Every selected chunk remembers where it came from:
89
+
90
+ ```python
91
+ for c in ctx.citations:
92
+ print(c["source"], c["page"], c["heading"])
93
+ # contract.pdf 3 None -> "contract.pdf, p.3"
94
+ # notes.md None "Refunds" -> "notes.md -> Refunds"
95
+ ```
96
+
97
+ ## Loading documents
98
+
99
+ | On-ramp | For |
100
+ | --- | --- |
101
+ | `Document.from_text(text)` | text you already have |
102
+ | `Document.from_chunks([...])` | content you already chunked |
103
+ | `Document.from_file("x.pdf")` | a file — PDF, DOCX, PPTX, XLSX, Markdown, or text/code |
104
+ | `Document.from_bytes(data, source="x.pdf")` | bytes you fetched (S3 / GCS / HTTP / DB) |
105
+ | `Document.from_folder("./docs", persist=True)` | a whole directory, with an optional incremental on-disk index |
106
+
107
+ ## Retrieval tiers — no vector database
108
+
109
+ A ladder; start cheap, climb only when a query needs it. All in-process, no ANN, no
110
+ index server.
111
+
112
+ ```python
113
+ doc = redhop.Document.from_text(text, retrieval="lexical") # BM25 (default)
114
+ doc = redhop.Document.from_text(text, retrieval="hybrid", model="bge-small") # BM25 -> dense rerank
115
+ doc = redhop.Document.from_text(text, retrieval="semantic", model="bge-small") # exact cosine over all chunks
116
+ ```
117
+
118
+ Add `rerank="cross-encoder"` on any tier for a precise (slower) second stage.
119
+
120
+ ## Assembly strategies
121
+
122
+ | `strategy=` | What it does |
123
+ | --- | --- |
124
+ | `reasoning_preserving` *(default)* | keep query-relevant seeds **and** rescue low-relevance chunks linked to one; drop only unlinked junk |
125
+ | `distractor_filtered` | drop everything below a query-grounding bar |
126
+ | `max_density` | greedily pack the densest chunks into the budget |
127
+ | `raw_topk` | keep retrieval order until the budget fills |
128
+ | `auto` | size-gated: pass small contexts through, prune large/diluted ones |
129
+
130
+ Already have chunks from your own retriever? Use `redhop.build_context(query,
131
+ retrieved_chunks=chunks, ...)` for the low-level surface.
132
+
133
+ ## Documentation
134
+
135
+ Full docs, the comparison vs LangChain / LlamaIndex, and the evidence behind every
136
+ default: **https://redhop.dev**
137
+
138
+ Apache-2.0. Also available for **Node.js** (`npm install redhop`) and **Rust**
139
+ (`cargo add redhop`).
140
+
redhop-0.1.2/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # RedHop
2
+
3
+ **A reasoning-aware context runtime for RAG.**
4
+
5
+ Hand it a document and a question. RedHop chunks, retrieves, and allocates the
6
+ context your model should actually see — then tells you what it kept, what it dropped,
7
+ and why, with citations back to the source. No vector database, no LLM, all in-process.
8
+
9
+ ```python
10
+ import redhop
11
+
12
+ doc = redhop.Document.from_file("contract.pdf")
13
+ ctx = doc.context("What is the governing law?")
14
+
15
+ answer = llm.generate(ctx.text()) # any LLM provider — no lock-in
16
+ ```
17
+
18
+ ```bash
19
+ pip install redhop
20
+ ```
21
+
22
+ One self-contained wheel — no Python dependencies. The default lexical tier needs no
23
+ model at all; the semantic/rerank tiers download a small model on first use (cached).
24
+
25
+ ## The idea
26
+
27
+ **Retrieval quality is not the same as reasoning quality.** Transformers tolerate
28
+ irrelevant context far better than they tolerate *missing reasoning links* — so the
29
+ chunk a multi-hop answer depends on is often low-relevance to the query and gets
30
+ silently pruned. RedHop's default keeps it, and makes the trade-off visible. It is
31
+ **not** a retriever, vector database, agent framework, or workflow engine — it does one
32
+ thing: turn a document and a query into the right prompt context, and explain the
33
+ decision.
34
+
35
+ ## It explains every decision
36
+
37
+ Every call returns a **Decision Report** — what it kept, what it dropped, and *why*,
38
+ including when it deliberately leaves a small context untouched.
39
+
40
+ ```python
41
+ print(ctx.report)
42
+ ```
43
+
44
+ ```text
45
+ RedHop Decision Report
46
+ ══════════════════════
47
+
48
+ Decision: Auto → pruning (intervened on a diluted context)
49
+
50
+ Why:
51
+ - large/diluted contexts dilute attention; pruning recovers signal density
52
+ Result:
53
+ - removed distractor chunks, kept all query-relevant evidence
54
+ - preserved a second-hop link a plain relevance filter would drop
55
+
56
+ Diagnostics
57
+ ───────────
58
+ Chunks: 24 → 3
59
+ Second-hop rescues: 1
60
+ ```
61
+
62
+ Read the fields directly via `ctx.report.auto_decision`, `total_tokens`,
63
+ `retained_evidence_ratio`, or call `doc.analyze(query)` for the report **without**
64
+ assembling a context.
65
+
66
+ ## Cite the evidence
67
+
68
+ Every selected chunk remembers where it came from:
69
+
70
+ ```python
71
+ for c in ctx.citations:
72
+ print(c["source"], c["page"], c["heading"])
73
+ # contract.pdf 3 None -> "contract.pdf, p.3"
74
+ # notes.md None "Refunds" -> "notes.md -> Refunds"
75
+ ```
76
+
77
+ ## Loading documents
78
+
79
+ | On-ramp | For |
80
+ | --- | --- |
81
+ | `Document.from_text(text)` | text you already have |
82
+ | `Document.from_chunks([...])` | content you already chunked |
83
+ | `Document.from_file("x.pdf")` | a file — PDF, DOCX, PPTX, XLSX, Markdown, or text/code |
84
+ | `Document.from_bytes(data, source="x.pdf")` | bytes you fetched (S3 / GCS / HTTP / DB) |
85
+ | `Document.from_folder("./docs", persist=True)` | a whole directory, with an optional incremental on-disk index |
86
+
87
+ ## Retrieval tiers — no vector database
88
+
89
+ A ladder; start cheap, climb only when a query needs it. All in-process, no ANN, no
90
+ index server.
91
+
92
+ ```python
93
+ doc = redhop.Document.from_text(text, retrieval="lexical") # BM25 (default)
94
+ doc = redhop.Document.from_text(text, retrieval="hybrid", model="bge-small") # BM25 -> dense rerank
95
+ doc = redhop.Document.from_text(text, retrieval="semantic", model="bge-small") # exact cosine over all chunks
96
+ ```
97
+
98
+ Add `rerank="cross-encoder"` on any tier for a precise (slower) second stage.
99
+
100
+ ## Assembly strategies
101
+
102
+ | `strategy=` | What it does |
103
+ | --- | --- |
104
+ | `reasoning_preserving` *(default)* | keep query-relevant seeds **and** rescue low-relevance chunks linked to one; drop only unlinked junk |
105
+ | `distractor_filtered` | drop everything below a query-grounding bar |
106
+ | `max_density` | greedily pack the densest chunks into the budget |
107
+ | `raw_topk` | keep retrieval order until the budget fills |
108
+ | `auto` | size-gated: pass small contexts through, prune large/diluted ones |
109
+
110
+ Already have chunks from your own retriever? Use `redhop.build_context(query,
111
+ retrieved_chunks=chunks, ...)` for the low-level surface.
112
+
113
+ ## Documentation
114
+
115
+ Full docs, the comparison vs LangChain / LlamaIndex, and the evidence behind every
116
+ default: **https://redhop.dev**
117
+
118
+ Apache-2.0. Also available for **Node.js** (`npm install redhop`) and **Rust**
119
+ (`cargo add redhop`).
@@ -0,0 +1,72 @@
1
+ [package]
2
+ name = "redhop"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ rust-version.workspace = true
6
+ license.workspace = true
7
+ authors.workspace = true
8
+ repository.workspace = true
9
+ homepage.workspace = true
10
+ keywords.workspace = true
11
+ categories.workspace = true
12
+ description = "Reasoning-aware context runtime for RAG — chunk, retrieve, and allocate the document context an LLM should see, with citations and a Decision Report. No vector DB, in-process."
13
+ # Shipped to crates.io so the package page isn't blank. Relative path from the
14
+ # crate; cargo bundles the file into the published tarball.
15
+ readme = "README.md"
16
+
17
+ [lib]
18
+ path = "src/lib.rs"
19
+
20
+ [features]
21
+ default = []
22
+ # Built-in document parsers (PDF/DOCX/PPTX/XLSX + text/code/markdown) and the
23
+ # `read_file` / `read_bytes` / `read_folder` loaders.
24
+ files = [
25
+ "dep:docx-rs",
26
+ "dep:calamine",
27
+ "dep:zip",
28
+ "dep:quick-xml",
29
+ "dep:pdf-extract",
30
+ "dep:ignore",
31
+ ]
32
+ # Semantic retrieval tier: bundled ONNX embedder + model registry, plus the
33
+ # cross-encoder reranker. Shares one ONNX runtime / one tokenizers dep.
34
+ semantic = ["dep:ort", "dep:tokenizers", "dep:hf-hub"]
35
+
36
+ [dependencies]
37
+ # ── always-on (the lexical-only build pulls only these) ──
38
+ serde = { workspace = true }
39
+ serde_json = { workspace = true }
40
+ thiserror = { workspace = true }
41
+ tracing = { workspace = true }
42
+ unicode-segmentation = { workspace = true }
43
+ regex = { workspace = true }
44
+ rayon = { workspace = true }
45
+ tantivy = { workspace = true }
46
+ tokio = { workspace = true }
47
+ futures = { workspace = true }
48
+ async-trait = "0.1"
49
+ parking_lot = "0.12"
50
+ rust-stemmers = "1.2"
51
+ lru = "0.12"
52
+
53
+ # ── `files` feature (document parsers) ──
54
+ docx-rs = { version = "0.4", optional = true }
55
+ calamine = { version = "0.32", optional = true }
56
+ zip = { version = "2", default-features = false, features = ["deflate"], optional = true }
57
+ quick-xml = { version = "0.37", optional = true }
58
+ pdf-extract = { version = "0.7", optional = true }
59
+ ignore = { version = "0.4", optional = true }
60
+
61
+ # ── `semantic` feature (ONNX embedder + cross-encoder reranker) ──
62
+ # `ort` is pinned exactly: the 2.x release-candidate line churns transitive
63
+ # (ndarray) constraints between RCs. We avoid the ndarray feature entirely
64
+ # and construct tensors from plain (shape, Vec) pairs to keep deps minimal.
65
+ ort = { version = "=2.0.0-rc.10", optional = true, default-features = false, features = ["std", "download-binaries"] }
66
+ tokenizers = { version = "0.20", optional = true, default-features = false, features = ["onig"] }
67
+ # Auto-downloads curated ONNX models by name. Sync `ureq` + `rustls-tls`
68
+ # (no OpenSSL) for clean Linux/Windows/macOS builds.
69
+ hf-hub = { version = "0.5", optional = true, default-features = false, features = ["ureq", "rustls-tls"] }
70
+
71
+ [lints]
72
+ workspace = true