Commit 17b892e
committed
feat(retain): expose processed_content_tokens on RetainResult
Delta retain already knows, at chunk-level granularity, which content
was new vs unchanged on an upsert to an existing document_id. Surface
that signal to post-retain hooks so extensions can reason about "how
much content actually went through the extraction pipeline" without
re-implementing the dedup logic.
New field `RetainResult.processed_content_tokens: int | None`:
* None — the retain went through the full (non-delta) path or has
no dedup signal. Consumers should treat this as "the full
submitted payload was processed."
* 0 — the submission matched prior content exactly; no chunks
went through extraction (metadata-only update).
* N>0 — only N tokens of content+context were actually re-extracted.
The remainder matched existing chunks by content_hash and
was skipped.
Populated in three places:
* Streaming / full retain path → None
* `_try_delta_retain` no-changes fallthrough (`_delta_metadata_only`)
→ 0
* `_try_delta_retain` partial-delta success → sum of
count_tokens(content) + count_tokens(context) across the chunks
built for extraction (delta_contents)
Sub-batch aggregation propagates None if any sub-batch bypassed dedup,
so callers never accidentally undercount when only part of a large
batch was eligible for delta processing.
Tests exercise the full path, unchanged-resubmit, appended-content,
and no-document-id cases plus a unit check on the aggregation helper.1 parent 45f47a9 commit 17b892e
5 files changed
Lines changed: 349 additions & 33 deletions
File tree
- hindsight-api-slim
- hindsight_api
- engine
- retain
- extensions
- tests
- hindsight-dev/benchmarks/perf
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2267 | 2267 | | |
2268 | 2268 | | |
2269 | 2269 | | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
2270 | 2275 | | |
2271 | 2276 | | |
2272 | 2277 | | |
| |||
2318 | 2323 | | |
2319 | 2324 | | |
2320 | 2325 | | |
2321 | | - | |
| 2326 | + | |
2322 | 2327 | | |
2323 | 2328 | | |
2324 | 2329 | | |
| |||
2334 | 2339 | | |
2335 | 2340 | | |
2336 | 2341 | | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2337 | 2346 | | |
2338 | 2347 | | |
2339 | 2348 | | |
| |||
2342 | 2351 | | |
2343 | 2352 | | |
2344 | 2353 | | |
2345 | | - | |
| 2354 | + | |
2346 | 2355 | | |
2347 | 2356 | | |
2348 | 2357 | | |
| |||
2371 | 2380 | | |
2372 | 2381 | | |
2373 | 2382 | | |
| 2383 | + | |
2374 | 2384 | | |
2375 | 2385 | | |
2376 | 2386 | | |
| |||
2403 | 2413 | | |
2404 | 2414 | | |
2405 | 2415 | | |
2406 | | - | |
| 2416 | + | |
2407 | 2417 | | |
2408 | 2418 | | |
2409 | 2419 | | |
| |||
2422 | 2432 | | |
2423 | 2433 | | |
2424 | 2434 | | |
2425 | | - | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
2426 | 2438 | | |
2427 | 2439 | | |
2428 | 2440 | | |
| |||
Lines changed: 64 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 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 | + | |
28 | 54 | | |
29 | 55 | | |
30 | 56 | | |
| |||
417 | 443 | | |
418 | 444 | | |
419 | 445 | | |
420 | | - | |
| 446 | + | |
421 | 447 | | |
422 | 448 | | |
423 | 449 | | |
424 | 450 | | |
425 | 451 | | |
426 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
427 | 461 | | |
428 | 462 | | |
429 | 463 | | |
| |||
463 | 497 | | |
464 | 498 | | |
465 | 499 | | |
| 500 | + | |
466 | 501 | | |
467 | | - | |
| 502 | + | |
468 | 503 | | |
469 | 504 | | |
470 | 505 | | |
| |||
486 | 521 | | |
487 | 522 | | |
488 | 523 | | |
489 | | - | |
| 524 | + | |
| 525 | + | |
490 | 526 | | |
491 | 527 | | |
492 | 528 | | |
| |||
595 | 631 | | |
596 | 632 | | |
597 | 633 | | |
598 | | - | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
599 | 637 | | |
600 | 638 | | |
601 | 639 | | |
| |||
1388 | 1426 | | |
1389 | 1427 | | |
1390 | 1428 | | |
1391 | | - | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1392 | 1433 | | |
1393 | 1434 | | |
1394 | 1435 | | |
| |||
1416 | 1457 | | |
1417 | 1458 | | |
1418 | 1459 | | |
1419 | | - | |
| 1460 | + | |
1420 | 1461 | | |
1421 | 1462 | | |
1422 | 1463 | | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
1423 | 1469 | | |
1424 | 1470 | | |
1425 | 1471 | | |
| |||
1678 | 1724 | | |
1679 | 1725 | | |
1680 | 1726 | | |
1681 | | - | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
1682 | 1733 | | |
1683 | 1734 | | |
1684 | 1735 | | |
| |||
1718 | 1769 | | |
1719 | 1770 | | |
1720 | 1771 | | |
1721 | | - | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
1722 | 1777 | | |
1723 | 1778 | | |
1724 | 1779 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
179 | 195 | | |
180 | 196 | | |
181 | 197 | | |
| |||
0 commit comments