Repository navigation
Commit a133c8a
fix(knowledge): the keyword leg keeps the letters and numbers of the CJK symbols block inside a term (#38566)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XDXvJPPtrTGfdDYhWWpihq5)_
Part of #38411. This PR takes item 4 of the card's remaining list (the
U+3000–303F nit from the review of the previous slice). Items 2 and 3
(the BrightRule model-graded eval and the larger per-leg pool) stay open
on the card.
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:知识检索里,中日文提问中的「〻」、假名重复符「〱」到「〵」、「〼」和苏州码子「〡」到「〩」「〸」到「〺」不再把词切断,比如「人〻」现在能被关键词一路匹配到;其他提问的切词结果不变。
- 为什么做:知识平台专题,上一轮中日韩关键词修复审核时留下的小尾巴,两种存储(本地 libSQL、PostgreSQL)一起改。
- 出错会怎样:最坏情况是含这些罕见符号的提问关键词排序变差,向量一路照常作答;不改索引、不需重建,可直接撤回。
- 要你做什么:无。
## What changes
- `keywordTerms` in `packages/plugins/knowledge-turso/src/sql.ts` and
`packages/plugins/knowledge-pgvector/src/sql.ts` split a query at every
member of the CJK symbols block except the three marks 々 〆 〇 (class
`U+3000–3004, U+3008–303F`). That block also holds 19 more letters and
numbers: the Hangzhou numerals U+3021–3029 and U+3038–303A, the kana
repeat marks U+3031–3035, U+303B (the vertical iteration mark) and
U+303C. Each of them cut the term it sat in, and a run of one character
is dropped, so 「人〻」 gave no term.
- The split class now takes only the members of the block that are
neither a letter nor a number: `U+3000–3004, U+3008–3020, U+302A–3030,
U+3036–3037, U+303D–303F`. Everything else in the class is unchanged.
- The class moves out of the `split` call into an exported constant
`KEYWORD_SEPARATORS`, byte-identical in both files, so the tests can
read it. `sql.ts` is not re-exported by either package's entry
(`index.ts` names its exports), so the published surface does not
change.
- The `UNSEGMENTED_RUN` doc comment said the split takes the rest of the
block as punctuation. That is no longer true, so the comment now says
only why the three marks are named (〆 belongs to no script).
- Changeset `.changeset/38411-cjk-symbol-block-letters.md`: patch on
both store packages.
## Tests
The same two new cases in each store, beside the existing CJK cases
(pgvector `keyword-terms.test.ts`; turso `acceptance.test.ts`, which
runs on `:memory:` and on a `file:` URL):
- **Block probe, from Unicode properties.** For each code point of
U+3000–303F, it checks whether `KEYWORD_SEPARATORS` splits `a`, then the
code point, then `b`. The code points that split must equal those that
fail the Unicode letter-or-number property test in the runtime. The test
computes this from the runtime's Unicode tables, with no hand list. Each
letter or number, three in a row, must yield a term. Behaviour pins:
「人〻」 gives `人〻`, 「第〢〣号」 gives `第〢〣, 〢〣号, 第〢, 〢〣, 〣号`, and 「出差、住宿。「审批」」
gives `出差, 住宿, 审批`.
- **Parity.** Each store pins `KEYWORD_SEPARATORS` against the same
regex literal, so the two classes are pinned to one text.
<details><summary>Local runs at 082af27</summary>
- `pnpm --filter @objectstack/knowledge-pgvector test` (no database):
Test Files 5 passed, 8 skipped (live files); Tests 24 passed, 93
skipped.
- `pnpm --filter @objectstack/knowledge-pgvector test` on a local
PostgreSQL 16.15 with pgvector, `OS_TEST_POSTGRES_URL` set and
`OS_EXPECT_LIVE_DIALECT_MATRIX=1`: Test Files 13 passed (13); Tests 117
passed (117). The cluster was stopped and removed afterwards.
- `pnpm --filter @objectstack/knowledge-turso test` (libSQL `:memory:`
and a local `file:` database): Test Files 4 passed (4); Tests 290 passed
(290).
- `pnpm --filter @objectstack/knowledge-pgvector typecheck` and the same
for turso: exit 0, with `check:test-typecheck` OK for both.
- Lock verdict on each run: `VERDICT command-exit 0`.
</details>
<details><summary>Ablation: the old class restored, the new pins
red</summary>
`scripts/ablation-replace.mjs` replaced the range `U+3008–3020,
U+302A–3030, U+3036–3037, U+303D–303F` with the old `U+3008–303F`, one
store at a time (anchor 1 → 0; blob moved), then restored (blob equals
`HEAD`, `git diff HEAD` empty):
- pgvector `keyword-terms.test.ts`: 2 failed, 6 passed. Failing: the
block probe (61 separators against the 42 the Unicode tables name) and
the parity pin.
- turso `acceptance.test.ts`: 4 failed, 134 passed. Failing: the same
two cases, on `:memory:` and on `file:`.
</details>
## Acceptance notes
- **Count.** The card says 18 code points. The runtime's Unicode tables
count 19 letters and numbers in U+3000–303F beyond 々 〆 〇: 9 + 3 Hangzhou
numerals, 5 kana repeat marks, U+303B and U+303C. The ablation shows the
same count (61 − 42).
- **Tone marks.** U+302A–302F are combining tone marks, not letters or
numbers, so they still split, as the fix shape names.
- **The kana repeat marks and U+303C have no script (Common).** The
split no longer cuts at them, but `UNSEGMENTED_RUN` does not name them,
so they are not pieced into the run beside them. 「いろ〳〵」 gives `〳〵` (a
word) and `いろ` (a piece); before it gave `いろ`. Adding them to the run is
outside this PR's file surface (the split class only). This is rare in a
typed question, so it is not filed.
- **Parity is pinned twice, not compared directly.** A pin that reads
the other package's `sql.ts` would need a declaration in
`scripts/cross-package-test-inputs.mjs` and in `turbo.json`, and both
are outside the claimed file surface. Each store's test therefore pins
the same literal.
## Verification
- Files to read first, by risk:
`packages/plugins/knowledge-turso/src/sql.ts` (the `KEYWORD_SEPARATORS`
hunk: the class ranges),
`packages/plugins/knowledge-pgvector/src/sql.ts` (the same hunk,
byte-identical apart from the store name in the comment),
`packages/plugins/knowledge-pgvector/src/__tests__/keyword-terms.test.ts`
(the block probe).
- Two-minute check: `pnpm --filter @objectstack/knowledge-pgvector exec
vitest run --maxWorkers=2 src/__tests__/keyword-terms.test.ts`. Expected
result: 8 passed, including "splits at the punctuation of the CJK
symbols block and at none of its letters or numbers".
- Derived gates (`node scripts/pm/dispatch-gates.mjs --commands`, at
082af27): 67 derived, 66 run with exit 0. `--ran` reconciles: 67
accounted, 0 unrun. NOT MEASURED: `check:dual-build-cjs-loads`, reason:
exit 3, PREREQUISITE NOT MET. It needs every package's `dist/`, and this
container built only the two stores' closure. CI runs it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>1 parent d08d2ae commit a133c8a
5 files changed
Lines changed: 91 additions & 10 deletions
File tree
- .changeset
- packages/plugins
- knowledge-pgvector/src
- __tests__
- knowledge-turso/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
51 | 74 | | |
52 | 75 | | |
53 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
150 | | - | |
| 149 | + | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
| |||
177 | 189 | | |
178 | 190 | | |
179 | 191 | | |
180 | | - | |
| 192 | + | |
181 | 193 | | |
182 | 194 | | |
183 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
1014 | | - | |
| 1014 | + | |
1015 | 1015 | | |
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | 1019 | | |
1020 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1021 | 1044 | | |
1022 | 1045 | | |
1023 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
| 398 | + | |
| 399 | + | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
| |||
425 | 437 | | |
426 | 438 | | |
427 | 439 | | |
428 | | - | |
| 440 | + | |
429 | 441 | | |
430 | 442 | | |
431 | 443 | | |
| |||
0 commit comments