perf: remember(force=True) should be a raw write — currently 5x slower than recall_index #18
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
remember()withforce=Truetakes ~1.7s per call on v5.1.1-beta, compared torecall_index()at ~0.34s. Both operations embed the content, so the extra ~1.3s is overhead in the write path thatforce=Trueshould be bypassing.Timing evidence
Model:
all-MiniLM-L6-v2, running on localhost, Docker on Mac.Expected behaviour
force=Trueis documented as "skip duplicate check". It should be a fast raw write: embed → store → done. At 0.34s for an embed+search, a write should be no more than ~0.4s.Impact
This makes bulk ingestion impractical. The LongMemEval benchmark stores ~250 turn-pair chunks per item. At 1.7s each that's ~425s per item, making a 500-item benchmark run take ~59 hours. At the expected ~0.4s it would take ~3.5 hours.
Suspected cause
v5 may be running contradiction detection, lifecycle processing, or other enrichment even when
force=True. These should be skipped entirely in force mode — the whole point is a raw bypass write.Suggested fix
In force mode, the write path should be:
Nothing else. Contradiction detection, dedup scoring, lifecycle hooks — all skipped.
Root cause identified
In
tools/core.py,force=Trueonly skips the dedup check (line 215) but the contradiction check still runs unconditionally (line 231-238):The contradiction check performs a similarity search against all existing memories, which costs ~1.3s on top of the ~0.34s embed. This is why
remember(force=True)costs 1.7s vsrecall_index()at 0.34s.Fix
force=Trueshould skip the contradiction check too:This would bring
remember(force=True)down to ~0.4s (embed + write only), making bulk ingestion viable.Additional root cause — v5 extract_facts()
In v5,
extract_facts(content)at line 174 also fires unconditionally regardless offorce=True. This is a Haiku API call costing ~1.2s perremember()call — the dominant bottleneck.Combined with the contradiction check,
force=Trueis actually running:extract_facts()— Haiku API call → ~1.2scheck_contradiction_heuristic()— similarity search → ~0.15sTotal: ~1.7s vs the expected ~0.4s for a raw write.
Full fix required
Both need guarding in
tools/core.py:With both guards in place,
force=Truebecomes: embed → write → return key (~0.4s).Closing — shipped in v5.1.2.
remember(force=True)is now a genuine raw bypass write: both the semantic duplicate check and the Tier 1 contradiction heuristic (the ~1.3s vector-search-plus-negation-scan that was running unconditionally) are skipped, and since v5.2.0 background enrichment is skipped underforce=Trueas well. Measured improvement at the time: ~1.7s → ~0.4s per call, taking the projected 500-item LongMemEval bulk ingestion from ~59 hours to ~3.5 hours.