[GH-ISSUE #1251] [Issue]: LTM keyword and metadata buckets are capped before the scope filter #637

Closed
opened 2026-10-20 17:29:15 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1251

Originally assigned to: @Promansis on GitHub.

Summary

Keyword and metadata index buckets are truncated to 128 entries before the scope filter runs, so out-of-scope chunks can crowd in-scope chunks out of the keyword, direct and graph-seed lanes. The fuzzy keyword scan has the same flaw: it caps at 512 keywords across the whole vault.

Affected package

long-term-memory (packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts, metadata-index.ts)

Expected behavior

Only chunks allowed for the current chat (scope, status, mode) count toward each bucket's cap and the fuzzy-scan cap.

Actual behavior

  • keyword-index.ts:80,87,102,109 do chunkIds.slice(0, 128). The allowed-set check is only inside add (:67), after the slice.
  • metadata-index.ts:56,65,69 apply the bucket slice and a 128-candidate cap before the retrieval filters (retrieval.ts:142).
  • Every chunk inherits its note's keywords (chunking.ts:80,118). A recurring character or place keyword on ~26+ multi-section notes, including other chats' and archived or resolved notes, exceeds 128 entries. Out-of-scope ids fill the slice first, so in-scope chunks never get the exact (score 3/4) hit and never become graph seeds. The direct lane behaves the same for popular #tags.
  • keyword-index.ts:92-94 sorts and slices all keywords in the vault (including out-of-scope and archived) to 512 on every recall. In a vault of ~2000 keywords, a keyword after roughly "d..." can never fuzzy-match.

Steps to reproduce

  1. Create > 128 chunks sharing one keyword (or #tag) in other chats or archived notes, so they sort first in the bucket.
  2. Add an in-scope note with the same keyword and query for it in the current chat.
  3. The in-scope chunks get no keyword/direct hit and are not graph seeds. For fuzzy matching, use a vault with > 512 keywords and a query matching a late-alphabet keyword.

Environment

  • Marinara Engine version: 2.5.0 line (staging)
  • Package version: long-term-memory 1.4.7
  • Install type: source (found by code audit and tsx probes against src/)
  • OS + version: not platform-specific
  • Browser or app shell: not UI-specific

Logs, screenshots, or video

None. Code-traced; anchors above. Full write-up: audit findings LTM-SCORE-04 and 08 (local scratch/audits/ltm-recall-scoring.md, not tracked).

Additional context

Proposed fix: apply the scope filter before the caps.

  • In keyword-index.ts, check allowedChunks while walking each bucket and stop after N allowed ids.
  • Pass the allowed set into getLtmMetadataMatches.
  • For fuzzy matching, iterate the query terms against a term index, or filter by scope before the 512 cap.
  • Add a regression: a bucket with > 128 entries where the in-scope chunks sort after the slice, and > 512 catalog keywords where a late-alphabet keyword should match.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1251 Originally assigned to: @Promansis on GitHub. ## Summary Keyword and metadata index buckets are truncated to 128 entries before the scope filter runs, so out-of-scope chunks can crowd in-scope chunks out of the keyword, direct and graph-seed lanes. The fuzzy keyword scan has the same flaw: it caps at 512 keywords across the whole vault. ## Affected package long-term-memory (`packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts`, `metadata-index.ts`) ## Expected behavior Only chunks allowed for the current chat (scope, status, mode) count toward each bucket's cap and the fuzzy-scan cap. ## Actual behavior - `keyword-index.ts:80,87,102,109` do `chunkIds.slice(0, 128)`. The allowed-set check is only inside `add` (:67), after the slice. - `metadata-index.ts:56,65,69` apply the bucket slice and a 128-candidate cap before the retrieval filters (`retrieval.ts:142`). - Every chunk inherits its note's keywords (`chunking.ts:80,118`). A recurring character or place keyword on ~26+ multi-section notes, including other chats' and archived or resolved notes, exceeds 128 entries. Out-of-scope ids fill the slice first, so in-scope chunks never get the exact (score 3/4) hit and never become graph seeds. The direct lane behaves the same for popular `#tags`. - `keyword-index.ts:92-94` sorts and slices all keywords in the vault (including out-of-scope and archived) to 512 on every recall. In a vault of ~2000 keywords, a keyword after roughly "d..." can never fuzzy-match. ## Steps to reproduce 1. Create > 128 chunks sharing one keyword (or `#tag`) in other chats or archived notes, so they sort first in the bucket. 2. Add an in-scope note with the same keyword and query for it in the current chat. 3. The in-scope chunks get no keyword/direct hit and are not graph seeds. For fuzzy matching, use a vault with > 512 keywords and a query matching a late-alphabet keyword. ## Environment - Marinara Engine version: 2.5.0 line (`staging`) - Package version: long-term-memory 1.4.7 - Install type: source (found by code audit and tsx probes against `src/`) - OS + version: not platform-specific - Browser or app shell: not UI-specific ## Logs, screenshots, or video None. Code-traced; anchors above. Full write-up: audit findings LTM-SCORE-04 and 08 (local `scratch/audits/ltm-recall-scoring.md`, not tracked). ## Additional context Proposed fix: apply the scope filter before the caps. - In `keyword-index.ts`, check `allowedChunks` while walking each bucket and stop after N *allowed* ids. - Pass the allowed set into `getLtmMetadataMatches`. - For fuzzy matching, iterate the query terms against a term index, or filter by scope before the 512 cap. - Add a regression: a bucket with > 128 entries where the in-scope chunks sort after the slice, and > 512 catalog keywords where a late-alphabet keyword should match. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:15 +07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#637
No description provided.