Skip to content

perf(consolidation): look up recalled observations by id - #6406

Merged
nicoloboschi merged 1 commit into
mainfrom
perf-consolidation-obs-by-id
Nov 6, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
perf-consolidation-obs-by-id

Conversation

@nicoloboschi

@nicoloboschi nicoloboschi commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #6324. Patch by @harshitgupta31415 (credited as co-author), plus a regression test.

What changes

The recalled observations are kept in one dict, filled once in recall order. The delete check, the merge-target check and the update lookup read it directly, instead of a list plus a set of ids beside it, a copy of that set for every merge, and a scan of the list for every update.

This is a cleanup more than a speed fix: the saved time is microseconds per batch, next to a model call that takes seconds.

No behaviour change

  • The observation list given to the prompt is the same objects in the same order, so the prompt text is unchanged.
  • Old and new logic compared on 200k random inputs (duplicate ids across and within recalls, str/UUID ids, unknown ids, self-merges, None targets): identical results every time.
  • The full api-slim suite ran with temporary checks that computed the old logic next to the new one on every real batch: 4,370 batches, 990 with overlapping recalls, zero mismatches. Those checks are not in this PR.

Test

tests/test_consolidation_merge_target.py: a merge delete moves its evidence onto an observation the model was shown, never onto one it was not shown. Removing the target check makes it fail.

The recalled observations are now kept in one dict, filled once in recall
order, instead of a list plus a set of ids beside it. The delete check, the
merge-target check and the update lookup read that dict directly, rather
than copying the id set on every merge and scanning the list on every update.

No behaviour change: the observation list handed to the prompt is the same
objects in the same order, and every delete/merge/update decision is the
same. Checked by comparing old and new logic on 200k random inputs and by
running both side by side on every batch of the api-slim suite.

Adds a regression test that a merge moves its evidence only onto an
observation the model was shown; it fails with the target check removed.

Closes #6324

Co-authored-by: harshitgupta31415 <[email protected]>
@nicoloboschi
nicoloboschi merged commit 8bf0b08 into main Nov 6, 2026
112 checks passed
@nicoloboschi
nicoloboschi deleted the perf-consolidation-obs-by-id branch November 6, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

consolidation scans recalled observations again for each update (266.21 µs → 39.77 µs, 6.69× faster)

1 participant