feat(search): EXP-05 — instruction-type tagging and search boost#5
Draft
moralespanitz wants to merge 1 commit intomainfrom
Draft
feat(search): EXP-05 — instruction-type tagging and search boost#5moralespanitz wants to merge 1 commit intomainfrom
moralespanitz wants to merge 1 commit intomainfrom
Conversation
Tags facts that look like explicit instructions (markers: 'always X', 'never Y', 'do not Z', 'remember to W', 'from now on', 'going forward') during extraction enrichment, by setting metadata.fact_role='instruction' and flooring importance to 0.95. Adds an applyInstructionBoost retrieval stage that adds a configurable weight to facts with metadata.fact_role='instruction' during search ranking, after current-state-ranking and before final RRF rerank. New config keys (both defaults-off): - instructionBoostEnabled: false - instructionBoostWeight: 0.15 Both are config-override-allowlisted so the BEAM adapter can A/B per ability via per-request config_override without server restart. Targets BEAM IF ability per Sprint 2 EXP-05. Memory currently hurts IF relative to no-memory baseline because instruction memories get diluted in mixed retrieval; boosting them recovers the signal. Behind feature flags. Defaults preserve current behavior.
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
EXP-05 from BEAM Sprint 2: tag explicit instructions at extraction time and boost them during retrieval ranking. Targets the BEAM IF (instruction-following) ability, where memory currently hurts relative to the no-memory baseline (Honcho 0.844, no-memory 0.760, AtomicMemory below baseline) because instruction memories get diluted in mixed retrieval pools.
Why
From
phase2-implementation-plans-2026-04-29.md(EXP-05):What
Ingest path (always-on, behaviorally identical when boost is off)
src/services/extraction-enrichment.ts— newINSTRUCTION_MARKERSconstant detects imperative phrasing in extracted facts. When matched,enrichExtractedFactwrites:metadata.fact_role: 'instruction'importance: max(prev, 0.95)(floor — keeps lifecycle decay from evicting them)Markers:
'always ','never ','from now on','please remember','make sure to',"don't forget",'do not forget','every time','whenever you','going forward','in the future','remember to'.Tagging is unconditional — only the retrieval boost is gated. This is intentional so a flag flip is bit-identical for already-ingested data.
Retrieval path (gated behind
instructionBoostEnabled)New file
src/services/instruction-boost.ts(~55 LOC).applyInstructionBoostaddsinstructionBoostWeightto the score of every result whosemetadata.fact_role === 'instruction', then re-sorts.Wired into
search-pipeline.ts:applyRankingProtectionStagesbetween the current-state-ranking stage and the conciseness-penalty stage. No-op when the flag is off.Plumbing
metadata?: Record<string, unknown>added toExtractedFact(extraction.ts) andFactInput(memory-service-types.ts) so the tag survives the extraction → enrichment → audn → storage hop.memory-storage.ts:storeProjection— newmergeStoreMetadatahelper mergesfact.metadatawithcmo_idwhen persisting the parent memory.cmo_idalways wins on conflict.memcell-projection.ts:buildAtomicFactProjection— propagatesfact.metadataonto the atomic-fact row metadata.'fact_role'added toRESERVED_METADATA_KEYSso callers cannot spoof it via the public ingest API. Drift-guard testreserved-metadata-keys.test.tscontinues to pass.Config
Two new keys in
src/config.ts(and mirrored onCoreRuntimeConfigandSearchPipelineRuntimeConfig):instructionBoostEnabledfalseINSTRUCTION_BOOST_ENABLEDinstructionBoostWeight0.15INSTRUCTION_BOOST_WEIGHTBoth are added to
INTERNAL_POLICY_CONFIG_FIELDS, which makes themconfig_override-allowlisted. The BEAM adapter can A/B per-ability per-run without a server restart:Files changed
src/services/instruction-boost.ts— new (55 LOC)src/services/__tests__/instruction-boost.test.ts— new (156 LOC, 8 cases)src/services/extraction-enrichment.ts— +49 LOC (markers, tagging, detector)src/services/__tests__/extraction-enrichment.test.ts— +73 LOC (16 new cases)src/services/extraction.ts—metadataonExtractedFactsrc/services/memory-service-types.ts—metadataonFactInputsrc/services/memory-storage.ts—mergeStoreMetadatahelpersrc/services/memcell-projection.ts— propagate metadata into atomic projectionsrc/services/search-pipeline.ts—applyInstructionBoostStagebetween current-state and concisenesssrc/db/repository-types.ts—'fact_role'reservedsrc/config.ts,src/app/runtime-container.ts— config keys + allowlistTest plan
npx tsc --noEmit— clean.npx vitest run src/services/__tests__/instruction-boost.test.ts— 8/8 pass.npx vitest run src/services/__tests__/extraction-enrichment.test.ts— 19/19 pass (3 pre-existing + 16 new).npx vitest run src/__tests__/reserved-metadata-keys.test.ts— pass (drift guard accepts the newfact_rolekey).fallowpre-commit hook — clean.npm test) — requires.env.testwith Postgres+pgvector; not run in this worktree per task instructions (server uses the main checkout's DB).instructionBoostEnabled: truevsfalseviaconfig_override.How to test locally
Constraints honored
any. No directprocess.envaccess (single touchpoint inconfig.ts).false(Sprint 2 defaults-off rule).