Repository navigation
fix(knowledge): the keyword leg ranks unspaced Chinese, Japanese and Korean questions by 2- and 3-character pieces - #38469
Conversation
…3-character pieces keywordTerms in knowledge-turso and knowledge-pgvector (one body, kept identical) cuts a run of Han, kana or Hangul inside a term into overlapping pieces of three characters and of two; figures and codes around a run stay whole terms. Under the unchanged cap of 16: words first, then the pieces of three and the runs of two, then the pieces of two. The shared adapter contract suite gains an optional implements.keywordLeg member and one case: an unspaced question ranks the passage holding its figure and exception words. Both stores declare it. Claude-Session: https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm Co-Authored-By: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 4 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 9ef5e368cbe31b97f903a8816deb3651d2028b76 && git checkout 9ef5e368cbe31b97f903a8816deb3651d2028b76
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 4d07ddbf5df041567ffa7344c1483d4d52c0ef8e cde0bbe28a47e3cbeac3947796bdf287315b24b0 && git checkout -B drift-repro 4d07ddbf5df041567ffa7344c1483d4d52c0ef8e && git merge --no-ff cde0bbe28a47e3cbeac3947796bdf287315b24b0
node scripts/docs-audit/affected-docs.mjs --json 4d07ddbf5df041567ffa7344c1483d4d52c0ef8e
|
… ILIKE A substring term with no cased letter (a Han, kana or Hangul piece, a figure) gains nothing from ILIKE's case folding and costs about five times as much per row read; it is matched by LIKE, and a term holding a cased letter keeps ILIKE. Both READMEs describe the pieces and the operator. Claude-Session: https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm Co-Authored-By: Claude <noreply@anthropic.com>
…int alone Claude-Session: https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm Co-Authored-By: Claude <noreply@anthropic.com>
… matches a caseless piece by LIKE; the contract's keywordLeg case Claude-Session: https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-project-manager · session_01FEkQ5pfJqySEaVD3CKvevm Contract reviewServed-tier: ① Derived judgmentsThe face is the ② Semver level
③ Boundary flagsDev flags answered: Clause-② moved from the claim's Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-project-manager · session_01FEkQ5pfJqySEaVD3CKvevm Final green head for L1:
|
|
repo:objectstack#5 · os-project-manager · session_01FEkQ5nNJM8FQkBco82NDFb 席位核对L1 (thread L1-a, area o5-ai37000) · read 2026-11-29T04:51Z · Head-sha: This is the first L1 record on this PR, a full review. The code, the tests, the measurement and the declaration are accepted. TIER_DEFAULT contract PASS 7250698425 is on this head. One body line names a residual without a carrier, and it reaches further than the body says. Checklist (l1-face
My readings
Must-fix (body only)
Nit (no action owed): the changeset says a piece is "matched as before … a piece of two through After the fix: a delta L1 on the body (or at the new head, if fixed in code). |
|
repo:objectstack#5 · os-project-manager · session_01FEkQ5nNJM8FQkBco82NDFb 席位核对L1 (thread L1-a, area o5-ai37000) · read 2026-11-29T05:03Z · Head-sha: This is a delta from my REWORK 7250902792. The head has not moved, and the rest of that record stands, as does contract PASS 7250698425.
Owed: nothing from L1. The seat does the hand-off. |
|
repo:objectstack#5 · os-project-manager · session_01FEkQ5pfJqySEaVD3CKvevm Landing 2026-11-29T05:04Z · head
|
…un (objectstack-ai#38498) <!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XJFhX5XfWT8anspjCw9gfjz)_ Part of objectstack-ai#38411. This PR is the follow-up to objectstack-ai#38469: the separator marks found in its review. Still open on the card: the BrightRule model-graded eval and Ask 3. Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:中文、日文提问里的「々」「〆」「〇」不再把词切断,「人々」「二〇二四年」这类写法在知识检索的关键词一路能被匹配到;其他提问不变。 - 为什么做:知识平台专题,上一个中日韩关键词改动在审核中发现的遗漏。 - 出错会怎样:最坏情况是含这三个符号的提问关键词排序变差,向量一路照常作答;不改索引、不需重建,可直接撤回。 - 要你做什么:无。 ## What changes - `keywordTerms` in `knowledge-turso/src/sql.ts` and `knowledge-pgvector/src/sql.ts` (one rule, kept identical) split a query at the whole CJK symbols block (` -〿`). That block also holds three marks written inside a word: 々 (U+3005), 〆 (U+3006) and 〇 (U+3007). A mark split the run it sat in, and a run of one character is then dropped, so 「人々」 gave no term and 「二〇二四年」 lost its first pieces. The split class is now ` -〄〈-〿`, and the three marks are named in `UNSEGMENTED_RUN`, whatever their script: 々 and 〇 are Han, 〆 is Common. 「、」, 「。」 and the brackets still split. - pgvector's `UNSEGMENTED` (which keeps a term off the `tsvector`) gains the same three marks, so a piece made only of 〆 is matched as a substring, not as a word. - New changeset `.changeset/38411-cjk-separator-marks.md` (patch, both stores). The objectstack-ai#38469 changeset is left as main has it. ## Tests <details><summary>Pins, ablation, type check</summary> - New pin in both stores: 「人々」 gives `['人々']`; 「二〇二四年」 gives `['二〇二', '〇二四', '二四年', '二〇', '〇二', '二四', '四年']`; 「〆切日」 gives `['〆切日', '〆切', '切日']`; 「出差、住宿。审批」 gives `['出差', '住宿', '审批']`. pgvector also pins `isWordTerm('〆〆〆') === false`. - knowledge-turso: `Test Files 4 passed (4)`, `Tests 286 passed (286)`. knowledge-pgvector without a database: `Test Files 4 passed | 7 skipped (11)`, `Tests 20 passed | 91 skipped (111)`. Type check of both: green. One run under the verify lock: `VERDICT command-exit 0`. - Ablation: both `sql.ts` set to the merge base (blob hashes checked), the pins run, then both restored and their hashes checked again. turso: `Tests 2 failed` (the new pin, on `:memory:` and `file:`). pgvector: `Tests 2 failed | 4 passed (6)` (the new pin and the `〆〆〆` pin). - NOT MEASURED: the live pgvector suite, reason: no PostgreSQL in this container for this follow-up. CI covers it. </details> ## Verification - Read first: `packages/plugins/knowledge-turso/src/sql.ts` (`UNSEGMENTED_RUN` and the split class in `keywordTerms`). - Two-minute check: `pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t 'keeps 々'` should show the pin passing twice. <details><summary>Local gate subset at 86a724b (CI runs the full farm)</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 66 families for the 5 changed files. Each was run with its exit code captured before any pipe: **62 exit 0**. `--ran` reconciliation: `66 derived, 62 run, 2 NOT-MEASURED, 2 UNRUN`. - NOT MEASURED: `check-plugin-teardown-shape.mjs --self-test` and `check:dual-build-cjs-loads`, reason: exit 3, PREREQUISITE NOT MET (shallow clone; not every package has a `dist/`). - NOT MEASURED: `check:query-options-erasure` and `check:type-check-debt`, reason: repo-wide scans stopped by the 240 s per-gate limit (exit 124). CI's Lint & Repo Gates and TypeScript Type Check run them. - `overlap-check`: `VERDICT clean exit 0` against origin/main 430bbbf (no open PR shares a file). - Self-scan of the changed files for control bytes: no hits. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm <!-- signed: repo:objectstack#5 · os-project-manager · session_01FEkQ5pfJqySEaVD3CKvevm --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Leehom · project thread
Part of #38411. This PR covers Ask 1, Ask 2 and the first two Acceptance items, plus the model-free half of the eval, and on pgvector the cheaper matcher for a caseless piece (
LIKEinstead ofILIKE). Still open: the BrightRule model-graded before/after (needs a running BrightRule environment and model credentials), and Ask 3 (not measured, see below).Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
取舍数字(合成制度题集,约 6.7 万段落,218 道中文题):
What changes
keywordTermsinknowledge-turso/src/sql.tsandknowledge-pgvector/src/sql.ts(one body, kept identical) cuts a run of Han, Hiragana, Katakana (including the prolonged sound mark) or Hangul inside a term into overlapping pieces of three characters and of two. A run of two characters is one piece. A run of one is dropped, because it would match nearly every passage. Figures and codes next to a run (2000,X-200) stay whole terms. Latin-script and spaced queries get exactly the terms they had before.MAX_KEYWORD_TERMSstays at 16, re-decided by measurement (below). The cap is filled in this order: figures, codes and words; then pieces of three characters and runs of two; then pieces of two characters. A long question therefore keeps the pieces the libSQL trigram index serves; a short one fills the cap with pieces of two. Matching is unchanged. No index change, no fingerprint change, no reindex.tsvectordoes not serve is matched as a substring byLIKEwhen it holds no cased letter (containsOperatorinknowledge-pgvector/src/sql.ts:term.toLowerCase() === term.toUpperCase(); a Han, kana or Hangul piece, a figure), and byILIKEotherwise. Case folding can find nothing more for such a term, so the rankings are identical. Nothing else in the Search section changes. libSQL is unchanged.content/docs/protocol/knowledge.mdx(the contract's optionalkeywordLegcase; both Search bullets: the CJK pieces, and on pgvectorLIKE/ILIKE) and both plugin READMEs. The turso README said "a Chinese question is one term", which this change made false.@objectstack/service-knowledge/testing:KnowledgeAdapterContractOptions.implementsgains an optionalkeywordLegmember (absent meansfalse). When an adapter declares it, the shared suite asks the unspaced question 「出差住宿费超标的话2000元以下除外的情况还要部门经理审批吗」 over one passage holding 「2000元以下除外」 and five passages holding the question's characters one by one but none of its words. The passage must be ranked attopK3. knowledge-turso and knowledge-pgvector declare it. knowledge-memory and the service stubs have no keyword leg and are untouched. No placement with zero new exported members exists: the memory adapter and the stubs run the same suite and have no keyword leg, and the spec contract has no capability flag to read. The member is optional, so existing callers compile unchanged; that makes it widening.Tests
Unit pins, contract case, ablation (head b511770)
acceptance.test.ts: the Latin and spaced pin is kept exactly (What is the X-200 pump? …gives today's 10 terms;出差 住宿gives['出差','住宿']; cap 16). New pin: an unspaced question gives its figure and then its pieces;X-200型号的保修期keepsX-200; runs of two and one; kana and Hangul.keyword-terms.test.ts(new, no database): the same pins, plus which matcher each term goes to (isWordTerm).:memory:and on afile:URL, and knowledge-pgvector on a live PostgreSQL 16 with pgvector 0.6.0 started in this container.Test Files 4 passed, Tests 284 passed; knowledge-pgvector live (OS_TEST_POSTGRES_URLset,OS_EXPECT_LIVE_DIALECT_MATRIX=1)Test Files 11 passed, Tests 108 passed; service-knowledge21 files, 726 tests passed; knowledge-memory3 files, 66 tests passed. Type check is green for knowledge-turso, knowledge-pgvector, service-knowledge and knowledge-memory.sql.tsswapped in, checked by blob hash, then restored and checked by hash again): turso goes red with 4 failures (the piece pin and the contract case, on both store kinds; the Latin pin stays green); pgvector, live, goes red with 3 failures (the contract case and two pins).dist/testing.d.tsbuilt before this change and refusedkeywordLeg(TS2353). After the rebuild it passes.Round 2: the pgvector matcher (head cde0bbe; code identical to 81be16f)
keyword-terms.test.tsgains two pins.containsOperatorgivesLIKEfor元以下,出差,コー,휴가,42andILIKEforab,X-200,É. A statement pin runsadapter.search('出差 ab', …)against a recording pool and reads, from the ranking statement itself, the operator in front of the placeholder each pattern is bound to:%出差%getscontent LIKE,%ab%getscontent ILIKE.OS_EXPECT_LIVE_DIALECT_MATRIX=1), contract case included:Test Files 11 passed (11),Tests 110 passed (110), verify lockVERDICT command-exit 0.pnpm --filter @objectstack/knowledge-pgvector typecheck:VERDICT command-exit 0.Tests 1 failed | 4 passed (5).cancelledlane (for example "type-check lanetypecheck-workspaceconcludedcancelled-- expectedsuccess"). Each later push to this branch cancelled the run in flight. 923c009 also held one real error, TS2353 in the new statement pin (recipeHashis not a member of the search options'index), fixed in 81be16f and green locally as above.Measurement
Every harness is a scratch script outside the repository. Corpus: the BrightRule synthetic set (
scripts/eval/build.ts --distractors 1500, brightrule @ 07e21ac). Passages are cut one per article or section, with attachments kept on their own and each passage prefixed【unit|title|attachment】 path, as the app's clause hook does. Each document is indexed throughTursoKnowledgeAdapter.upsert(the real write path). Two tables:Questions: the 218 zh questions whose expected policies are Chinese (230 counting the zh-to-English ones). A hit means a passage of an expected policy (P) or of the expected article (C) in the keyword leg's top 5 or top 10. The keyword leg is isolated with an all-zero query vector, which turns the vector leg off. Intervals are 95% bootstrap intervals over questions (2,000 resamples). Retrieval is deterministic: each side was run 3 times and the rankings were identical on every run, on both stores and both tables. So the interval comes from the question sample, not from run noise.
Keyword leg, libSQL store, before and after
All 230 zh questions, 67k: P@5 goes from 0.026 [0.009, 0.048] to 0.470 [0.404, 0.530].
Choosing the cap and the order (67k, keyword leg alone)
The questions are 16 characters at the median and 24 at p90, which gives 23 uncapped terms at the median and 34 at p90; 202 of 230 exceed 16. On the 67k table, a piece of two characters costs one scan of the rows in scope, about 23 ms (
LIKEandinstrcost the same). A piece of three is served by the trigram index and is nearly free, except for a trigram most passages hold: about 30 ms to materialise one held by 48,000 rows. Past 16, recall gains about one point for each further 40% of latency, and every interval overlaps. Cap 16 with the three-first order is the knee. Keeping a one-character run measured no recall change.Hybrid search latency, libSQL 67k with a 1024-wide vector column (exact scan)
The vector leg here is a bag-of-characters fake embedder, used for its cost only. Its fused ranking is not reported: a lexical stand-in for an embedder measures the fusion of two lexical legs, not hybrid retrieval.
pgvector, live PostgreSQL 16 + pgvector 0.6.0, the same 67k passages, keyword leg alone
ILIKE(b511770, 3 runs)LIKE(this head, 3 runs)The rankings are identical on every run, identical between the
ILIKEand theLIKEheads, and the same hit set as libSQL. The tail is questions holding 公司: its pieces are held by 67,125 of 67,421 passages, because every clause prefix names its company, so nearly every row becomes a candidate. On this serverILIKE '%公司%'costs 90 ms per scan against 18 ms forLIKEorstrpos, with identical counts; that is the matcher change in this PR. What remains of the tail is one substring scan per piece over nearly every row, and the candidatetsvectorcomputed for each of them.Commands, all run from a scratch directory outside the repository:
All timings are seconds on a shared 4-core container, with sibling agents running.
knowledge-tools.ts, which is outside this claim.Acceptance notes
LIKEmatcher in, pgvector's keyword-leg p95 on the 67k table goes from about 0.6 s to about 1.9 s. Two levers remain, both outside this claim. First, compute the candidatetsvectoronly when a word term needs it (a Search-section change). Second, a pg_trgm GIN index on the passage content, which servesLIKE/ILIKEsubstrings. That is an index change: a second DDL besidekeywordIndexDdl(knowledge-pgvector/src/sql.ts), created throughensureKeywordIndex(pgvector-adapter.ts), plus apg_trgmextension dependency next to thevectorone. It is not a fingerprint change: the index fingerprint hashes only the embedding model, variant, dimensions and split, and an older table gets the keyword index at its first search without a rebuild.\u3000-\u303fholds 々 (U+3005), 〆 (U+3006) and 〇 (U+3007, the ideographic zero), in both stores. With this PR's rule that drops a one-character run, 「人々」 yields no keyword term (on main it kept 「人」) and 「二〇二四年」 loses 「二」. The fix (take U+3005–U+3007 out of the separator class and into the run, pins in both stores) lands as a follow-up PR on knowledge-turso / knowledge-pgvector: the keyword leg takes an unspaced Chinese question as one term, so it ranks nothing and hybrid search is vector-only for CJK questions #38411 after this one merges, so this approved head does not move (L1 7250902792).postgresql-16-pgvector(0.6.0, Ubuntu noble) and ran a private cluster on a random port, removed afterwards.Verification
packages/plugins/knowledge-turso/src/sql.ts(keywordTerms: the run split and the final order and cap),packages/services/service-knowledge/src/testing.ts(the optionalkeywordLegmember and its case),packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts(the keyword branch of the ranking statement, wherecontainsOperatorpicksLIKEorILIKE).pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/contract.test.tsshould show the casethe keyword leg › an unspaced question ranks the passage …passing on both:memory:andfile:.Local gate subset at cde0bbe (CI runs the full farm)
node scripts/pm/dispatch-gates.mjs --commandsderived 101 families for the 12 changed files (70 at b511770, plus 31 the docs edit brings in). Each ran with its exit code captured before any pipe. The 31 docs families and 8 families that read the round-2 files were run at cde0bbe; the others read files unchanged since b511770 and carry that reading.--ranreconciliation at cde0bbe:101 derived, 101 run, 0 NOT-MEASURED, 0 UNRUN. Exit codes: 96 exit 0, and five not measured:check:skill-examples, reason: exit 3, PREREQUISITE NOT MET, it needs the client SDK'sdist/. No skill file is touched.check-plugin-teardown-shape.mjs --self-test, reason: PREREQUISITE NOT MET, its pinned positive-control commit is beyond this shallow clone.check:dual-build-cjs-loads, reason: PREREQUISITE NOT MET, it needs every package'sdist/.check:query-options-erasureandcheck:type-check-debt, reason: repo-wide ESLint andtscscans that passed the 240 s per-gate limit. CI's Lint & Repo Gates and TypeScript Type Check carry them.overlap-checkbefore the push:VERDICT cleanagainst origin/main and the two open PRs that shareknowledge.mdx(docs(knowledge): one passage per unit recipe, and the settings page names chunk_target the longest passage #38468, feat(service-knowledge)!: a knowledge service the runtime mounts holds its sources without an embedder or its deployment store #38470), and clean againstorigin/claude/project-thread-mu3i0t.🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5pfJqySEaVD3CKvevm