Repository navigation
fix(memory): increase recall budget and add vector distance cutoff - #677
Merged
Merged
Conversation
Raise MAX_MEMORY_LINE_CHARS 320→600 and MAX_PROMPT_CHARS 1600→4000 so moderately-sized memories no longer get truncated mid-sentence in the recall prompt. Add MAX_RECALL_VECTOR_DISTANCE = 0.45 and filter it in searchVisibleVectorMemories. Without a minimum-relevance threshold, low-relevance vector results (sentry autofix details surfacing for a junior CI question) were being injected into context for every request. The threshold only applies to vector recall path; lexical fallback behaviour is unchanged. Value is conservative and can be tightened if false positives persist. Co-Authored-By: claude-opus-4-5 <[email protected]> Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
MAX_RECALL_VECTOR_DISTANCE = 0.45 was an arbitrary agent-chosen constant. Absolute cosine distance thresholds are not portable across embedding models — text-embedding-ada-002 has a random-pair floor near distance 0.32, while text-embedding-3-* models go much lower, so no universal value exists. The principled fix is a recall-layer relevance gate (LLM or reranker) that filters candidates by semantic fit to the user request, not by raw geometry. Tracked separately. Co-Authored-By: claude-opus-4-5 <[email protected]> Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Add MEMORY_RECALL_MAX_VECTOR_DISTANCE env var and recallMaxVectorDistance
option on MemoryPluginOptions, following the same pattern as AI_MEMORY_MODEL.
Thread:
plugin.ts (env/option read)
→ recall.ts (MemoryRecallContext.maxVectorDistance)
→ store.ts (MemoryStoreOptions.maxVectorDistance)
→ searchVisibleVectorMemories (maxDistance filter)
Default 0.45 is appropriate for text-embedding-3-small (the default
embedding model). Operators should retune this value whenever they change
AI_EMBEDDING_MODEL since thresholds are model-dependent.
Co-Authored-By: claude-opus-4-5 <[email protected]>
Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
dcramer
marked this pull request as ready for review
June 29, 2026 19:56
Cosine distance for unit-normalized vectors is 0–1 in practice (text embeddings stay in the positive quadrant). Cap the env/option value at 1 with Math.min rather than allowing up to 2. Co-Authored-By: claude-opus-4-5 <[email protected]> Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
This branch was successfully deployed
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.
Problem
Memories were truncating and low-relevance vector results were surfacing in recall.
Changes
Truncation fix (
recall.ts):MAX_MEMORY_LINE_CHARS: 320 → 600MAX_PROMPT_CHARS: 1600 → 4000Configurable vector distance threshold (
plugin.ts,recall.ts,store.ts):Adds
MEMORY_RECALL_MAX_VECTOR_DISTANCEenv var following the same pattern asAI_MEMORY_MODEL. The threshold flows:Default is
0.45fortext-embedding-3-small(the current default embedding model). Operators should retune when changingAI_EMBEDDING_MODEL— there's no universal threshold across models.Also updates
init.ts.env.exampletemplate and memory plugin docs.What's not in this PR
A fully model-agnostic relevance gate (LLM reranker over recall candidates) is tracked in #679. The env-configurable threshold is a practical floor that covers the "obviously not relevant" case.
Verification
pnpm --filter @sentry/junior-memory exec tsc --noEmitandpnpm --filter @sentry/junior exec tsc --noEmit— both cleanRefs: https://jr-cramer.slack.com/archives/C0B595QDZLL/p1782761766112369