Fix: Complete Multi-Language Support for React-to-Me (#104) - #140
Fix: Complete Multi-Language Support for React-to-Me (#104)#140bleedblack1 wants to merge 1 commit into
Conversation
f30911e to
7206ada
Compare
Adam pushed back that 0/10 looked too low, and he was right. That number came from running BM25 directly on the polluted string. BM25 never sees that string: HybridRetriever expands the query into four LLM-generated alternates and appends the original last, so four of five queries reach BM25 clean and the fusion recovers most of the damage. Measured through the whole retriever, 20 of 40 and 21 of 40 documents survive. Half the retrieved context silently differing for non-English users is still reason enough to reject appending the instruction to `input`. But the honest number is half, not all, and the spec now argues from it. The review that produced the wrong number checked whether the claim was true without checking whether the test measured the product -- the same failure evaluator.py had four days ago. Recorded in the checklist, because an adversarial review has to attack the measurement as well as the claim. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thank you @bleedblack1 — and sorry this sat so long. This is implemented in #205, and the instruction wording is yours, kept nearly verbatim in You got the hard part right, and it is the part that is easy to miss: the retrieved context is English and must stay English, and scientific nomenclature inside the answer must not be translated either. You also picked the right profile. React-to-Me was the one with the gap — Cross-Database already worked, which made it easy to assume the feature existed. What I changed, and why — with the numberThe one thing I did not take is where the instruction goes. Your version appends it to query = f"{query}\n\n[CRITICAL INSTRUCTION: ...]"
result = await self.reactome_rag.ainvoke({"input": query, ...})
retrieval_docs = (lambda x: x["input"]) | retrieverSo those 61 words become part of the BM25 query and the embedded vector, and they also reach the query expansion that runs in front of both. I measured it rather than assuming. Through the whole retriever, appending the block to an English question leaves 20 of 40 and 21 of 40 documents surviving — about half the retrieved context silently changes, for exactly the users the feature is meant to help. (My first measurement said 0 of 10, which was wrong: that tested BM25 directly, and BM25 never sees the raw string because the expander rewrites the query first. Adam pushed back that the number looked too low, and he was right. Recording it because you might reasonably have wondered where a dramatic figure came from.) In #205 the language is a separate prompt variable, so The full reasoning is in |
This PR resolves an issue where the React-to-Me chatbot always responded in English, even when users submitted questions in other languages.
The root cause was that the detected language from the language detection pipeline was never passed to the final generation step. As a result, the LLM only received English inputs and produced English outputs.
This change ensures the chatbot:
The fix maintains retrieval quality while enabling full multilingual response support.
Problem
The chatbot pipeline already contained language detection and query rephrasing, but the information flow stopped before the generation stage.
Current behavior:
Because the model receives English queries and English context, responses are always generated in English.
Solution
The fix introduces an English-for-Search, Native-for-Response strategy.
Pipeline after this change:
Retrieval continues to use English queries for optimal embedding similarity, while the response language follows the detected language.
Implementation Details
1. React-to-Me Profile Fix
File updated:
The generation step now retrieves the detected language and injects a response instruction when the language is not English.
Example logic:
This instruction is appended to the query before invoking the RAG chain.
This approach avoids modifying the RAG chain architecture while ensuring the LLM follows the correct output language.
2. Prompt Reinforcement
File updated:
The system prompt now explicitly acknowledges that language instructions may appear in the query and must be followed.
This acts as a secondary safeguard to ensure consistent multilingual responses.
3. Rephrase Task Clarification
File updated:
The prompt documentation now explains the rationale behind always returning English queries.
This clarification helps future contributors understand that English queries are required because:
4. Cross-Database Summarization Improvements
File updated:
Updates include:
The updated prompt enforces consistent language output while preserving scientific terminology.
Scientific Terminology Preservation
The LLM is instructed not to translate scientific identifiers, including:
Examples remain unchanged:
This ensures scientific accuracy across languages.
Impact
English users
Non-English users
Retrieval system
Streaming responses
Result
This change enables true multilingual responses in the React-to-Me chatbot while preserving the existing RAG retrieval architecture and maintaining search accuracy.
Fix: #104