Skip to content

fix: skip translation memory lookup for texts over 1000 characters - #4098

Open
dkrizan wants to merge 1 commit into
mainfrom
dkrizan/tm-long-text
Open

dkrizan wants to merge 1 commit into
mainfrom
dkrizan/tm-long-text

Conversation

@dkrizan

@dkrizan dkrizan commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Translation memory suggestions now skip source texts longer than 1000 characters.

Why:

  • The TM lookup compares the source text with all translations by trigram similarity. Its cost grows with the length of the text. On a database with millions of translations, a text over 1000 characters (for example a help article with HTML) took more than 40 seconds in my tests.
  • Tolgee AI loads TM examples for its prompt through the same lookup, so it waited too. For such keys the editor showed neither TM suggestions nor the AI translation.

Changes:

  • AbstractTranslationMemoryService.getSuggestions and getSuggestionsList return no results when the base text is longer than MAX_SUGGESTION_SOURCE_LENGTH (1000). This covers the TM panel and the TM examples in Tolgee AI prompts.
  • Auto-translation from TM is not affected, it only looks for exact matches.

Not in this PR:

  • Texts under the limit can still be slow, because the lookup searches the trigram index over all translations. A follow-up could first limit the candidates to the base languages of the projects assigned to the TMs, and filter them by length.

Summary by CodeRabbit

  • Bug Fixes
    • Translation memory suggestions and examples are now skipped when the source text exceeds 1,000 characters. Shorter source text continues to use the existing suggestion lookup.

Trigram matching cost grows with the source length. With long texts
(e.g. HTML help articles) the TM suggestion query could run for minutes,
so the TM panel never loaded and Tolgee AI, which waits for TM examples,
returned nothing.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The translation-memory suggestion methods now return empty results when source text exceeds 1000 characters. New test data and tests cover both the paginated and list-returning methods.

Changes: Long-source suggestions

Layer / File(s) Summary
Suggestion length cutoff
backend/data/src/main/kotlin/io/tolgee/service/translation/AbstractTranslationMemoryService.kt
A shared constant sets the source-text limit to 1000 characters. Both suggestion methods return empty results above this limit.
Long-source test coverage
backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/TranslationMemoryTestData.kt, backend/app/src/test/kotlin/io/tolgee/service/translationMemory/TranslationMemoryLongTextTest.kt
The test data builder adds a key with a supplied source string. Tests verify that both suggestion methods return empty results for source text over the limit.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: bdshadow

Merge Risk: Minimal · up to ace39

This change skips translation-memory suggestions for source text over 1000 characters to avoid slow similarity searches. Texts at or below the limit behave as before, and exact-match auto-translation is unaffected. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: skip translation memory lookup for texts over 1000 characters" matches the main change. AbstractTranslationMemoryService.getSuggestions and getSuggestionsList return an empty result wh…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: skip translation memory lookup for texts over 1000 characters" matches the main change. AbstractTranslationMemoryService.getSuggestions and getSuggestionsList return an empty result when the source text exceeds MAX_SUGGESTION_SOURCE_LENGTH (1000). The PR objectives confirm the same goal: skip TM suggestions above 1,000 characters to avoid slow trigram searches. The other changes (new test class, test data helper addLongSourceKey) support this behavior change. The title is concise, specific, and follows the conventional-commit style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1f5ee6b and ace39f8.

Files selected for processing: 3

  • backend/app/src/test/kotlin/io/tolgee/service/translationMemory/TranslationMemoryLongTextTest.kt
  • backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/TranslationMemoryTestData.kt
  • backend/data/src/main/kotlin/io/tolgee/service/translation/AbstractTranslationMemoryService.kt

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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