Skip to content

Clarify Chinese query segmentation scope - #1014

Closed
candy-Tong wants to merge 1 commit into
Graphify-Labs:v8from
candy-Tong:feat/cjk-query-segmentation
Closed

Clarify Chinese query segmentation scope#1014
candy-Tong wants to merge 1 commit into
Graphify-Labs:v8from
candy-Tong:feat/cjk-query-segmentation

Conversation

@candy-Tong

@candy-Tong candy-Tong commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rebase the query tokenization fix onto the latest v8 branch (68863a7).
  • Keep the scope explicitly Chinese-only by renaming the CJK helpers and optional extra to Chinese.
  • Cache the optional jieba import at module level.
  • Segment Chinese query terms only when jieba is available; when jieba is unavailable, keep the original query term unchanged.
  • Use real jieba behavior in optional segmentation tests instead of mocking the tokenizer.

Fixes #962
Closes #1013

Tests

  • uv run --with pytest pytest tests/test_serve.py tests/test_query_cli.py tests/test_benchmark.py — 66 passed, 2 skipped
  • uv run --with pytest --with jieba pytest tests/test_serve.py -k "chinese or non_chinese" — 5 passed, 1 skipped
  • graphify update .

@safishamsi safishamsi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good contribution — CJK segmentation is a real gap and the jieba + bigram fallback design is sound. Two small things before merge: (1) _has_cjk() only covers U+4E00–U+9FFF (Chinese), so Japanese (Hiragana/Katakana) and Korean (Hangul) users get no segmentation — either broaden the ranges or rename to _has_chinese so the scope is honest; (2) jieba is imported on every _segment_cjk call — cache it at module level with a try/except guard. Could you fix those and open a fresh PR against v8?

@safishamsi

Copy link
Copy Markdown
Collaborator

Good contribution — CJK segmentation is a real gap and the jieba + bigram fallback design is sound. Two small things before merge: (1) _has_cjk() only covers U+4E00–U+9FFF (Chinese), so Japanese (Hiragana/Katakana) and Korean (Hangul) users get no segmentation — either broaden the ranges or rename to _has_chinese so the scope is honest; (2) jieba is imported on every _segment_cjk call — cache it at module level with a try/except guard. Could you fix those and open a fresh PR against v8?

@candy-Tong

Copy link
Copy Markdown
Contributor Author

Okay, I'll revise it and resubmit the PR later.

@candy-Tong
candy-Tong force-pushed the feat/cjk-query-segmentation branch from fc13be6 to 951eebe Compare May 26, 2026 09:35
@candy-Tong candy-Tong changed the title feat: add CJK word segmentation for graph query Clarify Chinese query segmentation scope May 26, 2026
@candy-Tong
candy-Tong force-pushed the feat/cjk-query-segmentation branch 4 times, most recently from d8282a7 to 794b087 Compare May 26, 2026 09:51
Keep Graphify query segmentation focused on Chinese terms: rename the CJK helpers and extra to Chinese scope, cache the optional jieba import at module load, and keep the original query term when jieba is unavailable.

Constraint: Reviewer asked either to broaden Hiragana/Katakana/Hangul support or rename CJK helpers; user chose Chinese-only because Japanese segmentation accuracy is uncertain.

Constraint: User requested no bigram fallback; without jieba, Chinese query terms are kept whole rather than segmented.

Rejected: Broaden to Japanese and Korean segmentation | jieba is Chinese-oriented and the user explicitly limited scope to Chinese.

Rejected: Character bigram fallback | user prefers no segmentation when jieba is unavailable.

Rejected: Mock jieba segmentation in tests | use real jieba behavior for optional integration coverage and skip no-jieba assertions when jieba is installed.

Confidence: high

Scope-risk: narrow

Directive: Do not label this path as CJK unless Hiragana/Katakana/Hangul segmentation is intentionally supported and tested.

Tested: uv run --with pytest pytest tests/test_serve.py tests/test_query_cli.py tests/test_benchmark.py (66 passed, 2 skipped)

Tested: uv run --with pytest --with jieba pytest tests/test_serve.py -k "chinese or non_chinese" (5 passed, 1 skipped)

Tested: graphify update .

Not-tested: Full test suite.

Co-authored-by: OmX <omx@oh-my-codex.dev>
@candy-Tong
candy-Tong force-pushed the feat/cjk-query-segmentation branch from 794b087 to fc0224c Compare May 26, 2026 09:54
@safishamsi

Copy link
Copy Markdown
Collaborator

The issues raised here (rename _has_cjk_has_chinese, cache jieba at module level) were addressed in #1026 which has already been merged and shipped in v0.8.19. Thanks @candy-Tong — no need to resubmit, this is now resolved.

@safishamsi safishamsi closed this May 26, 2026
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.

feat: add CJK word segmentation for graph query Is graphify will filter string that length < 2?

2 participants