Repository navigation
feat(profile): D164 batched converging profile refresh and indexed neighborhood gather - #692
Conversation
Replace per-entity transactions in EntityProfileRefresher.refresh_many with 64-entity prepare transactions committing fail-closed clears before any embedding call, followed by per-64-text-batch embed and batched revalidation commits with byte-identical EmbeddingRequest batches and call_keys. Add attest_profile_entities_batch for batched clustering attestation with pre-sorted text[] advisory locks and waiting ORDER BY entity_id FOR UPDATE. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
… §2) Rewrite neighborhood gather to UNION the two GIN-indexable branches (normalized_lemma % lemma AND similarity >= 0.3 with transaction-local pg_trgm.similarity_threshold='0.3', plus daitch_mokotoff overlap) over existing aliases indexes. Batch EntityClusterer.recluster_entities over up to 64 SQL-collation-ordered slots / 256 entities per transaction with per-slot normalized_lemma, 1-to-1 NeighborhoodReport parity, pre-sorted text[] advisory locks, waiting entity row locks, :obs:-only try-lock deferral in proposal mode, immediate commit and base refresh on auto-merge mutation, and math.sumprod HAC norms. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Build ix_observations_profile_salience_v2, ix_relations_profile_subject_salience_v2, and ix_relations_profile_object_salience_v2 online via resumable plain-table CREATE INDEX CONCURRENTLY inside autocommit_block(), verify all three, and drop the reader-less p9_16_0037 indexes via DROP INDEX CONCURRENTLY IF EXISTS with zero ACCESS EXCLUSIVE locks. Update catalog_contract, storage-capture head pins, and regenerate live_corpus_profile.json. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Add test-only pre-D164 reference oracle, unit tests, online migration resumability/lock tests, gather equivalence tests, batched profile/clusterer equivalence and failure-mode proofs, deterministic convergence replay, measured-shape EXPLAIN/query-budget/WAN-timing verification, and the scripts/replay_d164_retained_store.py script for private LoCoMo replay. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
math.sumprod accumulates with extended precision, so HAC distances could differ from main in the last bits and flip a cut or tie decision. Keep the cached per-cluster norm (same value, same arithmetic) and restore the original summation for dot products and norms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
Implementation review, round 1 (independent Claude reviewer; head 76f76d7)VERDICT: CHANGES_REQUESTED. Verified correct: refresher prepare-all, contention, 57014 translation, byte-identical batches and Blocking
Non-blocking
|
- Cache singleton vector norms and pairwise cosines per batch transaction in EntityClusterer.recluster_entities / _hac_pieces (bit-identical floats, cutting measured-shape 0%-changed local time from 21.74 s to 4.50 s). - Delete unused pre-D164 symbols from production (recluster_neighborhood, _gather, _GATHER_NEIGHBORHOOD, _TRY_LOCK_NEIGHBORHOOD, current_profile_entity_ids, _TRY_LOCK_ENTITY), copy verbatim origin/main (32a47c6) versions including _hac_pieces and _cosine into d164_pre_oracle.py, port test_clustering.py and test_clustering_lock_policy.py to recluster_entities / attest_profile_entities_batch, and add a randomised old-vs-new HAC test. - Fix replay_d164_retained_store.py to select its :obs: deferral target only from lemmas of nominated entities and count real deferrals. - Compare full NeighborhoodReports (including black_hole_tightened and (survivor_id, absorbed_id) merge pairs), keep merge_events.evidence and pre_merge_membership_snapshot with normalised UUIDs/timestamps, add an exact float4 0.3 similarity pair to the gather boundary test, label the 100%-changed WAN figure as computed, document downgrade index behaviour in p9_61_0082 (with regenerated live_corpus_profile.json), and add a unit test pinning recluster_entities' auto-merge lock order. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Implementation review, round 2 (independent Claude reviewer; head 44dd361): APPROVEThe code is approved. Merge gate: the design §6.4 frozen-store replay must report zero diffs; results will be posted here.
Non-blocking:
|
…cally Create and clean up rememberstack_query_<clone_db> and rememberstack_graph_<clone_db> roles in _cloned_database so alembic upgrade head (p9_58_0079) succeeds against unmigrated retained stores, and sort merge_events by semantic columns rather than wall-clock decided_at. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Frozen-store replay (design §6.4): 0 diffs on every store
* conv-30 has no non-excluded pair within the default 0.35 cut, so it was also replayed at 0.6 to exercise merges and reviews. The production job that failed on remember.dev was converging refresh for the 399 relations of the 302-claim document, Harness fixes found during the run are in 97e21c8 (script only):
Observed: a store restored without statistics (empty |
Implements the accepted D164 design (#690,
plan/designs/bounded_profile_convergence_design.md).Why
Converging profile refresh (profile refresh + neighborhood re-clustering) ran as one unbounded,
latency-bound task. On remember.dev a 302-claim document made
adjudicate_supersessionandlabel_relationexceed the1,800 s Cloud Run / Cloud Tasks ceiling on every attempt (893 s even next to the database). The root causes are
the per-entity evidence loads (each entity re-attested about 27 times), a gather query that bypassed the
aliasesGINindexes, salience indexes that no longer match their query, and a prepare-all pass that kept no progress
when cut off. Evidence and cost model:
plan/analysis/bounded_profile_convergence_analysis.md.What changes
EntityProfileRefresher.refresh_many. A batched prepare-all pass: 64-entity transactions, with fail-closed clearscommitted before any provider call. Then embed, revalidate and commit per 64-text batch, with byte-identical requests
and
call_keys. Rows already current at commit are skipped, andRETURNINGID checks guard the writes.EntityClusterer. A transaction-local trigram threshold and a GIN-indexed gather with a proven-equivalent rowset. Attestation is batched (up to 64 lemmas / 256 entities) with the same lock order and the same lemma slot order
from SQL. Rows are locked with waiting
FOR UPDATE; deferral happens only on a failed:obs:try-lock. Withauto-merge on, a batch stops at the first mutation. HAC arithmetic is unchanged (fee0d0e keeps the exact
pre-D164 summation).
p9_61_0082. Online and resumableCREATE INDEX CONCURRENTLYof three*_v2salience indexes on theplain
relationsandobservationstables, thenDROP INDEX CONCURRENTLYof the reader-lessp9_16_0037indexes.No stage, payload, component version, prompt, model or identity key changes, so nothing is re-extracted or re-embedded.
Tests
src/tests/spine/d164_pre_oracle.py).test_d164_convergence_pg.py:failure and on optimistic exhaustion;
test_d164_migrations_pg.py:relkind, resumable build, noAccessExclusiveLock.test_d164_batch_unit.py.profile refresher, clustering, migrations, storage capture and workers passed. ruff and pyright are clean, and the
storage-capture fixture and llms check pass.
scripts/replay_d164_retained_store.pyon retained LoCoMo stores: running now;results will be posted here before merge.
Process
re-review is planned then. Review rounds are posted as comments.
Contributor agreement
Signing on behalf of a legal entity (leave blank if accepting individually):
🤖 Generated with Claude Code
https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq