Memory search splits words at ZWJ/ZWNJ and matches unrelated Bengali and Hindi text
メンテナーはふだん 3 日以内に返信
評価
この issue はまだ評価されていません。
説明
🔴 Required Information
Describe the Bug:
Memory search splits a word at a zero-width joiner (ZWJ, U+200D) or zero-width non-joiner (ZWNJ, U+200C), so it also returns text that only shares the first letter of the word. Both SqliteMemoryService and InMemoryMemoryService do this, including with the combining-mark fix in #8169.
Some Indic words use these characters to pick a glyph form. In Bengali, র্যাব (RAB) writes the ra-phala with a ZWJ. In Hindi, क्ष uses a ZWNJ to show the half form instead of the ligature क्ष. A search for র্যাব also returns আমার নাম রাজ ("My name is Raj"), and a search for क्ष also returns मैं क्षमा माँगता हूँ ("I apologise").
ZWJ and ZWNJ are format characters (category Cf), not marks, so the tokenizer does not treat them as word characters:
https://github.com/google/adk-python/blob/c6586f19ab8a2bb8b53e70041633b10858d9902e/src/google/adk/memory/_sqlite_memory_service.py#L595-L613
Both services turn র্যাব into the tokens র and যাব (the virama left at the start of the second piece is dropped as an orphan mark), and র alone matches রাজ. क्ष becomes क् and ष, and क् matches क्षमा.
This came up in #8168, where we agreed to track it separately because both services need the same change to stay consistent.
Steps to Reproduce:
- Install google-adk 2.14.1, or use main at c6586f1.
- Run the script under "Minimal Reproduction Code".
Expected Behavior:
Each query returns only the sentence that contains the word:
InMemory 'র্যাব' ['র্যাব এসেছে']
InMemory 'क्ष' ['मैं क्ष लिखता हूँ']
Sqlite 'র্যাব' ['র্যাব এসেছে']
Sqlite 'क्ष' ['मैं क्ष लिखता हूँ']
Observed Behavior:
InMemory 'র্যাব' ['র্যাব এসেছে', 'আমার নাম রাজ']
InMemory 'क्ष' ['मैं क्ष लिखता हूँ', 'मैं क्षमा माँगता हूँ']
Sqlite 'র্যাব' ['র্যাব এসেছে', 'আমার নাম রাজ']
Sqlite 'क्ष' ['मैं क्ष लिखता हूँ', 'मैं क्षमा माँगता हूँ']
The result is the same on main at c6586f1 and on the #8169 branch.
Environment Details:
- ADK Library Version (pip show google-adk): 2.14.1 (main at c6586f1)
- 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:
No. Both services have always behaved this way.
Additional Context:
One option is to treat ZWJ and ZWNJ as word characters when they are between two word characters, in both tokenizers. A ZWJ at the start or end of a run would still be dropped, so emoji ZWJ sequences such as 👨👩👧 do not turn into a ZWJ-only token that matches every emoji sequence.
I'm happy to send a PR for both services once #8169 is merged, if this approach sounds right.
Minimal Reproduction Code:
import asyncio
import tempfile
from google.adk.events.event import Event
from google.adk.memory import InMemoryMemoryService
from google.adk.memory import SqliteMemoryService
from google.adk.sessions.session import Session
from google.genai import types
ZWJ, ZWNJ = "", ""
TEXTS = [
f"র{ZWJ}্যাব এসেছে", # Bengali: "RAB has come" (ra-phala written with ZWJ)
"আমার নাম রাজ", # Bengali: "My name is Raj"
f"मैं क्{ZWNJ}ष लिखता हूँ", # Hindi: "I write क्ष" (half form with ZWNJ)
"मैं क्षमा माँगता हूँ", # Hindi: "I apologise"
]
QUERIES = [f"র{ZWJ}্যাব", f"क्{ZWNJ}ष"]
async def main():
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)
],
)
services = {
"InMemory": InMemoryMemoryService(),
"Sqlite": SqliteMemoryService(f"{tempfile.mkdtemp()}/memory.db"),
}
for name, service in services.items():
await service.add_session_to_memory(session)
for query in QUERIES:
result = await service.search_memory(
app_name="app", user_id="user", query=query
)
print(name, ascii(query), [m.content.parts[0].text for m in result.memories])
await services["Sqlite"].close()
asyncio.run(main())
How often has this issue occurred?:
- Always (100%)
- 主要言語
- Python
- スター
- 22.3k
- フォーク
- 4.4k
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vllm-project/vllm#70030 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TigreGotico/tugaphone#408 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
gke-labs/kube-agents#7308 ·
メンテナーはふだん 1 日以内に返信
-
t: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
chore
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
lugassawan/swe-workbench#841 ·