Skip to content

Prefrontal recall: PR-topic queries and semantic relevance floor (0.4) - #63

Merged
khezen merged 3 commits into
mainfrom
fix/prefrontal-relevance-floor
Nov 24, 2026
Merged

khezen merged 3 commits into
mainfrom
fix/prefrontal-relevance-floor

Conversation

@khezen

@khezen khezen commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Problem

On peaks-com/mono#10519 (pension-switcher drafts + sorting), "Other repositories in peaks-com" was full of unrelated peaks-ios facts, and Seen before / Decisions / Patterns returned scope facts that had nothing to do with the PR.

Causes:

  • Hindsight recall returns the top results until the token budget is full. It has no relevance floor unless min_scores is passed, and codespy never passed it.
  • The remote query was the local context query (task, repo/scope id, Files: …). Those words appear in every repo of the org.
  • seen_before started with the scope id and package names, which every fact of that scope matches.
  • decisions and patterns used no PR content at all ("<scope>: decisions, …").

Changes

  • Queries (prefrontal/query.py)
    • The PR topic is the scope description, PR title and PR summary.
    • Remote pool: the PR topic only.
    • seen_before: the changed paths and symbols only.
    • decisions / patterns: the topic, then their usual phrasing. The topic is shortened first, so the phrasing always survives the word cap.
    • Each falls back to its old query, with no floor, when there are no paths/symbols or no topic.
  • Relevance floor: memory.prefrontal.recall.min_similarity (env MEMORY_RECALL_MIN_SIMILARITY, 0–1, default 0.4, 0 = off).
    • A fact is kept only if its scores.semantic is set and at or above the floor.
    • Applies to the remote pool (pre-call and raw recall_memory) and to seen_before, decisions and patterns.
    • "What changed" is built only from kept facts.
    • Not applied to context (reflect), the tool's local recall or reflect mode.
    • Also passed to Hindsight as MinScores(semantic=…), through a new Cerebral.arecall(min_semantic=…) argument.
  • Score logging for calibration
    • One INFO line per fact before filtering: Prefrontal[<task>] score section=… semantic=… kept=… repo=… text=….
    • Recall record details gain scores, remote_dropped, remote_scores, per-facet dropped, and remote_query.
    • The load log line now shows the dropped counts.
  • Updated docs (docs/memory.md), codespy.yaml, and CHANGELOG ### Fixed (no version bump).

Rollout

The default floor is 0.4, calibrated on mono#10519 with Cohere embed v4:

  • All 26 remote facts were unrelated peaks-ios facts and scored 0.30–0.39.
  • The lowest relevant local fact scored 0.411.
  • Unrelated local facts scored 0.30–0.33.

Known limits:

  • Some generic facts still pass: the repo layout convention (0.41–0.53) and an unrelated Salesforce pension PR (0.46–0.48).
  • Facts found only by keyword search, graph links or time proximity have no semantic score, so they are dropped. In this run that cost 3–4 relevant run-level facts.

MEMORY_RECALL_MIN_SIMILARITY=0 restores the old behaviour.

⚠️ The score lines include up to 80 chars of each fact's text, remote facts included. On public repos this can expose memory from private sibling repos (reach: org), or from other organisations (reach: bank), in CI logs. Run calibration where the logs aren't public.

Tests

  • New tests/test_prefrontal_relevance.py (25 tests): query shapes and fallbacks, per-facet filtering and min_semantic, context never filtered, "What changed" built only from kept facts, remote filtering and section omission, topic-only remote query, floor 0 keeps everything, the raw recall_memory remote branch, and score records.
  • Hindsight contract tests: recall_async(min_scores), MinScores.semantic, MemoryFact.scores / RecallScores.semantic.
  • Cerebral.arecall passes min_scores only when the floor is above 0.
  • Config tests: default, bounds, env override.

The full suite has the same failures as before this change, none new. One example is test_arecall_forwards_arguments, which still expects the bank to be called codespy instead of codebase.

@khezen khezen changed the title Prefrontal recall: PR-topic queries and semantic relevance floor Prefrontal recall: PR-topic queries and semantic relevance floor (0.4) Nov 24, 2026
@khezen
khezen merged commit 1dd5aad into main Nov 24, 2026
6 checks passed
@khezen
khezen deleted the fix/prefrontal-relevance-floor branch November 24, 2026 16:32
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