Repository navigation
feat(knowledge): Setup → Search Terms previews a question's terms, stop words and passage counts (#38710 step 3) - #39796
objectstack-fleet[bot] wants to merge 14 commits into
Conversation
…wordMatches (objectstack#38710 step 3) Registers one optional adapter member before the code that builds it (rule 5): per-term keyword-leg match counts and the passage total of a source's active generation, read by the administrator's term preview. Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…nd countKeywordMatches (objectstack#38710 step 3) Failing before the code: ISegmenterService.cut (terms equal to keywordTerms, stop words dropped), the contract suite's countKeywordMatches case (each term counted as the adapter's own keyword leg matches it; turso and pgvector declare it), the service's term preview and its action handler, and sys_search_term's Preview Terms action declaration. Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…urso and pgvector (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…ut and AdapterKeywordCounts Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…en bundles (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…-import; docs for the term preview (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…ctstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…ntract lives in its module (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…llback (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 6 package(s): 43 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 15 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 186 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 3e90fdf9a2a608b9874f175b8a02a99a88ae5e5b && git checkout 3e90fdf9a2a608b9874f175b8a02a99a88ae5e5b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 425f170b39fe6324d2a490e6e5907b49d749a991 f17ce11712981c0148b33a42617c70a3c2cca658 && git checkout -B drift-repro 425f170b39fe6324d2a490e6e5907b49d749a991 && git merge --no-ff f17ce11712981c0148b33a42617c70a3c2cca658
node scripts/docs-audit/affected-docs.mjs --json 425f170b39fe6324d2a490e6e5907b49d749a991
|
…e system, at the service (objectstack#38710 step 3) Red first: previewTerms and its action handler answer any caller today. Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
… system, at the service (objectstack#38710 step 3) The passage counts (IKnowledgeAdapter.countKeywordMatches) are not filtered by record permissions. KnowledgeService.previewTerms now refuses, before it reads the question or the source, every caller that is neither a system context nor holds manage_platform_settings (403 PERMISSION_DENIED), and the action handler hands it the caller's capabilities, never the action door's isSystem elevation. Stated in the member's jsdoc, the ADR-0161 K8 note and the changeset. Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…sSystem it ignores (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
…ets its census row (objectstack#38710 step 3) Claude-Session: https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW Co-authored-by: Claude <noreply@anthropic.com>
Requested by Tesla · project thread
Part of #38710 (step 3, PR 1: the term preview, item 1, and the import/export pins, item 3). Left on the card after this PR: the stop-word candidates (F3, held for a ruling), the dictionary candidates (not shipped: no search log is kept, and none is added), and the BrightRule re-run and cloud#5253 (readings held by others).
Clause-②: yes (two optional contract members)
Metadata-protocol: none
维护者速读
What changes
sys_search_termdeclares a list actionpreview_terms(type: 'script',requiredPermissions: ['manage_platform_settings'], paramsquestionand optionalknowledge_source, aresultDialogwith atableof term and passages, acode-listof dropped stop words, the source's passage total and a note). Noui/**code: the console's generic action door and result dialog render it. The knowledge service plugin registers the handler on the engine; the handler callsKnowledgeService.previewTerms, whose body lives in the new moduleknowledge-term-preview.ts(the facade file stays at its 1758-line ceiling).ISegmenterServicegains optionalcut(query, options?)answeringSegmenterCut { terms, stopWords }. The platform segmenter'skeywordTermsnow returnscut(...).terms, and the knowledge service'sKnowledgeSearchTerms.cutForis the one place both search (termsFor) and the preview read the cut from. There is no second cutting path.IKnowledgeAdaptergains optionalcountKeywordMatches(ctx, terms)answeringAdapterKeywordCounts { passages, matches }: the passages of the source's active generation, and for each term the passages its keyword match holds for. Turso and pgvector implement it, and each shares one per-term match helper with its own keyword search (keywordMatchSqlon Turso: trigram FTS5 phrase for 3+ characters, elseLIKE;keywordTermMatchon pgvector:phraseto_tsqueryfor a word term, elseLIKE/ILIKE). The SQL text of both search legs is unchanged. Memory does not implement it, so the preview says "Not counted" and never answers 0. ADR-0161 K8 gets its dated note (committed first, 42574f6), and the adapter contract suite getsimplements.keywordCountswith its case (testing-keyword-counts.ts).packages/rest/src/import-search-term-csv.test.ts: csv and xlsx export with the same rows, an xlsx export re-imported through the async jobs door record for record (ids included), and a 403 with no file for a caller without the capability. Plus a docs paragraph incontent/docs/protocol/knowledge.mdx.Read first (by risk):
packages/plugins/knowledge-pgvector/src/keyword-counts.tsand thecountKeywordMatcheshunk inpgvector-adapter.ts: the count must use the search's operator, scoped tosource_idand the activegeneration.packages/services/service-knowledge/src/knowledge-term-preview.ts,countFor: every way a count can't be given (held source, refused adapter, vector-only, no member, a thrown count) turns into anote, never a 0.packages/services/service-segmenter/src/segmenter-service.ts,cut:keywordTermsnow delegates to it, so a change in the collected stop words must not move any term.Tests
Head 7039ce8. Every heavy run went through
os-verify-lock.sh; each line quotes itsVERDICT command-exit.@objectstack/service-knowledgetest: 35 files, 941 passed (exit 0, rerun at head).@objectstack/service-segmentertest: 5 files, 55 passed (exit 0).@objectstack/platform-objectstest: 137 files, 2462 passed (exit 0).@objectstack/knowledge-tursotest: 8 files, 351 passed (exit 0).@objectstack/knowledge-memorytest: 3 files, 72 passed (exit 0).@objectstack/knowledge-pgvectortest (no server): 10 passed, 10 live files skipped (exit 0).OS_EXPECT_LIVE_DIALECT_MATRIX=1):pnpm --filter @objectstack/knowledge-pgvector exec vitest run --maxWorkers=2 live-postgres, 10 files, 119 passed (exit 0, at head). That CI job runs only offpull_request, so this local run is the PR's live evidence.@objectstack/restsrc/import-search-term-csv.test.ts: 6 passed (exit 0, at head).Ablation of the new contract cases. Each was an on-disk mutation through
scripts/ablation-replace.mjs, restored with blob == HEAD and an emptygit diff HEAD. The tests resolve the mutated module fromsrc(adaptersrc/index.ts; the@objectstack/service-knowledge/testingalias), so no build was involved.WHERE 1): the contract case red twice (:memory:andfile:), "'公开招标' is counted as the keyword leg matches it: expected 4 to be 2". Restored.GLOB): red, "'alpine' ... expected +0 to be 1". Restored.source_id = $1 OR true): red, "expected 5 to be 4". Restored.Acceptance notes
GET /data/:object/export) and the async import (POST /data/:object/import/jobs) already servesys_search_termin csv and xlsx, so item 3 is pins and a docs line.INVALID_FIELD. The pin spells that mapping. Not filed: it was observed on the REST door only, and the console import wizard's column mapping was not exercised.search-terms-38710.test.ts.knowledge-service.tsis now exactly at its facade line ceiling (1758/1758): the next addition there belongs in a sibling module.packages/rest/src/import-search-term-csv.test.ts(named by the order), the regeneratedpackages/spec/api-surface/contracts.jsonandexport-origins/contracts.json, and the changeset.Verification
Two minutes:
pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/search-terms-38710.test.ts. Expect every case to pass, including the "the term preview" describe (the cut equals search's terms, the counts equal a one-term keyword search, "Not counted" without the member).Derived gates (dispatch-gates --commands at 7039ce8, 125 families)
All 125 derived families ran locally at 7039ce8 with exit 0.
--ranreconciliation: "125 derived famil(ies) accounted for — 125 run, 0 NOT-MEASURED (a DERIVED zero — all 125 recorded an exit code and none of them is 3)". Fixed along the way:check:facade-delegation-only(the facade was 5 lines over its ceiling, so the docblock moved into the module) andcheck:where-matcher(a capturing callback in the new pin was rewritten as a loop). Local-only families:check:skill-frame-freshnessexit 0;check:dev-prereqsexit 1, "the workspace is not built" (32 of 111 packages have no dist, because builds here were targeted). That reading is about this machine, not the diff. Families CI owns (pnpm lint, the full farm) were not run locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01L9qibw3sEzqFZcu4JmuGwW