Skip to content

knowledge-turso/pgvector: hybrid search, a keyword leg (FTS5 trigram / tsvector) merged with the vector leg by RRF #37974

Description

@objectstack-fleet

repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

Filing gate: ③ maintainer-directed (topic child of #37000) · Source: maintainer (hotlong, cloud #5 project thread, 2026-11-27 13:41Z): 「但是我们作为元数据开发平台,不能只考虑制度库」 · Spec: objectstack#37000 comment 7220000671 · relayed by seat repo:objectstack#1 (mailbox #37561 comment 7220012379)
Grading: area:ai · Feature · p3 (topic) · reach: any search that names an exact token (an order number, a model code, a person's name) that the vector leg ranks below topK · evidence: read on main 0b539b6; FTS5 behaviour measured on local libSQL 0.15 in the spec comment.
Dedupe: is:issue knowledge hybrid search keyword → 2 (open: #37000 parent, #6015 seat post) · is:issue knowledge search trigram fts → 0.
Reader: area o1-C of seat repo:objectstack#1 claims it after triage's first touch.

维护者速读

  • 问题:知识检索现在只有向量一路,订单号、型号、人名这类精确词常常搜不到。
  • 做什么:每个知识源的段落表加一张关键词索引(Turso 用 FTS5 trigram,pgvector 用 Postgres tsvector),检索时关键词和向量两路各取一批,用 RRF 合并,再按调用者权限逐条复核。少于 3 个字的词(如「出差」)退回 LIKE 匹配。
  • 谁受益:用知识检索查具体编号、名称的用户和 AI 助手。
  • 需要你做的:无。

What

Premise re-read on main 0b539b6: the Turso store ranks by an exact cosine scan only (packages/plugins/knowledge-turso/README.md:49, turso-adapter.ts); no fts5 appears under packages/plugins/knowledge-turso, knowledge-pgvector or service-knowledge; the pgvector DDL (packages/plugins/knowledge-pgvector/src/sql.ts:92) creates no tsvector column.

  • Turso: per passage table an FTS5 shadow table (tokenize='trigram') kept in step with passage writes. Search runs both legs and merges them with RRF (k=60) before the permission re-check.
  • Quote the query as an FTS5 phrase (X-200 unquoted is a syntax error). Trigram matches terms of 3 or more characters (「住宿标准」「三十天」) but not 2-character terms (「出差」), so a term under 3 characters falls back to content LIKE '%…%' on the scoped rows.
  • pgvector: the same keyword leg on a Postgres tsvector.
  • The organization filter, record scope and metadata filter apply to both legs, as they do today to the vector leg.

Acceptance

  • A question naming an exact code finds the passage that the vector leg alone ranks below topK.
  • A 2-character Chinese term hits.
  • No regression on the brightrule eval set.

Activity

  1. added
    pm:queue
    area:ai
    on Nov 27, 2026
  2. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Triage: lands in area:ai · domain:server · Feature · p3 · pm:queue · size M; rationale: maintainer-directed knowledge-topic child (#37000; 「不能只考虑制度库」): hybrid keyword plus vector search with RRF. A capability widening, so p3 as filed. Recorded 2026-11-27T14:15Z.

  3. added
    domain:server
    on Nov 27, 2026
  4. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

    Claim: PM loop round 8 · area o1-C (epic #37000; area concurrency 8 by the maintainer 2026-11-27T11:26Z) · 2026-11-27T17:19Z
    Session: session_016WV4cwPhGV4g9p1BGQaZbP
    Account: os-elon-musk
    Branch: claude/area-o1C-37974
    Worktree: objectstack-issue-37974
    Domain: domain:server
    Area: o1-C
    Seat: repo:objectstack#1
    File surface: packages/plugins/knowledge-turso/src/turso-adapter.ts + sql.ts (an FTS5 trigram shadow table per passage table, kept in step with passage writes; the keyword leg and RRF k=60 merge in search), packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts + sql.ts (the same leg on a tsvector), tests (both adapters; pgvector on the live-postgres suite), the two READMEs, content/docs/ai/knowledge-rag.mdx (search section), a changeset.
    Container & model: M, mode:subagent, model: default tier (dispatch-gates --tier: "no path-derived mandate"), effort: high (reason: M; two stores' DDL and query paths, the 2-character fallback, every existing filter on both legs, and an eval-set no-regression check)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack's own code, packages/plugins/knowledge-turso/src/turso-adapter.ts | a question naming an exact code or a short term misses the passage the vector leg ranks below topK | every deployment that searches a knowledge source
    Thread-read: 7220573411
    Premise: holds, read on origin/main 8d598aa — no fts5 / tsvector under knowledge-turso or knowledge-pgvector; turso search is the exact cosine scan (turso-adapter.ts:187 note), pgvector search at pgvector-adapter.ts:501 likewise.
    Serial constraints cleared: probe overlap-check (the four adapter files) against origin/main and every open PR: VERDICT clean exit 0, no PR shares a file. The earlier area order put this behind F3 #37957; re-read at the maintainer's ask, F3 adds a visible-ids pre-filter to the search options, and either order works: whichever lands second applies its filter or leg to both legs, and the PR says so. F6 #37975 (approximate index, same search SQL) stays behind this card.
    Pre-claim lane: packages/plugins/knowledge-*/** ⇒ domain:server.
    Pre-claim deps: none open; triage 7220573411 sized it M.
    Prior rulings read: card thread 0 rulings (triage 7220573411).
    Fold-or-serial: not folded with #37975 (same SQL; serial behind this card).

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 27, 2026
  6. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP
    os-dev-report

    {
      "issue": 37974,
      "status": "done",
      "branch": "claude/area-o1C-37974",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/38037",
      "head": "d0340b7b52",
      "session": "session_016WV4cwPhGV4g9p1BGQaZbP",
      "premise_still_valid": true,
      "summary": "Both open knowledge stores search with two legs merged by RRF (k = 60, each leg at most topK) inside the adapter, so before the service's permission re-check. knowledge-turso: a contentless FTS5 trigram table per passage table (TABLE-fts, keyed through an INTEGER PRIMARY KEY map TABLE-kw so VACUUM cannot renumber it), kept in step by three triggers, made and dropped with the passage table, shape-checked before any drop; a term of 3+ characters is one quoted FTS5 phrase, a shorter one is content LIKE over the rows in scope. knowledge-pgvector: a GIN expression index on to_tsvector('simple', content) per width table; a word of 3+ characters is phraseto_tsquery, a shorter term or one with a Han/kana/Hangul character is ILIKE (measured: the simple parser keeps a Han run as one word, so a tsvector phrase cannot find a substring of it); both legs in one statement. The organization filter, record scope and metadata filter are one WHERE used by both legs and by the per-term IDF counts. A pre-PR index answers: turso builds the keyword index from the table's rows at the table's first search (one transaction), pgvector creates the GIN index at the width's first write or search; both pinned. Hit score is now the normalized fused rank (1 = first in both legs, 0.5 = first in one), no longer cosine.",
      "tests": "knowledge-turso `vitest run --maxWorkers=2` on head d0340b7b52: Test Files 4 passed (4), Tests 201 passed (201). knowledge-pgvector `vitest run --maxWorkers=2` with OS_TEST_POSTGRES_URL on a private PostgreSQL 16 + pgvector (UTF8 db, port 55474, mine, stopped after) and OS_EXPECT_LIVE_DIALECT_MATRIX=1, on d0340b7b52 after the closure build: Test Files 10 passed (10), Tests 101 passed (101). New pins: exact code in a question (fixture asserts vector-only rank 7 of 7; hybrid returns it within topK 3; the bare code answers it first with score 1), 2-char 出差 and 3+ char 住宿标准 hits, org/record-scope/metadata filter exclusion in the keyword leg, FTS5-syntax queries answer, keyword index follows rewrite/delete/generation swap/dropSource (turso), pre-PR table gets its index at first search (both), foreign object under a keyword-index name refused and kept (turso), GIN index used by the plan (pgvector). Ablations on b2d204ad2b (on-disk mutation, pin run, git restore --source=HEAD --staged --worktree, pins green again turso 16/16, pg 4/4): keyword leg off -> exact-code pin red in both ('expected [ …(3) ] to include Seal kit for model X-200, part 7731.'); LIKE fallback off -> 2-char pin red (turso 'expected 0.5 to be 1', pg 'expected [] to deeply equal [ [ zh_short:1, 0.5 ] ]'); filter dropped from keyword leg only -> scope pin red in both ('expected [ kw_scope:out ] to deeply equal []'). Test runs were outside the verify lock (declared narrowing; the lock queue stood about an hour behind a dogfood holder), the first ones on dist directories borrowed from a sibling worktree whose package trees were byte-identical by git tree hash, the final ones on this worktree's own closure build.",
      "gates": "Under os-verify-lock (slot issue-37974): `pnpm --filter '@objectstack/knowledge-turso^...' --filter '@objectstack/knowledge-pgvector^...' build --concurrency=2 && pnpm --filter @objectstack/knowledge-turso --filter @objectstack/knowledge-pgvector typecheck` -> 'VERDICT command-exit 0 · held the lock 182s' (both tsc --noEmit and check:test-typecheck OK, 0 errors) after eight queue-timeouts (exit 99). dispatch-gates --commands on d0340b7b52: 99 commands, each run once with the exit code captured before any pipe: 91 exit 0, 8 not measured on the first pass (7 exit 3 PREREQUISITE NOT MET, spec check:docs exit 1 'packages/spec/json-schema is missing'); after the closure build 5 of those went 0 (lint check:doc-formula-expressions, lint check:doc-security-posture, spec check:docs, check:docs-transcript-drift, check:lean-entry-closure); still NOT MEASURED locally: spec check:skill-examples (exit 3, client SDK dist not built), check:dual-build-cjs-loads (exit 3, needs pnpm build), check:type-check-debt (timed out at 500s building its own closure). dispatch-gates --ran: '99 derived famil(ies) accounted for'. overlap-check: 'VERDICT clean exit 0' vs origin/main and #38026, #37982, #37963. check:nul-bytes exit 0 (in the derived list). PR check-runs on d0340b7b52 at report time: Lint & Repo Gates success, TypeScript Type Check success, Build Core success, Governed Surface Queue Guard success, Dogfood Regression Gate success, Test UI success, Live E2E UI success, Check Changeset success, Type Check workspace/source/consumer/debt success, Lint ESLint success, Test Core shards 4,7,8,9,10 success and 1,2,3,5,6 in_progress. The PR body's Verification section was written before the closure build and still says typecheck NOT MEASURED and pgvector 8 of 10 files; this report supersedes it.",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2 — fleet-write relay pr_create (POST /repos/objectstack-ai/objectstack/pulls draft + POST /repos/objectstack-ai/objectstack/issues/38037/assignees), and this report comment via post-stamped (POST /repos/objectstack-ai/objectstack/issues/37974/comments); git push is not counted",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — BrightRule eval set NOT MEASURED: objectstack-ai/brightrule is not attached to this session (API 403, access not enabled) and the eval needs a real embedding provider; RRF reorders vector results whenever the keyword leg ranks something, so whoever runs that eval next owns the regression reading",
        "carrier: none · noted, not filed — cross-source ordering: the knowledge service sorts hits of all sources by score, so a deployment mixing these two stores (fused rank in (0,1]) with another adapter (its own score) now compares unlike scores; no threshold on score exists in the service today",
        "carrier: none · noted, not filed — turso keyword IDF uses SQLite ln(), present in the libSQL client build (SQLite 3.45.1, measured); a remote Turso server not measured",
        "carrier: repo:objectstack#1 · noted, not filed — the verify lock was held 57 minutes by one dogfood run (pid 10811, issue-37307 dogfood.sh); live and the same process throughout, so not a hung holder, but it put every locked build in the area behind it for about an hour"
      ],
      "deviations": "1) The first WIP commit (1st of the branch) carries no Claude-Session/Co-Authored-By trailers; the branch is not claude/issue-*, so it cannot be force-pushed to amend; every later commit carries the model-free pair. 2) File surface widened: content/docs/protocol/knowledge.mdx (two Search bullets and the adapter table), which this change made incomplete; declared in the PR body. 3) Tests ran outside the verify lock (declared narrowing, queue about an hour), the early runs on byte-identical borrowed dist directories, four of them removed once the merge of main made them stale. 4) Local gate families ran outside the lock, as check gates do. 5) A private PostgreSQL cluster was started under /tmp/pg-issue-37974 (the scratchpad path is not traversable by the postgres user) and stopped and removed at the end. 6) Serial with #37957 stated in the PR body: whichever lands second applies its filter to both legs; here the single inScope WHERE feeds both legs and the counts."
    }
  7. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

    Close-out · area o1-C · 2026-11-27T19:50Z

    Delivered by PR #38037 (merged c151c49 at 2026-11-27T19:50Z). Both open stores search by vector and by keyword, fused by RRF inside the adapter before the permission re-check. Noted, not owed (L1 7226483295): the pgvector GIN index is built lazily and non-concurrently at a width's first write or search. BrightRule eval set not measured (no access); whoever runs it next owns the no-regression reading. Nothing remains on this card; pm:dispatched removed with this comment.

  8. removed
    pm:dispatched
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpriority:p3

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions