[GH-ISSUE #1302] [Issue]: Long-Term Memory embeds recall queries as documents #662

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

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

Originally assigned to: @Promansis on GitHub.

Summary

Long-Term Memory embeds the recall search query through the same path as indexed chunks and never marks it as a query. With E5, nomic-embed-text or Snowflake Arctic Embed v2 models, the query gets the document prefix, which weakens semantic recall in every language. This is the package half of Pasta-Devs/Marinara-Engine#7429.

Affected package

long-term-memory (Long-Term Memory) 1.4.23

Expected behavior

The recall query is embedded with input type "query" and indexed chunks with "document", so the Engine applies the right prefix for the model.

Actual behavior

  • PackageEmbeddingAdapter.embed(texts, signal?) has no input-type parameter ([package-runtime.ts L109-L113](https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/package-runtime.ts#L109-L113)).
  • embedLongTermMemoryTexts calls adapter.embed(batch, options.signal) ([embedding-adapter.ts L24 and L35](https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/embedding-adapter.ts#L24-L35)).
  • Recall embeds [query] through that same function (retrieval.ts L213),```` exactly as rebuild does for chunks (rebuild.ts L135).`````
  • Even after the Engine fix, LTM won't send the type until this change lands.

Steps to reproduce

  1. On the Engine, give the connection LTM uses an embedding model with a prefix profile, for example intfloat/multilingual-e5-large, or nomic-embed-text on Ollama. LTM uses the default connection, or the one set with Connections → apply to all agents.
  2. Save a few memories and send chat messages until recall runs.
  3. Inspect the texts sent to the embeddings endpoint. The recall query starts with passage: (search_document: for nomic) instead of query: (search_query: ).

Environment

  • Marinara Engine version: 2.5.0 (staging at ecd62a2e4678d82fae753dd19f0f15cfbe48bba0)
  • Package version: 1.4.23 (staging at 11c8a563e7ef33b03442909814366f11330e1aad)
  • Install type: source. Found by code inspection, not reproduced against a live provider.
  • OS + version: not applicable
  • Browser or app shell: not applicable

Logs, screenshots, or video

No logs, because the wrong prefix fails silently. Code references are above.

Additional context

Minimal fix

  1. package-runtime.ts: embed(texts: string[], signal?: AbortSignal, inputType?: "query" | "document"): Promise<number[][] | null>;
  2. embedding-adapter.ts: add inputType?: "query" | "document" to MemoryRecallEmbeddingOptions, and call adapter.embed(batch, options.signal, options.inputType) at both call sites.
  3. retrieval.ts L213: embedLongTermMemoryTexts([query], { ...input, embeddingAdapter, inputType: "query" }).
  4. rebuild.ts L135 can stay as it is, since the default is document, or pass inputType: "document" explicitly.
  • No spaceId change and no reindex. Stored vectors are already document embeddings.
  • No capabilityApi bump. Older Engines ignore the third positional argument. The fix takes effect on Engines that include Pasta-Devs/Marinara-Engine#7429. Keep it positional, not an options object: older Engines hand the second argument to AbortSignal.any, so an object there would throw.
  • Regression in tests/long-term-memory-runtime.regression.ts: a fake adapter records its third argument. Recall should send "query", rebuild should send "document" (or undefined), and spaceId should stay unchanged.
  • Bump the package version and CHANGELOG as the repository requires.

Who is affected

  • Affected: e5 and multilingual-e5, nomic-embed-text, and Hugging Face snowflake-arctic-embed v2 model IDs.
  • Not affected: the default built-in MiniLM, bge-m3, OpenAI and Gemini embedding models. Their profiles have no prefixes.
  • Pasta-Devs/Marinara-Engine#7429, the Engine host change this depends on.
  • #1303 (LTM doesn't register the Engine refresh hook) and #1304 (show LTM's embedding source and how to change it).
  • #1295, section 4. This doesn't address the default MiniLM being English-only; #1304 covers that.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1302 Originally assigned to: @Promansis on GitHub. ## Summary Long-Term Memory embeds the recall search query through the same path as indexed chunks and never marks it as a query. With E5, nomic-embed-text or Snowflake Arctic Embed v2 models, the query gets the document prefix, which weakens semantic recall in every language. This is the package half of Pasta-Devs/Marinara-Engine#7429. ## Affected package `long-term-memory` (Long-Term Memory) 1.4.23 ## Expected behavior The recall query is embedded with input type `"query"` and indexed chunks with `"document"`, so the Engine applies the right prefix for the model. ## Actual behavior - `PackageEmbeddingAdapter.embed(texts, signal?)` has no input-type parameter (``[package-runtime.ts L109-L113](https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/package-runtime.ts#L109-L113)).`` - `embedLongTermMemoryTexts` calls `adapter.embed(batch, options.signal)` (```[embedding-adapter.ts L24 and L35](https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/embedding-adapter.ts#L24-L35)).``` - Recall embeds `[query]` through that same function ([retrieval.ts L213](````https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts#L213)),```` exactly as rebuild does for chunks ([rebuild.ts L135](`````https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/rebuild.ts#L135)).````` - Even after the Engine fix, LTM won't send the type until this change lands. ## Steps to reproduce 1. On the Engine, give the connection LTM uses an embedding model with a prefix profile, for example `intfloat/multilingual-e5-large`, or `nomic-embed-text` on Ollama. LTM uses the default connection, or the one set with Connections → apply to all agents. 2. Save a few memories and send chat messages until recall runs. 3. Inspect the texts sent to the embeddings endpoint. The recall query starts with `passage: ` (`search_document: ` for nomic) instead of `query: ` (`search_query: `). ## Environment - Marinara Engine version: 2.5.0 (`staging` at `ecd62a2e4678d82fae753dd19f0f15cfbe48bba0`) - Package version: 1.4.23 (`staging` at `11c8a563e7ef33b03442909814366f11330e1aad`) - Install type: source. Found by code inspection, not reproduced against a live provider. - OS + version: not applicable - Browser or app shell: not applicable ## Logs, screenshots, or video No logs, because the wrong prefix fails silently. Code references are above. ## Additional context ### Minimal fix 1. `package-runtime.ts`: `embed(texts: string[], signal?: AbortSignal, inputType?: "query" | "document"): Promise<number[][] | null>;` 2. `embedding-adapter.ts`: add `inputType?: "query" | "document"` to `MemoryRecallEmbeddingOptions`, and call `adapter.embed(batch, options.signal, options.inputType)` at both call sites. 3. `retrieval.ts` L213: `embedLongTermMemoryTexts([query], { ...input, embeddingAdapter, inputType: "query" })`. 4. `rebuild.ts` L135 can stay as it is, since the default is document, or pass `inputType: "document"` explicitly. - **No `spaceId` change and no reindex.** Stored vectors are already document embeddings. - **No `capabilityApi` bump.** Older Engines ignore the third positional argument. The fix takes effect on Engines that include Pasta-Devs/Marinara-Engine#7429. Keep it positional, not an options object: older Engines hand the second argument to `AbortSignal.any`, so an object there would throw. - **Regression** in `tests/long-term-memory-runtime.regression.ts`: a fake adapter records its third argument. Recall should send `"query"`, rebuild should send `"document"` (or `undefined`), and `spaceId` should stay unchanged. - Bump the package version and CHANGELOG as the repository requires. ### Who is affected - **Affected:** e5 and multilingual-e5, nomic-embed-text, and Hugging Face `snowflake-arctic-embed` v2 model IDs. - **Not affected:** the default built-in MiniLM, bge-m3, OpenAI and Gemini embedding models. Their profiles have no prefixes. ### Related - Pasta-Devs/Marinara-Engine#7429, the Engine host change this depends on. - #1303 (LTM doesn't register the Engine refresh hook) and #1304 (show LTM's embedding source and how to change it). - #1295, section 4. This doesn't address the default MiniLM being English-only; #1304 covers that. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:31 +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#662
No description provided.