InMemoryMemoryService search matches unrelated Thai and Hindi text because \w splits words at combining marks
維護者通常 3 天內回覆
評估
研究方向
Read the tokenizer in src/google/adk/memory/in_memory_memory_service.py (the re.findall(r'\w+', ...) at lines 49-52 and the tokenization at line 71), then compare it with the combining-mark handling in src/google/adk/memory/_sqlite_memory_service.py around lines 595-598, which already carries the intended behaviour. Run the issue's minimal reproduction script against both services to confirm they diverge, and port the SQLite tokenization. Done means the reproduction prints only the matching sentence for ข้าว and हिंदी and the memory tests for both services agree. Note the reporter has an open pull request (#8169) for this, so coordinate before starting.
由索引模型根據 Issue 內容生成。
描述
🔴 Required Information
Describe the Bug:
InMemoryMemoryService.search_memory returns memories that don't contain the query word when the text uses combining marks: Thai vowel and tone marks, or Devanagari vowel signs (Hindi). A search for ข้าว ("rice") also returns ขอบคุณครับ ("thank you"), and a search for हिंदी ("Hindi") also returns a sentence about Hyderabad.
The words are extracted with re.findall(r'\w+', ...), and \w doesn't match combining marks, so ข้าว is split into ข and าว:
https://github.com/google/adk-python/blob/d05e482038bdbb226c3a1179550cf83bd8fcbefb/src/google/adk/memory/in_memory_memory_service.py#L49-L52
https://github.com/google/adk-python/blob/d05e482038bdbb226c3a1179550cf83bd8fcbefb/src/google/adk/memory/in_memory_memory_service.py#L71
Non-ASCII query words are also matched as substrings of the event text, so a piece like ข is found inside unrelated words. SqliteMemoryService already treats combining marks as part of a word, with a comment about this exact example:
https://github.com/google/adk-python/blob/d05e482038bdbb226c3a1179550cf83bd8fcbefb/src/google/adk/memory/_sqlite_memory_service.py#L595-L598
The in-memory service doesn't have that change, so the two services return different results for the same data.
Steps to Reproduce:
- Install google-adk 2.14.1, or use main at d05e482.
- Run the script under "Minimal Reproduction Code". It stores four short Thai and Hindi sentences and searches for ข้าว and हिंदी.
Expected Behavior:
Only the sentence that contains the word, which is what SqliteMemoryService returns for the same data:
ข้าว ['ข้าวผัดอร่อยมาก']
हिंदी ['मुझे हिंदी पसंद है']
Observed Behavior:
ข้าว ['ข้าวผัดอร่อยมาก', 'ขอบคุณครับ']
हिंदी ['मुझे हिंदी पसंद है', 'मैं हैदराबाद में रहता हूँ']
Environment Details:
- ADK Library Version (pip show google-adk): 2.14.1 (main at d05e482)
- Desktop OS: Linux
- Python Version (python -V): 3.13.16
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A, no model is called.
🟡 Optional Information
Regression:
Not that I know of. I only tried 2.14.1 and main.
Additional Context:
The fix I have in mind is to tokenize the same way the SQLite service does: treat combining marks as word characters, and drop a mark that has no letter before it, such as the emoji variation selector U+FE0F.
I'd like to fix this myself. I have the change and the tests ready, and I'll open a PR that links to this issue.
Minimal Reproduction Code:
import asyncio
from google.adk.events.event import Event
from google.adk.memory import InMemoryMemoryService
from google.adk.sessions.session import Session
from google.genai import types
TEXTS = [
"ข้าวผัดอร่อยมาก", # "The fried rice is delicious"
"ขอบคุณครับ", # "Thank you"
"मुझे हिंदी पसंद है", # "I like Hindi"
"मैं हैदराबाद में रहता हूँ", # "I live in Hyderabad"
]
async def main():
service = InMemoryMemoryService()
session = Session(
app_name="app",
user_id="user",
id="session",
last_update_time=0,
events=[
Event(
id=f"event-{i}",
invocation_id="inv",
author="user",
timestamp=i,
content=types.Content(parts=[types.Part(text=text)]),
)
for i, text in enumerate(TEXTS)
],
)
await service.add_session_to_memory(session)
for query in ["ข้าว", "हिंदी"]: # "rice", "Hindi"
result = await service.search_memory(
app_name="app", user_id="user", query=query
)
print(query, [m.content.parts[0].text for m in result.memories])
asyncio.run(main())
How often has this issue occurred?:
- Always (100%)
- 主要語言
- Python
- 星號
- 22.3k
- 分支
- 4.4k
- 平均合併
- 1 天 2 小時
- 30 天內合併 PR
- 6
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
google/adk-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
google/adk-python#8360 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
google/adk-python#8359 ·
維護者通常 3 天內回覆
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 於 10 天前認領。 未關閉models
難度 1/5 1 小時以內 新手友好度 65/100
google/adk-python#8129 · 2 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 於 14 天前認領。 未關閉tools
難度 2/5 1-3 小時 新手友好度 75/100
google/adk-python#8064 · 4 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 於 17 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 88/100
google/adk-python#8024 · 1 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
查看 google/adk-python 的全部 Issue
相似的 Issue
-
🧫10장-투향
難度 2/5 1-3 小時 新手友好度 65/100
hyunjimoon/golden-cage-book#188 ·
-
agent/scanner bug stage/010-actionable
難度 1/5 1 小時以內 新手友好度 88/100
torch-spyre/spyre-inference#1812 ·
維護者通常 1 天內回覆
-
Bug: fenced drafts inside <think> tags break parsing or are returned instead of the answer可能已有人在做 @aad1tyaaaaa 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google/langextract#639 ·
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Update autodoc routing docs for relative in-repo lock uses可能已有人在做 @github-actions 今天認領。 未關閉
難度 1/5 1-3 小時 新手友好度 87/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