1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
"""Type stubs for the compiled `rustai._rustai` extension."""
:
=
=
"""Base class for every rustai error."""
"""The request failed at the transport level."""
"""The server answered with a failure status."""
"""robots.txt disallows this URL."""
"""The document could not be parsed."""
"""A search provider failed."""
"""The headless fallback was unavailable."""
"""Document metadata read from `<head>`."""
"""Best available title."""
...
"""Meta or Open Graph description."""
...
"""Declared author."""
...
"""Publication timestamp, verbatim from the page."""
...
"""BCP-47 language tag."""
...
"""Canonical URL."""
...
"""Site name."""
...
"""Everything above, as a dict."""
...
"""One block of an extracted document."""
"""`"heading"`, `"paragraph"`, `"list_item"`, `"code"`, `"quote"` or `"table"`."""
...
"""Heading level, or list nesting depth."""
...
"""Plain text."""
...
"""Rendered Markdown."""
...
"""Enclosing headings, outermost first."""
...
"""Index in document order."""
...
"""Estimated tokens."""
...
"""Everything above, as a dict."""
...
"""What the denoiser removed."""
"""Nodes considered."""
...
"""Nodes rejected as boilerplate."""
...
"""Bytes of HTML in."""
...
"""Bytes of Markdown out."""
...
"""Size reduction in `[0, 1]`."""
...
"""Everything above, as a dict."""
...
"""One link harvested from a listing page."""
"""Anchor text."""
...
"""Absolute URL."""
...
"""Nearby descriptive text, if the page offered any."""
...
"""Enclosing section headings, outermost first."""
...
"""Everything above, as a dict."""
...
"""A cleaned document."""
"""Source URL."""
...
"""`"article"` for prose, `"index"` for a listing page."""
...
"""Links harvested from a listing page."""
...
"""Title, falling back to the first heading."""
...
"""The whole cleaned document as Markdown."""
...
"""The whole cleaned document as plain text."""
...
"""Metadata from `<head>`."""
...
"""Rankable blocks."""
...
"""Denoiser statistics."""
...
"""Estimated tokens for the whole article."""
...
"""The article as nested dicts."""
...
"""Return len(self)."""
...
"""A raw HTTP response."""
"""URL as requested."""
...
"""URL after redirects."""
...
"""HTTP status code."""
...
"""`Content-Type` header."""
...
"""Decoded response body."""
...
"""Wall time in milliseconds."""
...
"""Whether headless Chrome produced this body."""
...
"""Extract this page without fetching it again."""
...
"""Everything above, as a dict."""
...
"""One search hit."""
"""Result title."""
...
"""Absolute URL."""
...
"""Provider snippet."""
...
"""Providers that returned this URL."""
...
"""Fused rank-fusion score."""
...
"""Best position this URL reached at any *single* provider, zero-based.
Not this result's position in the fused list — for that, enumerate the
list you were handed. A result ranked first by two providers and a
result ranked first by one both report `0`; what separates them is
`score`, which is what the list is sorted by.
"""
...
"""Everything above, as a dict."""
...
"""A compressed context window."""
"""The query it was built for."""
...
"""Ready-to-prompt Markdown."""
...
"""Estimated tokens."""
...
"""Sources that contributed, as dicts."""
...
"""Why each unit was chosen, as dicts.
Keys: `source` and `unit`, which are indices rather than text --
`articles[source].units[unit]` is the block itself -- plus `tokens`
and the three scores behind the decision: `relevance` (BM25 against
the query), `density` (nouns and numbers over filler) and the combined
`score`. Enough to answer "why is this in my context window and that
paragraph is not".
"""
...
"""Units available before selection."""
...
"""Everything above, as a dict."""
...
"""Return str(self)."""
...
"""The result of a full research run."""
"""The query as asked."""
...
"""The compressed context."""
...
"""Ready-to-prompt Markdown, straight from the context."""
...
"""Search hits, best first."""
...
"""Articles that were successfully read."""
...
"""`(stage, message)` pairs for non-fatal failures."""
...
"""Everything above, as a dict."""
...
"""Return str(self)."""
...
"""A reusable pipeline: connection pool, providers, extractor and slimmer.
Build one and keep it: the connection pool, the robots cache and the
per-host delays all live on the client, so a second call to a host you
have already visited is cheaper.
`providers` accepts `"duckduckgo"`, `"wikipedia"` or `"wikipedia:ko"`,
`"searxng:https://…"`, `"rss:https://…"` and `"sitemap:https://…"`.
`limit` caps how many search hits are kept -- the same quantity
`research()` calls `max_sources`.
`max_tokens_per_source` caps how much any one page may contribute to the
context. Leaving it `None` is right for most questions: measured over six
queries at budgets of 1,000, 2,048 and 4,096 tokens, capping either
changed nothing or bought source coverage by admitting less relevant text,
and coverage rises on its own as the budget grows. Reach for it when a
question needs corroboration rather than depth -- two of those six queries
had a single long page take 86% and 90% of the window, in one case
starving the encyclopedia article on the exact term asked about.
"""
"""Initialize self. See help(type(self)) for accurate signature."""
...
"""Search every configured provider and return fused results.
Provider failures are not raised: a partial result set is more useful
than an exception when one of five providers is having a bad day. Pass
`strict=True` to raise when *every* provider failed.
"""
...
"""Fetch URLs concurrently.
**The result is not 1:1 with the input.** With `raise_on_error=False`
(the default) a failed URL is simply absent, so one dead link cannot
lose you the other nineteen — but neither can you tell which one went,
and indexing the result against the input you passed will be wrong.
Match on `Page.url` instead, or pass `raise_on_error=True` when a
missing page is a problem rather than a nuisance.
This differs deliberately from `extract_many`, which is 1:1 and raises:
there, an input is a document you already hold, and losing one silently
would be a bug in your own pipeline. Here an input is somebody else's
server, and it is allowed to be down.
"""
...
"""Fetch and extract in one step.
**The result is not 1:1 with the input** — see `fetch`. Match on
`Article.url` rather than by position, or pass `raise_on_error=True`.
"""
...
"""Search, read the top results, and compress them into a context window."""
...
"""Write the cookie jar to the `cookie_file` this client was built with.
Returns how many cookies were saved, or 0 when no file was configured.
Clearance cookies are the expensive part of getting through a bot wall;
saving them means not paying for them again next run.
"""
...
"""Denoise a raw HTML string into Markdown. No network access."""
...
"""Denoise many HTML strings at once, in parallel across the rayon pool.
This is the batch form of [`extract`]. Parsing is CPU-bound and per-document
independent, so a list of 20 documents costs roughly one document's wall
time on a multi-core machine — and because the GIL is released for the whole
call, it parallelises whether or not the caller uses threads.
`urls` is optional; when given it must be the same length as `documents`.
Output is 1:1 with the input, so a failed document raises rather than
silently shifting every later index.
"""
...
"""Rank and compress already-extracted articles into a context window."""
...
"""Search, read and compress in one call, using a throwaway client.
`max_tokens_per_source` caps how much any one page may contribute; see
`Client` for when that is worth doing.
"""
...
"""Estimate how many LLM tokens a string costs."""
...
"""Split text into the tokens the ranker uses."""
...
"""Score a block of text for information density, `0.0`–`1.0`."""
...
"""Normalise a URL to the identity used for deduplication."""
...
"""Parse an RSS or Atom feed into a list of dicts."""
...
"""Parse a sitemap into `{"urls": [...], "sitemaps": [...]}`."""
...