Repository navigation
fix(knowledge): the keyword leg ranks unspaced Chinese, Japanese and Korean questions by 2- and 3-character pieces - #38469
objectstack-fleet[bot] wants to merge 5 commits into
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 |
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.-〿contains 々 (U+3005) and 〆 (U+3006), so 「人々」 splits at 々. This is an observation only.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