Repository navigation
Open
Description
Passive extraction pre-searched existing memories with the full user+tool transcript. That made hybrid retrieval less accurate and more expensive: embeddings and FTS ran over tool dumps and long session text instead of durable user evidence.
Current behavior
processSessionbuilt the pre-search query from every user message and tool result before extraction.- The completed-run projection prepends prior public-thread messages as ambient
contextauthority, then appends this turn's run entries (packages/junior/src/chat/plugins/task-runner.ts). searchMemoriesalready runs parallel vector + lexical legs and fuses ranks with RRF (packages/junior-memory/src/store.ts,ranking.ts).- Recent lexical perf work kept that hybrid contract: perf(memory): remove structured identifier matching #1227, perf(memory): optimize lexical search #1233, perf(memory): bound lexical ranking candidates #1242.
- perf(memory): defer lexical recall until needed #1244 explored skipping lexical on automatic recall when any in-threshold vector hit exists. That path does not fix extraction and weakens exact/token recall.
Gap
- Extraction needs nearby existing memories for skip/supersede context.
- The retrieval query should include this turn's instructions and ambient thread context, but not raw tool dumps.
- Hybrid RRF performs well when each leg is a bounded top-k index probe, not when the query is a whole transcript or tool payload.
Impact
- Worse candidate quality for passive extraction skip/dedup decisions
- Unnecessary embedding + FTS cost on every completed session with tool output
- Pressure to optimize by dropping a hybrid leg instead of fixing the query
Prior art
- Supabase hybrid search: independent top-k full-text and vector CTEs, then RRF over short lists — https://supabase.com/docs/guides/ai/hybrid-search
- ParadeDB hybrid manual: keep lexical and vector separate, fuse ranks, do not blend raw scores — https://www.paradedb.com/blog/hybrid-search-in-postgresql-the-missing-manual
- Conversational RAG query rewrite / condense-question before retrieval (LangChain ConversationalRetrievalChain family)
- Multi-query rewrite and HyDE-style expansion for hard retrieval cases
Proposal
Requested design implemented in #1246:
- Keep hybrid RRF for both
searchMemoriesandrecallMemories(no skip lexical if any vector hit). - For extraction pre-search, query from this turn's run-actor instructions + ambient thread context (not tool dumps), capped around 1.5k chars, instructions first then leftover budget for context.
- Keep each retrieval leg bounded; tighten lexical rank candidates to a small hybrid window (hundreds, not thousands).
- Leave the full run transcript available to the extraction model; only the retrieval query is curated.
- Document selection rules in code comments so later sources (e.g. compact tool summaries / Luna rewrite) can be added deliberately.
Metadata
Metadata
Assignees
Labels
No labels
Activity
sentry-junior commentedon Aug 5, 2026
Follow-up recommendation for tool results:
This is intentionally deferred from #1246: the current deterministic baseline uses turn instructions + ambient thread context. Add the rewrite step only with evidence that tool-heavy turns miss existing memories or create duplicates.