[GH-ISSUE #1295] [Bug/Enhancement] LTM recall: Korean tokenization, short keyword filtering, and multilingual embedding support #658

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

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

Originally assigned to: @Promansis on GitHub.

Summary

I'd like to report several potential issues affecting Long-Term Memory (LTM) recall quality when using Korean or other non-English languages.

A Korean community member investigated LTM's retrieval behavior and shared a detailed technical analysis. I received permission to share the findings here.

I also reviewed the relevant source files in the staging branch.

The main concern is that valid memories may be stored successfully but become difficult to retrieve in Korean conversations, especially when semantic retrieval is unavailable or lexical matching fails.

This is separate from the extraction and subject-identity issues addressed in #1277.

1. Korean Keywords Shorter Than 3 Characters Are Filtered Out

Confirmed in source code.

File: keyword-extract.ts

The keyword normalization function contains:

if (normalized.length < 3) return null;

This removes tokens shorter than three characters.

Although this may be reasonable for filtering short English terms, many important Korean words and character names contain only two syllables.

Examples:

Korean keyword Meaning Result
반지 Ring Filtered
약속 Promise Filtered
비밀 Secret Filtered
서래 Character name Filtered
동쪽 다리 Eastern bridge Both tokens filtered
동쪽다리 Eastern bridge, no space Retained

For example, a memory may contain:

"서래는 무진에게 반지를 선물받았다."

If the extracted keywords are 서래, 무진, 반지, and 선물, all four are shorter than three characters and may be excluded from keyword indexing.

The memory itself is not deleted, but the keyword retrieval lane may lose important matching signals.

Suggested Improvement

  • Consider language-aware minimum token lengths.
  • Preserve meaningful two-syllable Korean nouns and character names.
  • Avoid applying English-oriented token length restrictions uniformly across writing systems.
  • Add regression tests using Korean names and short keywords.

2. BM25 Tokenization Does Not Account for Korean Particles or Morphology

Confirmed in source code.

File: bm25.ts

The current tokenizer uses:

const TOKEN_PATTERN = /[\p{L}\p{N}_]+/gu;

This supports Unicode characters but does not perform Korean morphological analysis or particle separation.

Consequently, semantically related forms can become different tokens.

Examples:

Query Stored memory Potential mismatch
반지를 반지 Particle suffix
서래가 서래 Subject particle
무진에게 무진 Dative particle
그림 선물 그림선물 Spacing difference

For example:

Query: "반지를 받았다"

Memory: "반지 선물"

The lexical tokenizer produces different tokens, even though both phrases may refer to the same event.

BM25 requires matching indexed terms, so Korean inflection and spacing differences can reduce lexical recall.

Other shared words may still allow a match; this does not mean every Korean query fails.

Suggested Improvement

  • Consider Korean-aware normalization or tokenization.
  • Support matching common Korean particle variations where appropriate.
  • Consider conservative fallback matching for compound words and spacing differences.
  • Preserve exact-name matching to avoid false positives.
  • Add regression tests for common Korean noun and particle combinations.

3. Graph Recall Depends on Lexical and Keyword Seeds

Confirmed in source code.

File: retrieval.ts

Graph recall uses seed notes selected from BM25 and keyword search results:

const seedNotes = Array.from(
  new Set([
    ...pickGraphSeedNotes(index, lexical, 5),
    ...pickGraphSeedNotes(index, keywords, 5)
  ])
);

The graph traversal itself supports linked memories, including incoming and outgoing links.

However, it needs initial seed memories.

If Korean lexical matching fails and short keywords are filtered out, the graph lane may have no relevant seed from which to begin traversal.

For example:

  1. A user asks about a ring previously given to a character.
  2. BM25 fails to match 반지를 with 반지.
  3. The two-syllable keyword 반지 is filtered out.
  4. The relevant memory may not become a graph seed.
  5. Related relationship or timeline memories may not receive graph-retrieval scores.

This is a cascading effect of the previous two issues rather than necessarily a separate graph implementation bug.

Semantic retrieval may still find the memory independently if suitable embeddings are available.

Suggested Improvement

Please consider whether graph recall should have alternative seed sources when lexical and keyword matching are weak, potentially including semantic retrieval results.

4. Multilingual Embedding Support and Configuration

Further verification requested.

The community analysis raised concerns about Korean semantic retrieval when LTM uses an English-oriented local embedding model.

The LTM source includes support for an embedding adapter, and package-runtime.ts resolves an adapter through the host runtime:

return (await runtime.resolveEmbeddings?.())
  ?? runtime.embeddings
  ?? null;

However, I have not independently confirmed:

  • Which embedding model is selected by default in the current Engine version.
  • Whether the default model reliably supports Korean semantic similarity.
  • Whether users can select an external embedding provider through the UI.
  • Whether Korean recall is significantly degraded with the default configuration.
  • Whether existing memories require reindexing after changing embedding models.

The original community report suggested that the default local model may not adequately support Korean, but I don't want to claim that Korean semantic scores are always zero without verifying the actual runtime behavior.

Suggested Investigation

Could you clarify:

  1. Which embedding model LTM uses by default.
  2. Whether multilingual embedding providers can already be configured through the Engine.
  3. Whether an LTM-specific embedding selection UI is planned or necessary.
  4. Whether changing embedding models triggers automatic vector reindexing.
  5. Whether Korean semantic retrieval has existing regression tests.

A configurable multilingual embedding provider could be especially useful for users running Korean, Japanese, Chinese, or mixed-language roleplay sessions.

5. Mixed-Language Recall

An additional concern is that some users have conversations in one language but store summaries or LTM memories in another.

For example:

  • Conversation: English
  • Summary and memory content: Korean
  • Memory keywords: Korean

Exact lexical matching between languages cannot reliably recover equivalent words.

Keyword matching may also become ineffective when the query and stored keywords use different languages.

In these cases, multilingual semantic retrieval becomes particularly important.

It would be helpful to document which retrieval components support cross-language matching and which require matching languages.

Expected Behavior

LTM should be able to retrieve relevant memories in Korean conversations without systematically losing important signals because of Korean word length, particles, or spacing.

Ideally:

  • Short Korean character names and meaningful keywords remain searchable.
  • Common particle variations do not completely prevent lexical retrieval.
  • Graph recall remains useful when lexical matching is weak.
  • Users can reliably use a multilingual embedding model.
  • Mixed-language workflows are supported or their limitations are clearly documented.

Relevant Source Files

  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-extract.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/bm25.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/graph.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/embedding-adapter.ts
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/package-runtime.ts

Testing Status

The short-keyword filtering, Unicode lexical tokenization, and graph-seed dependency were verified through source inspection.

I have not yet performed a full end-to-end recall benchmark with controlled Korean conversations. The examples above illustrate likely failure conditions based on the implementation, rather than measured retrieval failure rates.

The default embedding model's Korean performance also remains unverified.

I'd appreciate confirmation of these behaviors and any guidance on improving multilingual recall.

Thank you for your continued work on LTM and for considering feedback from Korean users!

Originally created by @tlsiddl on GitHub (Oct 10, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1295 Originally assigned to: @Promansis on GitHub. ## Summary I'd like to report several potential issues affecting Long-Term Memory (LTM) recall quality when using Korean or other non-English languages. A Korean community member investigated LTM's retrieval behavior and shared a detailed technical analysis. I received permission to share the findings here. I also reviewed the relevant source files in the `staging` branch. The main concern is that **valid memories may be stored successfully but become difficult to retrieve in Korean conversations**, especially when semantic retrieval is unavailable or lexical matching fails. This is separate from the extraction and subject-identity issues addressed in #1277. ## 1. Korean Keywords Shorter Than 3 Characters Are Filtered Out **Confirmed in source code.** File: `keyword-extract.ts` The keyword normalization function contains: ```ts if (normalized.length < 3) return null; ``` This removes tokens shorter than three characters. Although this may be reasonable for filtering short English terms, many important Korean words and character names contain only two syllables. Examples: | Korean keyword | Meaning | Result | |---|---|---| | 반지 | Ring | Filtered | | 약속 | Promise | Filtered | | 비밀 | Secret | Filtered | | 서래 | Character name | Filtered | | 동쪽 다리 | Eastern bridge | Both tokens filtered | | 동쪽다리 | Eastern bridge, no space | Retained | For example, a memory may contain: "서래는 무진에게 반지를 선물받았다." If the extracted keywords are `서래`, `무진`, `반지`, and `선물`, all four are shorter than three characters and may be excluded from keyword indexing. The memory itself is not deleted, but the keyword retrieval lane may lose important matching signals. ### Suggested Improvement - Consider language-aware minimum token lengths. - Preserve meaningful two-syllable Korean nouns and character names. - Avoid applying English-oriented token length restrictions uniformly across writing systems. - Add regression tests using Korean names and short keywords. ## 2. BM25 Tokenization Does Not Account for Korean Particles or Morphology **Confirmed in source code.** File: `bm25.ts` The current tokenizer uses: ```ts const TOKEN_PATTERN = /[\p{L}\p{N}_]+/gu; ``` This supports Unicode characters but does not perform Korean morphological analysis or particle separation. Consequently, semantically related forms can become different tokens. Examples: | Query | Stored memory | Potential mismatch | |---|---|---| | 반지를 | 반지 | Particle suffix | | 서래가 | 서래 | Subject particle | | 무진에게 | 무진 | Dative particle | | 그림 선물 | 그림선물 | Spacing difference | For example: Query: "반지를 받았다" Memory: "반지 선물" The lexical tokenizer produces different tokens, even though both phrases may refer to the same event. BM25 requires matching indexed terms, so Korean inflection and spacing differences can reduce lexical recall. Other shared words may still allow a match; this does not mean every Korean query fails. ### Suggested Improvement - Consider Korean-aware normalization or tokenization. - Support matching common Korean particle variations where appropriate. - Consider conservative fallback matching for compound words and spacing differences. - Preserve exact-name matching to avoid false positives. - Add regression tests for common Korean noun and particle combinations. ## 3. Graph Recall Depends on Lexical and Keyword Seeds **Confirmed in source code.** File: `retrieval.ts` Graph recall uses seed notes selected from BM25 and keyword search results: ```ts const seedNotes = Array.from( new Set([ ...pickGraphSeedNotes(index, lexical, 5), ...pickGraphSeedNotes(index, keywords, 5) ]) ); ``` The graph traversal itself supports linked memories, including incoming and outgoing links. However, it needs initial seed memories. If Korean lexical matching fails and short keywords are filtered out, the graph lane may have no relevant seed from which to begin traversal. For example: 1. A user asks about a ring previously given to a character. 2. BM25 fails to match `반지를` with `반지`. 3. The two-syllable keyword `반지` is filtered out. 4. The relevant memory may not become a graph seed. 5. Related relationship or timeline memories may not receive graph-retrieval scores. This is a cascading effect of the previous two issues rather than necessarily a separate graph implementation bug. Semantic retrieval may still find the memory independently if suitable embeddings are available. ### Suggested Improvement Please consider whether graph recall should have alternative seed sources when lexical and keyword matching are weak, potentially including semantic retrieval results. ## 4. Multilingual Embedding Support and Configuration **Further verification requested.** The community analysis raised concerns about Korean semantic retrieval when LTM uses an English-oriented local embedding model. The LTM source includes support for an embedding adapter, and `package-runtime.ts` resolves an adapter through the host runtime: ```ts return (await runtime.resolveEmbeddings?.()) ?? runtime.embeddings ?? null; ``` However, I have not independently confirmed: - Which embedding model is selected by default in the current Engine version. - Whether the default model reliably supports Korean semantic similarity. - Whether users can select an external embedding provider through the UI. - Whether Korean recall is significantly degraded with the default configuration. - Whether existing memories require reindexing after changing embedding models. The original community report suggested that the default local model may not adequately support Korean, but I don't want to claim that Korean semantic scores are always zero without verifying the actual runtime behavior. ### Suggested Investigation Could you clarify: 1. Which embedding model LTM uses by default. 2. Whether multilingual embedding providers can already be configured through the Engine. 3. Whether an LTM-specific embedding selection UI is planned or necessary. 4. Whether changing embedding models triggers automatic vector reindexing. 5. Whether Korean semantic retrieval has existing regression tests. A configurable multilingual embedding provider could be especially useful for users running Korean, Japanese, Chinese, or mixed-language roleplay sessions. ## 5. Mixed-Language Recall An additional concern is that some users have conversations in one language but store summaries or LTM memories in another. For example: - Conversation: English - Summary and memory content: Korean - Memory keywords: Korean Exact lexical matching between languages cannot reliably recover equivalent words. Keyword matching may also become ineffective when the query and stored keywords use different languages. In these cases, multilingual semantic retrieval becomes particularly important. It would be helpful to document which retrieval components support cross-language matching and which require matching languages. ## Expected Behavior LTM should be able to retrieve relevant memories in Korean conversations without systematically losing important signals because of Korean word length, particles, or spacing. Ideally: - Short Korean character names and meaningful keywords remain searchable. - Common particle variations do not completely prevent lexical retrieval. - Graph recall remains useful when lexical matching is weak. - Users can reliably use a multilingual embedding model. - Mixed-language workflows are supported or their limitations are clearly documented. ## Relevant Source Files - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-extract.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/bm25.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/graph.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/embedding-adapter.ts` - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/package-runtime.ts` ## Testing Status The short-keyword filtering, Unicode lexical tokenization, and graph-seed dependency were verified through source inspection. I have not yet performed a full end-to-end recall benchmark with controlled Korean conversations. The examples above illustrate likely failure conditions based on the implementation, rather than measured retrieval failure rates. The default embedding model's Korean performance also remains unverified. I'd appreciate confirmation of these behaviors and any guidance on improving multilingual recall. Thank you for your continued work on LTM and for considering feedback from Korean users!
Author
Owner

@SpicyMarinara commented on GitHub (Oct 10, 2026):

@Promansis

<!-- gh-comment-id:6097416585 --> @SpicyMarinara commented on GitHub (Oct 10, 2026): @Promansis
Author
Owner

@Promansis commented on GitHub (Oct 10, 2026):

Done :) @tlsiddl please let me know how that goes so far, I have another set of work ready to go for the embedding stuff but it's taking a bit longer. Interested to see if 1.4.23 helps though

<!-- gh-comment-id:6099830821 --> @Promansis commented on GitHub (Oct 10, 2026): Done :) @tlsiddl please let me know how that goes so far, I have another set of work ready to go for the embedding stuff but it's taking a bit longer. Interested to see if 1.4.23 helps though
Author
Owner

@tlsiddl commented on GitHub (Oct 12, 2026):

Thanks again for the fix in #1295!

I noticed one remaining edge case involving single-character Korean names.

In the current staging code:

keyword-extract.ts

const minimumLength = isHangulToken(candidate) ? 2 : 3;

bm25.ts

if (token.length <= 1) continue;

These conditions still exclude single-character Korean tokens.

Some Korean character and persona names consist of only one Hangul syllable (e.g., 온, 린). These are meaningful proper nouns, but they are currently discarded during keyword extraction and BM25 tokenization.

Would it be possible to preserve single-syllable Korean character/persona names, perhaps through exact-name matching or another targeted exception, without allowing excessive noise from arbitrary single-character tokens?

This is a follow-up to #1295 rather than a separate issue.

Thanks!

<!-- gh-comment-id:6119049038 --> @tlsiddl commented on GitHub (Oct 12, 2026): Thanks again for the fix in #1295! I noticed one remaining edge case involving single-character Korean names. In the current staging code: keyword-extract.ts ``` const minimumLength = isHangulToken(candidate) ? 2 : 3; ``` bm25.ts ``` if (token.length <= 1) continue; ``` These conditions still exclude single-character Korean tokens. Some Korean character and persona names consist of only one Hangul syllable (e.g., 온, 린). These are meaningful proper nouns, but they are currently discarded during keyword extraction and BM25 tokenization. Would it be possible to preserve single-syllable Korean character/persona names, perhaps through exact-name matching or another targeted exception, without allowing excessive noise from arbitrary single-character tokens? This is a follow-up to #1295 rather than a separate issue. Thanks!
Author
Owner

