Repository navigation
feat(knowledge-turso, knowledge-pgvector): hybrid search, a keyword leg merged with the vector leg by RRF - #38037
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…ngeset Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…chunk id Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
📓 Docs Drift CheckThis PR changes 2 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 — 2 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 15940bf430ebdecd439c2e1e4dfd0514868c1c3a && git checkout 15940bf430ebdecd439c2e1e4dfd0514868c1c3a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin cb3f8b9538d167460d3a67c5201a1e6315e936e2 d0340b7b522d45fe8323611654a0a259f12f102b && git checkout -B drift-repro cb3f8b9538d167460d3a67c5201a1e6315e936e2 && git merge --no-ff d0340b7b522d45fe8323611654a0a259f12f102b
node scripts/docs-audit/affected-docs.mjs --json cb3f8b9538d167460d3a67c5201a1e6315e936e2
|
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 L1 verdict (L1-a): ACCEPT at head 席位核对Shape and gates. 11 files, +915/-61, in The score question. The score is now the fused RRF rank normalised to What I read myself.
Nits, not owed.
Landing: not governed, so the area lands it after ACCEPT, with all checks green. |
|
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Landing · area o1-C · head
State: ready + auto-merge; #37974 closes on merge via |
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP
Fixes #37974
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
Both open knowledge stores now search with two legs and merge them by reciprocal rank fusion (RRF, k = 60, each leg ranks at most
topK) inside the adapter, so before the knowledge service re-checks each hit as the caller.#,@or+inside a term keeps it whole (X-200,v1.2,a/b), at most 16 terms. A passage's keyword score is the sum, over the terms it holds, of the term's BM25 inverse document frequency among the rows in scope (binary term frequency), so a word most passages hold weighs little. Keyword ties are ranked by cosine distance, and fused ties go to the better vector rank, so the keyword leg never reorders by chunk id what the vector leg ranks.X-200is never FTS5 syntax. It is matched in a contentless trigram FTS5 table beside each passage table (TABLE-fts), keyed through a map table (TABLE-kw, an INTEGER PRIMARY KEY, so a VACUUM cannot renumber it) and kept in step by three triggers on the passage table (insert, delete, update ofchunk_idorcontent), inside the statement that writes the passage. A shorter term (「出差」) is matched bycontent LIKEover the rows in scope. The keyword index is made with the passage table and dropped with it (generation swap,completeBuild,dropSource). Its names hold a hyphen, which no source id, generation table or object name can hold; an object under one of those names that the store did not make is refusedSERVICE_UNAVAILABLE, naming it, and never dropped.phraseto_tsquery('simple', term)onto_tsvector('simple', content), served by a GIN expression index (knowledge_vec_dWIDTH_content_tsv): no column added, no row rewritten. A shorter term, or one holding a Han, kana or Hangul character, is matched bycontent ILIKE: measured on PostgreSQL 16, thesimpleparser keeps a run of Han characters as one word ('出差住宿标准每晚三百元'), so a tsvector phrase could never find 「住宿标准」 inside it. Both legs run in one statement (one snapshot), each behind the existing active-generation guard.filterare built once and applied in both legs (and in the inverse-document-frequency counts), before either ranks.CREATE INDEX IF NOT EXISTS; a concurrent loser re-reads the catalogue and goes on. Both pinned.scoreis now the fused rank normalized to (0, 1]: 1 for first in both legs, 0.5 for first in one alone. It was the cosine similarity.content/docs/ai/knowledge-rag.mdx(retrieval and both store sections), and the two Search bullets plus the adapter table ofcontent/docs/protocol/knowledge.mdx, which this change made incomplete (outside the claim's file surface; declared in the report).Serial with #37957. That card adds a visible-ids pre-filter to the search options and is not started. Whichever lands second applies its filter or leg to both legs: here the one
WHERE(inScopein both adapters) is the single place a new filter goes, and it already feeds both legs and the counts.Read first (by risk)
packages/plugins/knowledge-turso/src/sql.tskeywordIndexDdl: the triggers and the backfill. A trigger that drifts from the passage table leaves the contentless index wrong silently (the FTS5deletecommand needs the indexed text, whichold.contentholds).packages/plugins/knowledge-turso/src/turso-adapter.tssearchAttempt: the sharedinScopeinvec,candandstats; the parameter numbering (?1is the vector in both legs).packages/plugins/knowledge-pgvector/src/pgvector-adapter.tssearchAttemptandensureKeywordIndex: the one statement and the first-search index build.Two-minute check
cd packages/plugins/knowledge-turso && pnpm exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t "hybrid search"prints 16 passed (8 cases on:memory:and on afile:URL).Tests
New pins (turso: acceptance.test.ts, top-level describe; pgvector: acceptance.live-postgres.test.ts, top-level describe)
X-200,"A",NEAR(the,OR,* pump^2,col:umn,-x,a AND b NOT c) answers; the keyword index follows a rewrite, a delete, a generation swap anddropSource; a table without a keyword index gets one at its first search, 7 map rows from 7 passages, and stays in step after; an object table underTABLE-kwrefuses the build, naming it, and keeps its row.Readings (head d0340b7 for both suites; ablations on b2d204a before the merge of main, which touched no knowledge package)
knowledge-tursovitest run --maxWorkers=2: Test Files 4 passed (4), Tests 201 passed (201).knowledge-pgvectorvitest run --maxWorkers=2against a private PostgreSQL 16 with pgvector (UTF8 database): Test Files 8 passed, Tests 96 passed;reconcile-purgeandreindex-real-driverdid not load (@objectstack/metadata-protocol/@objectstack/objectqlunbuilt here) — NOT MEASURED locally; neither file callssearch.terms = []): exact-code pin red in both stores, "expected [ …(3) ] to include 'Seal kit for model X-200, part 7731.'".Acceptance notes
objectstack-ai/brightrulerepository is not attached to this session (the API answers 403, access not enabled), and the eval needs a real embedding provider. RRF reorders the vector leg's results whenever the keyword leg ranks something, so this is the reading that would show a regression; it belongs to whoever runs that eval next.KnowledgeHit.scorefrom these two stores is the normalized fused rank, no longer the cosine similarity. The knowledge service sorts hits across sources by score, so a deployment mixing these stores with another adapter now compares a fused rank with that adapter's score. No threshold onscoreexists in the service today.ln(), an SQLite math function: present in the libSQL client build (SQLite 3.45.1, measured); a remote Turso server is not measured.CREATE INDEXruns, once.Verification
Local gate families (dispatch-gates --commands on d0340b7; lock saturated, so run outside it as check gates are)
check:doc-formula-expressions,check:doc-security-posture, speccheck:skill-examples,check:docs-transcript-drift,check:dual-build-cjs-loads,check:lean-entry-closure— each "run a build first");spec check:docsexit 1 "packages/spec/json-schema is missing" (a missing generated tree, also nothing measured). These 8 are NOT MEASURED locally; CI runs them on a built tree.dispatch-gates --ran: "99 derived famil(ies) accounted for".overlap-check: VERDICT clean exit 0 against origin/main and the three open PRs sharing the docs files (feat(knowledge): a knowledge source needs no adapter and no requires entry; it binds to the deployment's store #38026, fix(knowledge-turso)!: Test connection comes with the Turso fields it checks; the group text drops the cloud fallback #37982, fix(service-knowledge)!: retire the knowledge field gate's title arm behind a per-source recipe proof #37963).typecheckneeds the dependency closure built, and the build never got the verify lock (queued about an hour behind a dogfood holder) — NOT MEASURED through the package script. Narrowed instead:tsc -pover each package's test config withpathsto the workspace sources: knowledge-turso 0 errors; knowledge-pgvector 2 errors, both "Cannot find module '@objectstack/objectql'" in the two unloaded test files.Generated by Claude Code