Skip to content

knowledge-pgvector: the keyword leg scans nearly every row once per Chinese piece, so keyword p95 at 67k passages is about 1.9 s (a trigram GIN index on passage content) #38473

Backlog

Description

@objectstack-fleet

repo:objectstack#5 · os-project-manager · session_01FEkQ5pfJqySEaVD3CKvevm

Filing gate: ② fleet Feature (a new index and a new extension dependency on the pgvector store). Source: topic #38346 (a follow-up the seat named on PR #38469, seat note 2026-11-29 03:59Z: "If a follow-up is real, file it as a card and name it in the body").
Grading: area:ai · Feature · fleet source ⇒ p3 · reach: every pgvector deployment searched in Chinese, Japanese or Korean once PR #38469 lands · evidence: measured on PR #38469 (live PostgreSQL 16 + pgvector 0.6.0, 67,421 passages, 218 unspaced zh questions, 3 runs per side).
Blocked-by: #38469

维护者速读

What happens

After PR #38469, keywordTerms cuts an unspaced CJK question into up to 16 overlapping 2- and 3-character pieces. On pgvector, a piece holding a Han, kana or Hangul character is not served by the simple tsvector GIN index (the parser keeps the whole run as one word), so it is matched by LIKE (no cased letter) or ILIKE over every row in scope. A piece most passages hold (for example 公司, held by 67,125 of 67,421 passages, because every clause prefix names its company) makes nearly every row a candidate, and each piece is one substring scan of them.

Measured on PR #38469, keyword leg alone, 67,421 passages:

side p50 p95
before pieces 132–150 ms 617–691 ms
pieces, ILIKE (first head) 538–563 ms 2,883–3,085 ms
pieces, LIKE for caseless terms (PR #38469 as it lands) 187–195 ms 1,832–1,925 ms

Ask

  1. A pg_trgm GIN index on passage content, created beside the keyword index: a second DDL next to keywordIndexDdl (packages/plugins/knowledge-pgvector/src/sql.ts, the tsvector expression just above it), created through ensureKeywordIndex in pgvector-adapter.ts, with CREATE EXTENSION IF NOT EXISTS pg_trgm handled the way the adapter handles vector. Re-read the anchors on the base; the readings above are from PR fix(knowledge): the keyword leg ranks unspaced Chinese, Japanese and Korean questions by 2- and 3-character pieces #38469's head cde0bbe.
  2. If the extension cannot be created (a managed Postgres without it), the adapter keeps today's scan and says so once; the dev measures what the adapter does today when vector is missing and follows the same shape.
  3. Measure first: the same 67k table and question set, rankings identical before and after, p50/p95 in the report. If the index does not move p95 materially, report that and close the card instead.

Not a fingerprint change: computeIndexFingerprint (packages/services/service-knowledge/src/knowledge-index-fingerprint.ts) hashes only the embedding model, variant, dimensions and split.

Other lever, named and not asked: compute the per-candidate tsvector only when a word term needs it (Search section). Measure it in the same run if it is cheap to try.

Acceptance

Reader

repo:objectstack#5 (the seat holding #38346), after PR #38469 merges and triage's first touch for domain:* and queue state.
Dedupe (open and closed): pg_trgm knowledge 2 (#38411 the parent defect, #38447 closed, a duplicate of it) · pgvector keyword latency 3 (#38411, #37000 topic, #37957 closed, unrelated) · knowledge keyword leg trigram 5 (#38411, #37974 closed hybrid search, #37000, #37975 closed libSQL approximate index, #38447). None on this.

Activity

  1. added
    area:ai
    on Nov 29, 2026
  2. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · sunhaolin · session_017xRBcSxvUE3fDrox79CL9t

    Triage: lands in packages/plugins/knowledge-pgvector (a pg_trgm GIN index on passage content, built on first search for old tables) · area:ai · domain:server · Feature · p3 (fleet source) · pm:blocked (Blocked-by: #38469, in the body) · size S. Rationale: a pgvector store searched in Chinese, Japanese or Korean answers correctly, but the keyword leg scans nearly every row once per piece: p95 ~1.9 s at 67k passages, measured on PR #38469. That PR (the #38411 fix) is not merged, so the cost is not shipped yet and the card waits on it. ⛔ When it unblocks, it goes to the decision box, not the queue: it adds a database-extension dependency to the pgvector store (a new runtime third-party dependency, on the human floor). If PR #38469 ships and the slowdown hurts use, re-read it as a Bug of the shipped search.

    Recorded 2026-11-29T04:42Z.

  3. added
    domain:server
    pm:blocked
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aidomain:serverpm:blockedpriority:p3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions