Skip to content

fix(memory): increase recall budget and add vector distance cutoff - #677

Merged
dcramer merged 4 commits into
mainfrom
fix/memory-recall-truncation-and-relevance
Jun 29, 2026
Merged

dcramer merged 4 commits into
mainfrom
fix/memory-recall-truncation-and-relevance

Conversation

@dcramer

@dcramer dcramer commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Problem

Memories were truncating and low-relevance vector results were surfacing in recall.

Changes

Truncation fix (recall.ts):

  • MAX_MEMORY_LINE_CHARS: 320 → 600
  • MAX_PROMPT_CHARS: 1600 → 4000

Configurable vector distance threshold (plugin.ts, recall.ts, store.ts):

Adds MEMORY_RECALL_MAX_VECTOR_DISTANCE env var following the same pattern as AI_MEMORY_MODEL. The threshold flows:

plugin.ts (MEMORY_RECALL_MAX_VECTOR_DISTANCE env / recallMaxVectorDistance option)
  → MemoryRecallContext.maxVectorDistance
    → MemoryStoreOptions.maxVectorDistance
      → searchVisibleVectorMemories (maxDistance filter)

Default is 0.45 for text-embedding-3-small (the current default embedding model). Operators should retune when changing AI_EMBEDDING_MODEL — there's no universal threshold across models.

Also updates init.ts .env.example template 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

  • TypeScript: pnpm --filter @sentry/junior-memory exec tsc --noEmit and pnpm --filter @sentry/junior exec tsc --noEmit — both clean

Refs: https://jr-cramer.slack.com/archives/C0B595QDZLL/p1782761766112369

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>
@vercel

vercel Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment Jun 29, 2026 7:59pm

Request Review

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>
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>
@dcramer
dcramer merged commit adbdbc3 into main Jun 29, 2026
18 checks passed
@dcramer
dcramer deleted the fix/memory-recall-truncation-and-relevance branch June 29, 2026 20:11

This branch was successfully deployed

1 active deployment
Preview – junior-docs — ce7d8774 Deployed Jun 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant