Repository navigation
fix(knowledge-pgvector): a failed search is a coded refusal, its statement has a time limit, and its pool size is a setting - #38726
Conversation
…ement has a time limit, and its pool size is a setting Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj Co-authored-by: Claude <noreply@anthropic.com>
…meout shape Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj Co-authored-by: Claude <noreply@anthropic.com>
…al codes, and a changeset Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 16 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 3 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 cf081a845ae30de8eb8c85b00f19afb1cf74c37d && git checkout cf081a845ae30de8eb8c85b00f19afb1cf74c37d
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0d68ce2db33a4328362b2695174b47277f377daa 4f6b7d850da64e02ce16a1d182acdd4d5632ef61 && git checkout -B drift-repro 0d68ce2db33a4328362b2695174b47277f377daa && git merge --no-ff 4f6b7d850da64e02ce16a1d182acdd4d5632ef61
node scripts/docs-audit/affected-docs.mjs --json 0d68ce2db33a4328362b2695174b47277f377daa
|
|
repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx Contract reviewServed-tier: This review is owed only because the claim and the PR declare ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx 维护者速读
席位核对REWORK (docs only, code accepted as is) · L1 · area o2-E · Head-sha
Rework (should-fix, prose only)
The claim's file surface does not name Nits (optional in the same round, not blocking)
Out of scope, carried
|
…s search refusals Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx Contract reviewServed-tier: This is a delta read by the original reviewer of record 7272956301 (PASS at ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx 维护者速读
席位核对ACCEPT · L1 · area o2-E · Head-sha
|
|
repo:objectstack#2 · os-warren · session_01JQwxbYGom9jneGXshSXk4W 2026-11-30T09:30Z · Landing · PR #38726 (#38718, topic #38703 row B2) · zone o2-E
|
…al mode; report the three modes, hybrid by default (objectstack-ai#38745) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_ Part of objectstack-ai#38692 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 使用 pgvector 存储的知识源可以按选定方式检索:只按意思、只按字词或两者结合;不选仍是两者结合,结果与现在逐位相同。 - 属于知识管理专题「一期 a:检索方式」。 - 出错会是某种方式漏掉或多出段落;未声明方式的知识源不受影响,可直接撤回。 - 无。 ## Stack Base: `main`. The spec PR objectstack-ai#38720 is merged and `main` is merged in, so this diff is the adapter's own 6 files; it lands in the same release as the service PR objectstack-ai#38722, the first reader of the mode. Built on `main` after objectstack-ai#38726 (B2) merged: the ranking statement still runs under B2's `SET LOCAL statement_timeout` in a transaction of its own, a failed search is still refused by the coded errors of `src/errors.ts`, and the pool default is B2's 20. The ruling it implements is on `main`: ADR-0161, the dated note of 2026-11-30 under K8. ## What changes - `knowledge-pgvector` reports `capabilities.retrieval = { modes: ['vector', 'keyword', 'hybrid'], default: 'hybrid' }`. - A search runs only the legs its mode names, in SQL: `keyword` never calls the embedder (distance column is a constant); `vector` writes no keyword condition at all (no `LIKE`/`ILIKE`, no `tsquery`), not just none into the fusion. That leg is most of a hybrid statement's cost: on PG17 + pgvector 0.8.7 over 59,949 clauses, vector-only took the statement from 1,655 ms to 445 ms at the same top-10 quality (os-bob, objectstack-ai#38692). - Single-leg scores follow the RRF scale (rank n → 61/(60+n), first hit 1); `hybrid` unchanged, `fuse(rows, topK, legs)` bit-identical for two legs. - README paragraph, protocol doc §4.1 sentence, patch changeset. - A mode the store does not list is refused (`400 VALIDATION_ERROR`) before anything is embedded or ranked, rather than run on the one-leg scale (review S1). `Clause-②: yes (widening)`: the exported adapter's `capabilities` grows `retrieval` (review M1). ## Tests - New `retrieval-modes.test.ts` (recording pool): legs per mode, no embedder call under `keyword`, empty question, hybrid bit-identity over ranks 1..200 with `Object.is`, single-leg scores, and a pin that a `vector` search sends no statement holding `LIKE`, `ILIKE`, `tsquery` or `@@` (with `hybrid` as the control that does). - The whole package against live PostgreSQL 16 + pgvector (`OS_TEST_POSTGRES_URL`), at 6707107 (main with objectstack-ai#38720 merged): 179 tests passed; typecheck clean. ## Acceptance notes - With the service PR applied on top, the pgvector suite against live PostgreSQL passes (133). ## Verification - Two-minute check: `pnpm --filter @objectstack/knowledge-pgvector exec vitest run src/__tests__/retrieval-modes.test.ts` → all pass (no database needed). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [ ] 4. One issue, one branch off an up-to-date `main`, one pull request. (Stacked: see "Stack" above.) - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [ ] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbaASqBozmmj1n5tbUf <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbaASqBozmmj1n5tbUf --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Fixes #38718
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
Topic #38703 row B2, in
@objectstack/knowledge-pgvectoronly (no change toservice-knowledgeorcore).search()now answers every failure of the store's database as an ADR-0112 refusal, judged by SQLSTATE (never by the server's message, whichlc_messagestranslates):57014(statement past its limit, or cancelled) isTIMEOUT504; class53(too_many_connections, out of memory, disk full) isSERVICE_UNAVAILABLE503; no connection (the pool's wait timed out, class08,57P01–57P05, a socket error) isSERVICE_UNAVAILABLE503; any other SQLSTATE isDATABASE_ERROR500. The message is one sentence naming the source; the SQLSTATE, the driver text and the setting to change go toremedy(operator text the service logs). An already-coded error (the adapter's own refusals) and a non-database error (the embedder's) pass through unchanged. New modulesrc/errors.ts.poolFromPgnow marks every error its pool and connections throw (a non-enumerable symbol; message, code and keys untouched, so write paths read exactly whatpgthrew), and the classifier treats a marked uncoded error as "no connection".try/catchinsearch()around the attempts loop (moved into a privatesearchAttempts); the ranking statement's body is untouched (the 知识源加「检索方式」和混合比例:只用向量 / 只用关键词 / 混合(可设比例),由应用元数据指定,单次检索可覆盖 #38692 phase-1a pgvector PR follows this one).searchStatementhelper: its own transaction,SET LOCAL statement_timeout = Nfirst. Chosen form:SET LOCALin a transaction, so the limit lasts exactly one statement, touches no session state and holds behind a transaction-mode pooler (the builder lock still needs session mode; README says so). Default 10000 ms, the same bound the Turso store uses for a remote request (fix(knowledge-turso): a scoped search reads its passage table once a statement; a request past its bound answers TIMEOUT #38693);statementTimeoutMsplugin/adapter option, else the settingOS_KNOWLEDGE_STATEMENT_TIMEOUT_MS. Only the ranking statement is limited; catalog reads, writes and builds are not.OS_KNOWLEDGE_POOL_MAX(plugin optionpoolMaxwins), default 20 (raised from 4 in Rework 2 below, on os-bob's measurement). Strict likeOS_DATABASE_POOL_MAX: a value that is not a positive integer stops the boot naming the setting; blank reads as unset. The plugin reads it (as it already reads the URL from the environment), so a composed boot (os servehandsprocess.env) and a host that mounts the plugin directly read the same setting;resolveKnowledgeStoreincoreneeded no change. The boot line now says the pool size, the limit and where each was read from.max_connections = 200(README, "Pool size and time limit"):replicas × (OS_DATABASE_POOL_MAX + OS_KNOWLEDGE_POOL_MAX + builds running at once) + headroom ≤ max_connections. With 20 kept as headroom, platform pool at its default 5 and one build running, the default of 20 fits up to 6 replicas (3 replicas = 60 store connections); the ceiling is 84 with 2 replicas, 54 with 3, 39 with 4. A larger pool moves waiting from the pool into the database; it does not make one search faster. This is the setting key and ratio B12 (the delivery note) carries.Why
Premise re-read on
origin/maind2caaec before code:codedRefusalOf(knowledge-service.ts:4974) accepts only a SCREAMING_SNAKEcodewith an integerstatus400–599;searchRound(:3237-3249) logs an uncoded throw aterrorandcontinues, andsearch()throwswholeRefusalonly whenrefusedis non-empty (:2561). Apgerror'scodeis a SQLSTATE (57014) or absent, so a single-source search answered{ hits: [] }. The ablation below reproduces exactly that.Tests
src/__tests__/search-refusals.test.ts(unit, runs everywhere, 14 cases): the statement shape (BEGIN,SET LOCAL statement_timeout = 10000, the ranking,COMMIT; the ranking never on a bare pooled query; a given limit; a bad limit refused at construction); one case per error class (statement timeout57014, cancel57014with a translated server message, pool wait throughpoolFromPgat the ranking's connect and at a pooled read,53300,57P01,42P01), each pinned oncode+status; the embedder's uncoded error passed through by identity; throughKnowledgeService.search: the caller is refusedTIMEOUT504 instead of an empty list; the settings reader (precedence, blank, strict refusals).src/__tests__/search-refusals.live-postgres.test.ts(live,OS_TEST_POSTGRES_URL, no pgvector needed): a realpg_sleeppastSET LOCAL statement_timeoutanswers57014and classifiesTIMEOUT504, andSHOW statement_timeouton the same pooled connection after the transaction reads the session's own value; a real full pool (max: 1) times out throughpoolFromPgand classifiesSERVICE_UNAVAILABLE503 on bothqueryandconnect. Pins codes, never durations.Local readings at head 9a39db7
pnpm --filter @objectstack/knowledge-pgvector test: exit 0, Test Files 6 passed / 9 skipped (live files, no URL), Tests 38 passed / 95 skipped.vitest run src/__tests__/search-refusals.live-postgres.test.tswithOS_TEST_POSTGRES_URLat a local PostgreSQL 16.15: exit 0, 2/2.pnpm --filter @objectstack/knowledge-pgvector typecheck: exit 0 (incl.check:test-typecheck, 0 debt).eslint --no-inline-configon the five changed source/test files: exit 0.scripts/check-nul-bytes.mjs: exit 0.dispatch-gates.mjs --commands(7 paths, 694 changed lines): 26 of 27 commands exit 0;check-plugin-teardown-shape.mjs --self-testexit 3 — NOT MEASURED locally, reason: shallow clone cannot reach its pinned fixture commit (the script says so); CI runs it.git checkout HEAD --): withsearch()rethrowing the raw error, 8 of 14 cases go red, and theKnowledgeServicecase receives{ hits: [] }— the defect as filed. WithpoolFromPg's marking removed, the two pool-wait cases go red.Acceptance notes
Clause-②: yesis copied from the claim. Behaviour that changes for a caller: a database failure that used to read as zero hits from that source is now a refusal (refused[], or a whole-search refusal when it was the only source); a search statement over 10 s is now stopped where it used to run to completion.searchRound, so it still reads as zero hits for that source. The general fix sits inservice-knowledge(searchRoundtreating any uncoded throw as a refusal), which this card was told not to touch (held by refactor(service-knowledge): split KnowledgeService into five concern modules behind a delegating facade #38700). carrier: 专题:私有部署企业版(PostgreSQL + pgvector)知识检索 10 人同时提问不超时;Turso 只保基本能力 #38703 (topic owner) · noted, not filed.connectTimeoutMs(also the pool's wait) stays a plugin option only, default 5000; the card asked for the pool size and the time limit, not this.Verification
Two-minute check:
pnpm --filter @objectstack/knowledge-pgvector exec vitest run src/__tests__/search-refusals.test.ts— expect 14 passed, among them "through KnowledgeService: the caller is refused TIMEOUT, not answered an empty hit list".Read first, by risk:
src/errors.ts(the SQLSTATE table),src/pgvector-adapter.tssearch()/searchStatement(),src/plugin.tspoolFromPgandresolveStoreSettings.Rework (L1 7272964718, docs only)
Head
4340f85dadds the two should-fix doc edits and nothing else; nits N1–N3 not taken this round.content/docs/deployment/environment-variables.mdx(Database & Storage, besideOS_DATABASE_POOL_MAX):OS_KNOWLEDGE_POOL_MAX(integer,4, per replica, plugin option wins, the sizing formula with a link to the README section, a non-integer refuses the boot) andOS_KNOWLEDGE_STATEMENT_TIMEOUT_MS(integer,10000, per search statement,SET LOCAL, refusedTIMEOUTpast it, plugin option wins, a non-integer refuses the boot).content/docs/protocol/knowledge.mdx§4.1: one sentence each for the pool precedence (poolMax, elseOS_KNOWLEDGE_POOL_MAX, else 4), the ranking statement underSET LOCAL statement_timeout(default 10000 ms), and the three refusals by SQLSTATE.Regen-provenance: 7272956301 · 9a39db7 → 4340f85 ·
git diff --name-only 9a39db77 4340f85d→ content/docs/deployment/environment-variables.mdx, content/docs/protocol/knowledge.mdx (prose faces only, no code path moved)Rework 2 (pool default 4 → 20, on new data)
Head
4f6b7d85. The only behaviour change isDEFAULT_POOL_MAX4 → 20 insrc/plugin.ts; the rest is its pins and prose. Nits N1–N3 not taken.statement_timeoutstays 10000 ms.Evidence (not this PR's bench reading): os-bob's measurement on the card, #38718 comment 7273601824 — local PostgreSQL 17 + pgvector 0.8.7, 59,949 indexed BrightRule clauses, end to end over MCP
search_knowledge, scoped, 15 questions in rotation:(Those empty results are what this PR turns into
SERVICE_UNAVAILABLErefusals; the larger pool is what keeps them from happening at 20 concurrent callers.)src/plugin.ts:DEFAULT_POOL_MAX = 20; its docblock rewritten to justify the move (the measurement, a lazy ceiling rather than a count opened at boot, fits up to 6 replicas atmax_connections=200, class 53 refusals past that), replacing the old "not moved" note. The two option docblocks say 20.OS_KNOWLEDGE_POOL_MAXunset may now open up to 20 store connections per replica under load instead of 4. With the README's formula (platform pool 5, one build, 20 kept as headroom,max_connections=200) a replica reaches up to 26, so up to 6 replicas fit (6 × 26 = 156 ≤ 180; 7 × 26 = 182 does not); 3 replicas take 60 store connections. More replicas or a smaller server must set it lower (4keeps the old size) or raisemax_connections, otherwise the server refuses connections (too_many_connections, class 53) and those searches are refusedSERVICE_UNAVAILABLE.search-refusals.test.ts(DEFAULT_POOL_MAXand the blank-setting case), the README options and settings tables,environment-variables.mdx'sOS_KNOWLEDGE_POOL_MAXrow,knowledge.mdx§4.1, the changeset.4f6b7d85:search-refusals.test.ts14/14,tsc --noEmitexit 0.Regen-provenance: 7272956301 · 4340f85 → 4f6b7d8 ·
git diff --name-only 4340f85d 4f6b7d85→ .changeset/knowledge-pgvector-coded-search-refusals.md, content/docs/deployment/environment-variables.mdx, content/docs/protocol/knowledge.mdx, packages/plugins/knowledge-pgvector/README.md, packages/plugins/knowledge-pgvector/src/tests/search-refusals.test.ts, packages/plugins/knowledge-pgvector/src/plugin.ts (NOT prose-only: one constant and its docblock inplugin.ts, one test pin; the record does not carry across this hop by itself)Human Minimum
packages/specholds no runtime logic. (not touched)main, one pull request.packages/spectouched: n/a.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code