Commit e90cfa4
authored
fix(reflect): scope delta mental model recall to new memories only (#1192)
Delta mode mental model refresh was running a full recall across ALL
memories (identical to full mode), then passing all facts to a second
LLM call for delta ops. This caused content bloat, duplication, and
made delta strictly more expensive than full mode.
Changes:
- Add created_after/created_before time range filter to the recall
pipeline (retrieval.py, link_expansion_retrieval.py, graph_retrieval.py)
threaded through recall_async -> reflect_async -> tool closures
- Delta refresh passes last_refreshed_at as created_after so the
agentic loop only retrieves memories created/updated since the last
refresh (uses updated_at to catch consolidation updates)
- Short-circuit delta when no new facts found (skip LLM call, preserve
existing content)
- Accumulate based_on across delta refreshes (merge previous + new,
deduped by ID)
- Pass context to reflect agent during MM refresh with document name,
stay-on-topic guidance, and example preservation instructions
- Rewrite delta prompt: preserve existing content from prior refreshes,
merge overlapping topics, preserve concrete examples over abstract
rules
- Add recall time-range unit tests (8 tests)
- Add integration test verifying delta fusion quality1 parent 1078566 commit e90cfa4
9 files changed
Lines changed: 629 additions & 34 deletions
File tree
- hindsight-api-slim
- hindsight_api/engine
- reflect
- search
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2514 | 2514 | | |
2515 | 2515 | | |
2516 | 2516 | | |
| 2517 | + | |
| 2518 | + | |
2517 | 2519 | | |
2518 | 2520 | | |
2519 | 2521 | | |
| |||
2659 | 2661 | | |
2660 | 2662 | | |
2661 | 2663 | | |
| 2664 | + | |
| 2665 | + | |
2662 | 2666 | | |
2663 | 2667 | | |
2664 | 2668 | | |
| |||
2787 | 2791 | | |
2788 | 2792 | | |
2789 | 2793 | | |
| 2794 | + | |
| 2795 | + | |
2790 | 2796 | | |
2791 | 2797 | | |
2792 | 2798 | | |
| |||
2911 | 2917 | | |
2912 | 2918 | | |
2913 | 2919 | | |
| 2920 | + | |
| 2921 | + | |
2914 | 2922 | | |
2915 | 2923 | | |
2916 | 2924 | | |
| |||
5509 | 5517 | | |
5510 | 5518 | | |
5511 | 5519 | | |
| 5520 | + | |
| 5521 | + | |
5512 | 5522 | | |
5513 | 5523 | | |
5514 | 5524 | | |
| |||
5661 | 5671 | | |
5662 | 5672 | | |
5663 | 5673 | | |
| 5674 | + | |
| 5675 | + | |
5664 | 5676 | | |
5665 | 5677 | | |
5666 | 5678 | | |
| |||
5688 | 5700 | | |
5689 | 5701 | | |
5690 | 5702 | | |
| 5703 | + | |
| 5704 | + | |
5691 | 5705 | | |
5692 | 5706 | | |
5693 | 5707 | | |
| |||
7077 | 7091 | | |
7078 | 7092 | | |
7079 | 7093 | | |
| 7094 | + | |
| 7095 | + | |
| 7096 | + | |
| 7097 | + | |
| 7098 | + | |
| 7099 | + | |
| 7100 | + | |
| 7101 | + | |
| 7102 | + | |
| 7103 | + | |
| 7104 | + | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
7080 | 7110 | | |
7081 | 7111 | | |
7082 | 7112 | | |
| 7113 | + | |
7083 | 7114 | | |
7084 | 7115 | | |
7085 | 7116 | | |
| |||
7097 | 7128 | | |
7098 | 7129 | | |
7099 | 7130 | | |
| 7131 | + | |
| 7132 | + | |
| 7133 | + | |
| 7134 | + | |
| 7135 | + | |
| 7136 | + | |
| 7137 | + | |
| 7138 | + | |
| 7139 | + | |
| 7140 | + | |
| 7141 | + | |
7100 | 7142 | | |
7101 | 7143 | | |
7102 | 7144 | | |
| |||
7127 | 7169 | | |
7128 | 7170 | | |
7129 | 7171 | | |
| 7172 | + | |
| 7173 | + | |
| 7174 | + | |
| 7175 | + | |
| 7176 | + | |
| 7177 | + | |
| 7178 | + | |
| 7179 | + | |
| 7180 | + | |
| 7181 | + | |
| 7182 | + | |
| 7183 | + | |
| 7184 | + | |
| 7185 | + | |
7130 | 7186 | | |
7131 | 7187 | | |
7132 | 7188 | | |
| |||
7179 | 7235 | | |
7180 | 7236 | | |
7181 | 7237 | | |
| 7238 | + | |
| 7239 | + | |
| 7240 | + | |
| 7241 | + | |
| 7242 | + | |
| 7243 | + | |
| 7244 | + | |
| 7245 | + | |
| 7246 | + | |
| 7247 | + | |
| 7248 | + | |
| 7249 | + | |
| 7250 | + | |
| 7251 | + | |
| 7252 | + | |
| 7253 | + | |
| 7254 | + | |
7182 | 7255 | | |
7183 | 7256 | | |
7184 | 7257 | | |
| |||
7523 | 7596 | | |
7524 | 7597 | | |
7525 | 7598 | | |
7526 | | - | |
| 7599 | + | |
7527 | 7600 | | |
7528 | 7601 | | |
7529 | 7602 | | |
| |||
Lines changed: 51 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
528 | | - | |
| 528 | + | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
532 | 534 | | |
533 | 535 | | |
534 | 536 | | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
540 | 543 | | |
541 | 544 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
549 | 565 | | |
550 | 566 | | |
551 | 567 | | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
559 | 576 | | |
560 | 577 | | |
561 | 578 | | |
562 | 579 | | |
| 580 | + | |
| 581 | + | |
563 | 582 | | |
564 | 583 | | |
565 | 584 | | |
| |||
587 | 606 | | |
588 | 607 | | |
589 | 608 | | |
590 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
591 | 615 | | |
592 | 616 | | |
593 | 617 | | |
| |||
631 | 655 | | |
632 | 656 | | |
633 | 657 | | |
634 | | - | |
| 658 | + | |
635 | 659 | | |
636 | | - | |
| 660 | + | |
637 | 661 | | |
638 | 662 | | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
643 | 666 | | |
644 | 667 | | |
645 | 668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
| |||
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| 183 | + | |
| 184 | + | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| |||
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| 221 | + | |
| 222 | + | |
217 | 223 | | |
218 | 224 | | |
219 | 225 | | |
| |||
250 | 256 | | |
251 | 257 | | |
252 | 258 | | |
| 259 | + | |
| 260 | + | |
253 | 261 | | |
254 | 262 | | |
255 | 263 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
0 commit comments