r3trace 0.6.51__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.
- r3trace-0.6.51/LICENSE +22 -0
- r3trace-0.6.51/PKG-INFO +402 -0
- r3trace-0.6.51/README.md +357 -0
- r3trace-0.6.51/THIRD-PARTY-NOTICES +222 -0
- r3trace-0.6.51/pyproject.toml +145 -0
- r3trace-0.6.51/pyproject.toml.orig +169 -0
- r3trace-0.6.51/src/r3trace/__init__.py +115 -0
- r3trace-0.6.51/src/r3trace/__main__.py +22 -0
- r3trace-0.6.51/src/r3trace/app/__init__.py +8 -0
- r3trace-0.6.51/src/r3trace/app/app.css +736 -0
- r3trace-0.6.51/src/r3trace/app/app.js +8612 -0
- r3trace-0.6.51/src/r3trace/app/index.html +155 -0
- r3trace-0.6.51/src/r3trace/app/server.py +1526 -0
- r3trace-0.6.51/src/r3trace/app/updates.py +69 -0
- r3trace-0.6.51/src/r3trace/app/window.py +304 -0
- r3trace-0.6.51/src/r3trace/cli.py +489 -0
- r3trace-0.6.51/src/r3trace/config.py +390 -0
- r3trace-0.6.51/src/r3trace/configs/default.yaml +42 -0
- r3trace-0.6.51/src/r3trace/documents.py +727 -0
- r3trace-0.6.51/src/r3trace/logging_setup.py +94 -0
- r3trace-0.6.51/src/r3trace/masking.py +295 -0
- r3trace-0.6.51/src/r3trace/parallel.py +40 -0
- r3trace-0.6.51/src/r3trace/pipeline.py +2193 -0
- r3trace-0.6.51/src/r3trace/prompts/claims/v1.yaml +46 -0
- r3trace-0.6.51/src/r3trace/prompts/claims/v2.yaml +46 -0
- r3trace-0.6.51/src/r3trace/prompts/claims/v3.yaml +46 -0
- r3trace-0.6.51/src/r3trace/prompts/linking/v1.yaml +6 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/coding/v1.yaml +178 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/coding/v2.yaml +183 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/coding/v3.yaml +185 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/coding/v4.yaml +185 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/direct/v1.yaml +153 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/direct/v2.yaml +160 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/direct/v3.yaml +162 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/direct/v4.yaml +162 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/direct/v5.yaml +162 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/v1.yaml +176 -0
- r3trace-0.6.51/src/r3trace/prompts/reasoning/v2.yaml +178 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/first-round/v1.yaml +38 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/first-round/v2.yaml +41 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/first-round/v3.yaml +51 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/later-rounds/v1.yaml +71 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/later-rounds/v2.yaml +71 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/later-rounds/v3.yaml +72 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/later-rounds/v4.yaml +87 -0
- r3trace-0.6.51/src/r3trace/prompts/relevance/v1.yaml +44 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/parsing/v1.yaml +88 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/parsing/v2.yaml +149 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/parsing/v3.yaml +149 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/parsing/v4.yaml +148 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/schema/v1.yaml +121 -0
- r3trace-0.6.51/src/r3trace/prompts/structuring/schema/v2.yaml +119 -0
- r3trace-0.6.51/src/r3trace/prompts.py +130 -0
- r3trace-0.6.51/src/r3trace/provenance.py +408 -0
- r3trace-0.6.51/src/r3trace/py.typed +0 -0
- r3trace-0.6.51/src/r3trace/quotes.py +258 -0
- r3trace-0.6.51/src/r3trace/r3trace.py +495 -0
- r3trace-0.6.51/src/r3trace/runs.py +824 -0
- r3trace-0.6.51/src/r3trace/runtime/__init__.py +7 -0
- r3trace-0.6.51/src/r3trace/runtime/codeact.py +605 -0
- r3trace-0.6.51/src/r3trace/runtime/llm.py +935 -0
- r3trace-0.6.51/src/r3trace/runtime/python_executor.py +1853 -0
- r3trace-0.6.51/src/r3trace/settings.py +171 -0
- r3trace-0.6.51/src/r3trace/splitting.py +522 -0
- r3trace-0.6.51/src/r3trace/stages/__init__.py +12 -0
- r3trace-0.6.51/src/r3trace/stages/citing.py +116 -0
- r3trace-0.6.51/src/r3trace/stages/claims.py +329 -0
- r3trace-0.6.51/src/r3trace/stages/reasoning.py +581 -0
- r3trace-0.6.51/src/r3trace/stages/relevance.py +669 -0
- r3trace-0.6.51/src/r3trace/stages/structuring/__init__.py +8 -0
- r3trace-0.6.51/src/r3trace/stages/structuring/parsing.py +621 -0
- r3trace-0.6.51/src/r3trace/stages/structuring/schema.py +250 -0
r3trace-0.6.51/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Theologitis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
r3trace-0.6.51/PKG-INFO
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: r3trace
|
|
3
|
+
Version: 0.6.51
|
|
4
|
+
Summary: Just-in-time reasoning over a collection of documents: surface relevance, structure it, reason over it.
|
|
5
|
+
Keywords: llm,agent,documents,reasoning,multi-document,question-answering
|
|
6
|
+
Author: Michael Theologitis
|
|
7
|
+
Author-email: Michael Theologitis <michael.theologitis@outlook.com>
|
|
8
|
+
License-Expression: MIT AND Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: THIRD-PARTY-NOTICES
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Text Processing
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: litellm>=1.103,<2
|
|
23
|
+
Requires-Dist: litellm>=1.109 ; python_full_version >= '3.15'
|
|
24
|
+
Requires-Dist: jinja2>=3.1.0
|
|
25
|
+
Requires-Dist: filelock>=3.16.1
|
|
26
|
+
Requires-Dist: pydantic>=2.14
|
|
27
|
+
Requires-Dist: pyyaml>=6.0
|
|
28
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
29
|
+
Requires-Dist: tenacity>=8.0
|
|
30
|
+
Requires-Dist: pypdf[cryptodome]>=6.19.0
|
|
31
|
+
Requires-Dist: mammoth>=1.12.2
|
|
32
|
+
Requires-Dist: markdownify>=1.0.0
|
|
33
|
+
Requires-Dist: beautifulsoup4>=4.11
|
|
34
|
+
Requires-Dist: rapidfuzz>=3.14.1
|
|
35
|
+
Requires-Dist: rapidfuzz>=3.14.6 ; python_full_version >= '3.15'
|
|
36
|
+
Requires-Dist: keyring>=25 ; extra == 'app'
|
|
37
|
+
Requires-Dist: platformdirs>=4.1 ; extra == 'app'
|
|
38
|
+
Requires-Dist: starlette>=1.10 ; extra == 'app'
|
|
39
|
+
Requires-Dist: uvicorn>=0.54 ; extra == 'app'
|
|
40
|
+
Requires-Python: >=3.11
|
|
41
|
+
Project-URL: Homepage, https://github.com/michaeltheologitis/r3trace
|
|
42
|
+
Project-URL: Repository, https://github.com/michaeltheologitis/r3trace
|
|
43
|
+
Provides-Extra: app
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# R3Trace
|
|
48
|
+
|
|
49
|
+
[](https://arxiv.org/abs/2609.27173)
|
|
50
|
+

|
|
51
|
+
[](https://github.com/michaeltheologitis/r3trace/blob/main/LICENSE)
|
|
52
|
+
|
|
53
|
+
**Context representation for large-scale reasoning with smaller, cheaper models.**
|
|
54
|
+
|
|
55
|
+
Ask a question whose evidence is spread across many documents. R3Trace finds and
|
|
56
|
+
organizes the relevant information, then reasons over it to produce an answer.
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
## App
|
|
61
|
+
|
|
62
|
+
### Mac (Apple silicon)
|
|
63
|
+
|
|
64
|
+
#### Direct
|
|
65
|
+
|
|
66
|
+
[Download R3Trace](https://github.com/michaeltheologitis/r3trace/releases/latest/download/R3Trace.dmg), double-click it, and drag R3Trace to Applications.
|
|
67
|
+
|
|
68
|
+
<img src="https://raw.githubusercontent.com/michaeltheologitis/r3trace/main/docs/install.png" width="480" alt="The R3Trace disk image window: drag R3Trace onto the Applications folder">
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
#### Brew
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
brew install michaeltheologitis/r3trace/r3trace
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Either way, R3Trace updates itself: **R3Trace → Check for Updates…**
|
|
78
|
+
|
|
79
|
+
### Any computer
|
|
80
|
+
|
|
81
|
+
First install uv:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Run R3Trace in your browser:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv tool install --python 3.15 "r3trace[app]"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
r3trace app
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Library
|
|
98
|
+
|
|
99
|
+
### Install
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pip install r3trace
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or `uv add r3trace`.
|
|
106
|
+
|
|
107
|
+
Set the API key(s) for the AI provider(s) you use:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
export OPENAI_API_KEY=sk-...
|
|
111
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
You can also put them in a `.env` file in your working directory.
|
|
115
|
+
|
|
116
|
+
### Command line
|
|
117
|
+
|
|
118
|
+
Ask a question about documents in a folder:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
r3trace run "Which supplier missed the most delivery windows?" ./reports \
|
|
122
|
+
--model openai/gpt-6-luna
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`./reports` is the folder containing your documents. `--model` selects the AI
|
|
126
|
+
model to use.
|
|
127
|
+
|
|
128
|
+
You can use any model supported by [LiteLLM](https://docs.litellm.ai/docs/providers),
|
|
129
|
+
for example:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
anthropic/claude-sonnet-5-5
|
|
133
|
+
gemini/gemini-3.8-flash
|
|
134
|
+
hosted_vllm/Qwen/Qwen3.5-35B-A3B
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The default is `openai/gpt-6-luna`.
|
|
138
|
+
|
|
139
|
+
You can read an entire folder, select files using glob patterns, or specify
|
|
140
|
+
individual files. A glob pattern uses `*` to match filenames and `**` to
|
|
141
|
+
include subfolders.
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# All supported files in reports and its subfolders
|
|
145
|
+
r3trace run "Who approved the Q3 overspend?" ./reports
|
|
146
|
+
|
|
147
|
+
# Only PDF files directly inside reports
|
|
148
|
+
r3trace run "Who approved the Q3 overspend?" "./reports/*.pdf"
|
|
149
|
+
|
|
150
|
+
# PDF files inside reports and its subfolders
|
|
151
|
+
r3trace run "Who approved the Q3 overspend?" "./reports/**/*.pdf"
|
|
152
|
+
|
|
153
|
+
# Only these three files
|
|
154
|
+
r3trace run "Who approved the Q3 overspend?" q1.md q2.md q3.md
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Keep glob patterns in quotes, as shown above. When reading a folder or using
|
|
158
|
+
a glob pattern, R3Trace skips links to files outside the selected folder.
|
|
159
|
+
Individual files can be specified directly.
|
|
160
|
+
|
|
161
|
+
Add `--evidence-level document` to skip quoting sentences: the answer's
|
|
162
|
+
provenance then lists only its documents.
|
|
163
|
+
|
|
164
|
+
#### Carry On a Stopped Run
|
|
165
|
+
|
|
166
|
+
If a run fails or you stop it partway, it prints the command that carries it on:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
r3trace resume logs/20261105T173546Z_bb4f0c37 ./reports
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Give it the same sources the run read, in the same order. It reuses what the run
|
|
173
|
+
finished and only does the rest.
|
|
174
|
+
|
|
175
|
+
### Python
|
|
176
|
+
|
|
177
|
+
Load documents from a folder, glob pattern, or list of files:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from r3trace import r3trace
|
|
181
|
+
|
|
182
|
+
docs = r3trace.read_documents("./reports")
|
|
183
|
+
result = r3trace.run(
|
|
184
|
+
"Which supplier missed the most delivery windows?",
|
|
185
|
+
docs,
|
|
186
|
+
)
|
|
187
|
+
print(result) # "Ardent Logistics missed the most delivery windows: 8 in total."
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`read_documents` supports PDF, Word (`.docx`), `.txt`, `.md`, `.csv`, `.json`,
|
|
191
|
+
`.html`, `.htm`, and `.xml` files; Word files and web pages are read as Markdown, a
|
|
192
|
+
web page under the title, author, dates and address its metadata gives. It skips
|
|
193
|
+
hidden files and folders when reading directories or using glob patterns.
|
|
194
|
+
|
|
195
|
+
It returns each document's text along with its filename. If a file is inside
|
|
196
|
+
a subfolder, its name includes that subfolder. For example, a file at `reports/q3/ardent.pdf` is named `q3/ardent.pdf`.
|
|
197
|
+
Here, `q3` is simply the subfolder name, and `ardent.pdf` is the filename.
|
|
198
|
+
|
|
199
|
+
If your documents are already stored as text in Python, pass them directly
|
|
200
|
+
without reading files:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
result = r3trace.run(
|
|
204
|
+
"Which supplier missed the most delivery windows?",
|
|
205
|
+
[doc_a, doc_b, doc_c],
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
You can provide documents as a list:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
documents = [doc_a, doc_b, doc_c]
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Or give them names:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
documents = {
|
|
219
|
+
"report_a": doc_a,
|
|
220
|
+
"report_b": doc_b,
|
|
221
|
+
"report_c": doc_c,
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
To skip quoting, run at the document level:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
result = r3trace.run(
|
|
229
|
+
"Which supplier missed the most delivery windows?",
|
|
230
|
+
docs,
|
|
231
|
+
evidence_level="document",
|
|
232
|
+
)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
R3Trace then doesn't ask the model for quotes, so the provenance lists only
|
|
236
|
+
documents (`result.provenance["relevant_trail"]["documents"]`), not their
|
|
237
|
+
sentences.
|
|
238
|
+
|
|
239
|
+
#### Re-use Representation
|
|
240
|
+
|
|
241
|
+
To ask another question without repeating the earlier processing, use
|
|
242
|
+
`r3trace.ask`:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
other = r3trace.ask(result, "Which supplier delivered on time most often?")
|
|
246
|
+
print(other)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
This reuses the information organized during the first run and only
|
|
250
|
+
repeats the final reasoning step.
|
|
251
|
+
|
|
252
|
+
#### Resume a Run
|
|
253
|
+
|
|
254
|
+
If a run fails or is stopped partway, for example by a rate limit or a lost
|
|
255
|
+
connection, `r3trace.resume` carries it on from where it was, in the same folder.
|
|
256
|
+
Give it the run's folder (the error names it) and the same documents:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
result = r3trace.resume("logs/20261105T173546Z_bb4f0c37", docs)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
It checks that the documents are the run's, reuses each result the run had
|
|
263
|
+
saved, document by document, and computes only what is missing, then the final
|
|
264
|
+
reasoning step.
|
|
265
|
+
|
|
266
|
+
#### Provenance
|
|
267
|
+
|
|
268
|
+
`result.provenance` has three parts: the relevant trail, the claims, and the
|
|
269
|
+
evidence trail.
|
|
270
|
+
|
|
271
|
+
`result.provenance["relevant_trail"]` is the answer's citations traced back.
|
|
272
|
+
`cited` holds what the answer cites: the IDs of relevance summaries
|
|
273
|
+
(`summary_ids`) and of documents whose parsed records it used (`parse_ids`).
|
|
274
|
+
`documents` lists the documents behind those summaries, directly or through the
|
|
275
|
+
parsed records it cites, each with its `document` ID and `name`.
|
|
276
|
+
|
|
277
|
+
Its `quotes` list the sentences the answer is based on. Each has the
|
|
278
|
+
document's `name`, `text` as the AI model quoted it, and
|
|
279
|
+
`document_text`, the document's own words, from its `start` to its `end`
|
|
280
|
+
character in that document. The two differ when the model changed the
|
|
281
|
+
wording. `match` says how the sentence was found: `exact`, `normalized`
|
|
282
|
+
(only spacing, case, quotation marks, dashes or markup differ), `elided` (the
|
|
283
|
+
model wrote `...` for words it left out) or `fuzzy` (some words differ), and a
|
|
284
|
+
`fuzzy` one has a `score` out of 100:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
quote = result.provenance["relevant_trail"]["quotes"][0]
|
|
288
|
+
print(quote["name"], quote["match"], quote["score"]) # q3/ardent.pdf fuzzy 94.1
|
|
289
|
+
print(quote["text"]) # Ardent missed 8 delivery windows, mainly in August.
|
|
290
|
+
print(quote["document_text"]) # Ardent missed 8 delivery windows, mostly in August.
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
With `evidence_level="document"`, `quotes` is empty.
|
|
294
|
+
|
|
295
|
+
`result.provenance["claims"]` splits the answer into its claims (each
|
|
296
|
+
sentence, clause, list item or table row), then links each one to the quotes
|
|
297
|
+
that directly support it. Each claim has its `text`, from its `start` to its
|
|
298
|
+
`end` character in `result.answer`, the `documents` behind it by ID, and the
|
|
299
|
+
`quotes` behind it, each by its `document`, `start` and `end`, as in the
|
|
300
|
+
relevant trail's `quotes`:
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
for claim in result.provenance["claims"]:
|
|
304
|
+
print(claim["text"], claim["documents"])
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Finding the claims takes one more call to the AI model, after the answer, and
|
|
308
|
+
linking them one call per claim, made in parallel. With
|
|
309
|
+
`evidence_level="document"`, the one call does both, and a claim lists only its
|
|
310
|
+
documents. To skip these calls, pass `claims=False`.
|
|
311
|
+
|
|
312
|
+
`result.provenance["evidence_trail"]` is the part of the relevant trail the
|
|
313
|
+
claims rest on: the `documents` and `quotes` they cite, in the same form. When
|
|
314
|
+
no claim cites anything, for example with `claims=False`, it is the whole
|
|
315
|
+
relevant trail. Its `from` says which: `"claims"` or `"trail"`.
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
evidence = result.provenance["evidence_trail"]
|
|
319
|
+
print(evidence["from"], [document["name"] for document in evidence["documents"]])
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
[`examples/provenance.ipynb`](https://github.com/michaeltheologitis/r3trace/blob/main/examples/provenance.ipynb)
|
|
323
|
+
shows the rest of the provenance.
|
|
324
|
+
|
|
325
|
+
## Notebooks
|
|
326
|
+
|
|
327
|
+
The examples use five short memos, with the information spread across them
|
|
328
|
+
so no single document contains the complete answer:
|
|
329
|
+
|
|
330
|
+
- [`examples/quickstart.ipynb`](https://github.com/michaeltheologitis/r3trace/blob/main/examples/quickstart.ipynb) — a complete example of using R3Trace.
|
|
331
|
+
- [`examples/provenance.ipynb`](https://github.com/michaeltheologitis/r3trace/blob/main/examples/provenance.ipynb) — checking the original sentences, summaries, and records behind an answer.
|
|
332
|
+
- [`examples/options.ipynb`](https://github.com/michaeltheologitis/r3trace/blob/main/examples/options.ipynb) — configuring models, summary rounds, reasoning, generation settings, custom connections, and saved files.
|
|
333
|
+
- [`examples/vllm.ipynb`](https://github.com/michaeltheologitis/r3trace/blob/main/examples/vllm.ipynb) — using an AI model hosted on your own vLLM server.
|
|
334
|
+
|
|
335
|
+
## Output
|
|
336
|
+
|
|
337
|
+
`r3trace.run(...)` returns the answer and the information created during the run:
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
result.answer # Final answer
|
|
341
|
+
result.relevant_context # Relevant text found in the documents
|
|
342
|
+
result.structured_context # Information extracted and organized from the documents
|
|
343
|
+
result.provenance # What the answer is based on (see Provenance above)
|
|
344
|
+
result.run_dir # Folder where this run's files are saved
|
|
345
|
+
result.skipped # What the run skipped, and why
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
When the AI model's reply for one document stays unusable after its retries
|
|
349
|
+
(cut off at its output limit, not fitting the requested format, or empty),
|
|
350
|
+
the run skips that document's relevance note or parsed records and carries on
|
|
351
|
+
rather than failing. `result.skipped` lists each skip, `r3trace run` prints a
|
|
352
|
+
line about them after the answer, and the run folder's `skipped.json` has
|
|
353
|
+
the details.
|
|
354
|
+
|
|
355
|
+
## Run artifacts
|
|
356
|
+
|
|
357
|
+
Every run saves its results and processing records in a folder under `./logs`.
|
|
358
|
+
|
|
359
|
+
```text
|
|
360
|
+
logs/<timestamp>_<hex>/ <- result.run_dir
|
|
361
|
+
├── ids.json <- each document's ID
|
|
362
|
+
├── names.json <- each document's filename
|
|
363
|
+
├── documents.json <- each document's SHA-256 (UTF-8, lone surrogates passed through)
|
|
364
|
+
├── events.jsonl <- when each processing step started and finished
|
|
365
|
+
├── skipped.json <- notes and parses skipped, and why
|
|
366
|
+
├── splits.json <- how documents were split, if necessary
|
|
367
|
+
├── relevance/
|
|
368
|
+
│ ├── result.json <- relevant text and supporting quotes
|
|
369
|
+
│ └── calls.json <- AI requests made during relevance checking
|
|
370
|
+
├── structuring/
|
|
371
|
+
│ ├── schema/
|
|
372
|
+
│ │ ├── result.json <- structure created for organizing information
|
|
373
|
+
│ │ ├── calls.json <- AI requests
|
|
374
|
+
│ │ └── transcript.yaml <- record of the process
|
|
375
|
+
│ └── parsing/
|
|
376
|
+
│ ├── result.json <- information extracted from documents
|
|
377
|
+
│ └── calls.json <- AI requests
|
|
378
|
+
├── reasoning/
|
|
379
|
+
│ ├── result.json <- final answer
|
|
380
|
+
│ ├── calls.json <- AI requests
|
|
381
|
+
│ └── transcript.yaml <- record of the reasoning process
|
|
382
|
+
├── claims/
|
|
383
|
+
│ ├── result.json <- the answer's claims and its evidence trail
|
|
384
|
+
│ ├── calls.json <- AI requests
|
|
385
|
+
│ └── transcript.yaml <- record of the request
|
|
386
|
+
└── asks/<folder>/ <- saved results for each additional question
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Evaluation
|
|
390
|
+
|
|
391
|
+
For benchmark results, comparisons with other methods, and evaluation code,
|
|
392
|
+
see [r3con-evaluation](https://github.com/michaeltheologitis/r3con-evaluation).
|
|
393
|
+
|
|
394
|
+
## License
|
|
395
|
+
|
|
396
|
+
MIT — see [LICENSE](https://github.com/michaeltheologitis/r3trace/blob/main/LICENSE).
|
|
397
|
+
|
|
398
|
+
`src/r3trace/runtime/python_executor.py` includes modified code from
|
|
399
|
+
[smolagents](https://github.com/huggingface/smolagents), licensed under
|
|
400
|
+
Apache-2.0 and © HuggingFace Inc.
|
|
401
|
+
|
|
402
|
+
See [THIRD-PARTY-NOTICES](https://github.com/michaeltheologitis/r3trace/blob/main/THIRD-PARTY-NOTICES).
|