feat: observable retrieval traces + batch dedup#319
Open
AliceLJY wants to merge 2 commits intoCortexReach:masterfrom
Open
feat: observable retrieval traces + batch dedup#319AliceLJY wants to merge 2 commits intoCortexReach:masterfrom
AliceLJY wants to merge 2 commits intoCortexReach:masterfrom
Conversation
Observable Retrieval (Feature 3): - Add TraceCollector (src/retrieval-trace.ts) that tracks entry IDs through each pipeline stage, computing drops, score ranges, and timing - Add RetrievalStatsCollector (src/retrieval-stats.ts) for aggregate query metrics: latency percentiles, zero-result rate, top drop stages - Instrument all retrieval stages in MemoryRetriever.retrieve() with optional trace (zero overhead when disabled via optional chaining) - Add retrieveWithTrace() for always-on debug tracing - Add memory_debug tool (requires enableManagementTools) returning full per-stage pipeline trace with drop info - Extend memory_stats tool to include retrieval quality metrics Batch Dedup (Feature 2): - Add batchDedup() (src/batch-dedup.ts) for cosine similarity dedup within extraction batches before expensive LLM dedup calls - Add ExtractionCostStats tracking (batchDeduped, durationMs, llmCalls) Tests: 26 new tests (16 trace + 10 batch-dedup), all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. [High] Fix hybrid trace timing: replace sequential vector_search/bm25_search stages with single parallel_search stage that correctly represents concurrent execution 2. [High] Fix negative drop display: search stages with input=0 now show "found N" instead of "dropped -N" 3. [Medium] Fix rerankUsed overcount: only emit rerank trace stage when rerank is actually enabled (config.rerank !== "none"), not on every query Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TraceCollectorandRetrievalStatsCollectorto make the multi-stage retrieval pipeline fully debuggable. Each stage (vector search, BM25, RRF fusion, min score filter, rerank, recency boost, importance weight, length normalization, time/decay boost, hard cutoff, noise filter, MMR diversity) is instrumented with entry ID tracking, drop computation, score ranges, and timing. Zero overhead when tracing is disabled (uses optional chaining).memory_debugtool: New management tool that returns retrieval results plus full per-stage pipeline trace showing exactly which entries were dropped at each stage and why.memory_statsextension: Now includes retrieval quality metrics (zero-result rate, latency percentiles, top drop stages) when stats collector is active.batchDedup()for O(n^2) pairwise cosine similarity check on extraction candidates (n <= 5) to skip near-duplicate candidates before expensive LLM dedup calls. IncludesExtractionCostStatstracking.Test plan
TraceCollectorandRetrievalStatsCollector(stage tracking, drops, score ranges, zero-overhead, p95 latency, capacity eviction)batchDedupandExtractionCostStats(similar/dissimilar detection, threshold sensitivity, edge cases)🤖 Generated with Claude Code