Conversation
TenzDelek
commented
Apr 1, 2026
| if target_language: | ||
| with SessionLocal() as db_session: | ||
| for idx, source_text in enumerate(prompt): | ||
| exact = find_exact_match( |
Member
Author
There was a problem hiding this comment.
first try to find exact match with the input, if matched ignore the llm step
TenzDelek
commented
Apr 1, 2026
| tm_hits[idx] = exact.target_text | ||
| continue | ||
|
|
||
| rows = find_fuzzy_matches( |
Member
Author
There was a problem hiding this comment.
if fails then we fuzzy match with the input
Member
Author
There was a problem hiding this comment.
here the input still go under llm translation
TenzDelek
commented
Apr 1, 2026
| assistant_id, prompt, target_language | ||
| ) | ||
|
|
||
| if not texts_for_llm: |
Member
Author
There was a problem hiding this comment.
if true, that means exact match successes so we return it without the need to call the llm
TenzDelek
commented
Apr 1, 2026
| ).first() | ||
|
|
||
|
|
||
| def find_fuzzy_matches( |
Member
Author
There was a problem hiding this comment.
fuzzy match logic generated via opus
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
Add Translation Memory (TM) system to optimize translation workflows by caching and reusing previous translations. The system provides both exact matching for instant retrieval and fuzzy matching using PostgreSQL's trigram similarity to surface relevant prior translations, significantly reducing LLM API calls and improving response times for repeated content.