@tlsiddl commented on GitHub (Oct 12, 2026):

One more detail: the particle-stripping helper has the same minimum-length restriction.

hangul-lexical.ts (stripHangulParticle):

for (let length = 1; length <= 4 && value.length - length >= 2; length += 1)

This prevents single-syllable names with Korean particles, such as 린이, 린에게, and 온은, from being normalized to 린 and 온.

This is particularly important in Korean roleplay, where character names frequently appear with grammatical particles.

Example (lexical retrieval only):

  • Stored memory: 린이 웃었다
  • Query: 린은 뭐 했지?
  • The name tokens do not match in keyword or BM25 retrieval, potentially preventing graph-seed selection as well.

Simply relaxing the minimum token lengths in keyword-extract.ts and bm25.ts would not fully resolve this issue.

Suggestion: When the remaining stem matches a known character or persona name, allow a single-syllable stem in stripHangulParticle and preserve it during keyword extraction and BM25 tokenization.

This would help support short Korean proper names without broadly enabling noisy single-character matches.

<!-- gh-comment-id:6119141623 --> @tlsiddl commented on GitHub (Oct 12, 2026): One more detail: the particle-stripping helper has the same minimum-length restriction. hangul-lexical.ts (stripHangulParticle): ``` for (let length = 1; length <= 4 && value.length - length >= 2; length += 1) ``` This prevents single-syllable names with Korean particles, such as 린이, 린에게, and 온은, from being normalized to 린 and 온. This is particularly important in Korean roleplay, where character names frequently appear with grammatical particles. Example (lexical retrieval only): * Stored memory: 린이 웃었다 * Query: 린은 뭐 했지? * The name tokens do not match in keyword or BM25 retrieval, potentially preventing graph-seed selection as well. Simply relaxing the minimum token lengths in keyword-extract.ts and bm25.ts would not fully resolve this issue. Suggestion: When the remaining stem matches a known character or persona name, allow a single-syllable stem in stripHangulParticle and preserve it during keyword extraction and BM25 tokenization. This would help support short Korean proper names without broadly enabling noisy single-character matches.
Author
Owner

@tlsiddl commented on GitHub (Oct 15, 2026):

Hi @Promansis, thanks for the recent Korean name matching improvements!

Could you also take a look at the one-syllable Korean name issue I mentioned earlier?

For example:

  • Stored memory: 린이 웃었다
  • Query: 린은 뭐 했지?
  • Expected: 린 should be recognized as the same character name.

The current particle-stripping logic appears to require at least two characters to remain, so one-syllable names may still be excluded from keyword/BM25 matching.

Does the recent fix cover this case, or would it need a separate change?

Thanks!

<!-- gh-comment-id:6183661674 --> @tlsiddl commented on GitHub (Oct 15, 2026): Hi @Promansis, thanks for the recent Korean name matching improvements! Could you also take a look at the one-syllable Korean name issue I mentioned earlier? For example: * Stored memory: 린이 웃었다 * Query: 린은 뭐 했지? * Expected: 린 should be recognized as the same character name. The current particle-stripping logic appears to require at least two characters to remain, so one-syllable names may still be excluded from keyword/BM25 matching. Does the recent fix cover this case, or would it need a separate change? Thanks!
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#658
No description provided.