Repository navigation
Commit cb8d853
chore(knowledge-pgvector): per-search segment timing and a load bench for search_knowledge (objectstack-ai#38729)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ88oxgpPaPHgsNM7N7PvvwbS)_
Refs objectstack-ai#38719 (part 1) — the committed segment timing and the load bench.
Part 2, the baseline on the A4 environment, stays on the card, which
this PR does not close.
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:只新增一个提交进仓库的测速脚本,产品行为不变。
- 属于「私有部署企业版知识检索 10 人同时提问不超时」专题的基线一项,给第三期每项做不做提供数据。
- 出错只会让测速读数不准,不影响任何客户;脚本不随软件包发布,可直接撤回。
- 无。
## What changes
A new, unpublished directory
`packages/plugins/knowledge-pgvector/bench/` (the package's `files` is
`dist`, `README.md`, `CHANGELOG.md`, so nothing here ships):
- `instrument.mjs` — per-search segment timing read through seams the
code already takes. Nothing under `src/` of this package or of
`service-knowledge` is changed:
- `embed` — the adapter's `embedder` option;
- `pool_wait` + `ranking` + `other_sql` — the adapter's `pool` option, a
`PgPoolLike` whose one-shot query is split into checkout, statement and
release, the same steps `pg.Pool#query` runs;
- `visible_ids` + `permission_recheck` + `system_read` — the service's
`dataEngine` option, each read classified by the arguments the service
passes;
- adapter rounds (a refill round = backfill) — the adapter as registered
with the service.
Concurrent searches are kept apart by an `AsyncLocalStorage` store per
search.
- `run.mjs` — the load bench, runnable against any PostgreSQL URL with
pgvector. It seeds a synthetic dataset into two throwaway schemas,
builds the index through the real `KnowledgeService`, then makes real
`search_knowledge` calls (the tool executor, as a non-system caller)
over record-scope fraction × concurrency. Default grid: 1/10/30/100 %
and unscoped × 1/5/10/20 clients, closed loop.
- Per cell: p50/p95/max/mean of the total and of every segment, each
with its sample count; hit count; searches per question; backfill share
(scoped and unscoped cells are separate rows); embedding-call failures;
failed and refused searches with their codes; empty answers; the
service's `search failed` log lines; block reads of the store's tables.
- It also records the machine shape (client CPUs and memory; server
version, pgvector version and memory settings) and whether the cell ran
cold or warm.
- `instrument.test.mjs` — pins statement shape and call counts over the
real adapter and service from source, with no database. It never pins a
duration.
- `README.md` — the manual.
### Segment status
| segment (card) | status | seam |
|:--|:--|:--|
| embed | measured | adapter `embedder` option |
| vector statement | measured as `ranking` | adapter `pool` option; the
statement also carries the keyword leg for any query with keyword terms
(counted per cell) and the scope predicate |
| scope predicate | **NOT MEASURED in situ** | it is a conjunct of the
ranking statement's one WHERE. `--isolate-scope` adds a DERIVED
out-of-situ number: the same WHERE as a bare count minus the
source-and-generation WHERE as a bare count, run serially and timed by
the server. An in-situ number needs the store to time its statement
parts itself, a change under `knowledge-pgvector/src` (held by objectstack-ai#38692) |
| permission re-check | measured | service `dataEngine` option
(`permission_recheck` after ranking, `visible_ids` before it) |
| pool wait | measured (not on the card) | adapter `pool` option |
## Tests
- `pnpm --filter @objectstack/knowledge-pgvector test` at `8e3e522f`: 6
files passed, 8 skipped (the live-PostgreSQL files: no
`OS_TEST_POSTGRES_URL`); 29 tests passed, 93 skipped.
- `pnpm --filter @objectstack/knowledge-pgvector typecheck`: exit 0. The
bench files are `.mjs` and outside the package's TS programs.
- Ablation: with `permission_recheck` reclassified on disk,
`bench/instrument.test.mjs` went red (1 failed / 4 passed); restored
with `git restore`.
<details><summary>Local smoke run — 5,000 passages, 1024 dims, 40
searches a cell (NOT a baseline, not quotable)</summary>
Machine: 4 vCPU, 15.7 GiB, shared container. PostgreSQL 16.15 with
pgvector **0.6.0** (Ubuntu package; the kit ships 0.8.7),
`shared_buffers` 512MB, pool 4, fake in-process embedder, warm. Its job
is to show the script runs the whole grid; it is not the A4 baseline.
Columns: scope · concurrency · n · total p50/p95 ms · pool wait p50 ·
ranking p50 · re-check p50 · backfill · `search failed` lines · rows in
scope.
```
1% | 1 | 40 | 53.73 / 73.57 | 0.1 | 50.46 | 1.95 | 0 | 0 | 50
1% | 20 | 40 | 434.59 / 625.09 | 350.72 | 71.83 | 2.21 | 0 | 0 | 50
10% | 1 | 40 | 73.35 / 106.8 | 0.09 | 70.21 | 1.87 | 0 | 0 | 500
30% | 1 | 40 | 114.04 / 205.01 | 0.08 | 111.08 | 1.73 | 0 | 0 | 1500
100% | 1 | 40 | 263.53 / 453.83 | 0.07 | 260.75 | 1.69 | 0 | 0 | 5000
100% | 20 | 40 | 1776.19 / 2117.96 | 1451.12 | 323.8 | 5.45 | 0 | 0 | 5000
none | 1 | 40 | 250.89 / 491.17 | 0.07 | 245.3 | 1.82 | 0 | 0 | -
none | 20 | 40 | 1295.42 / 1570.26 | 1046.31 | 241.46 | 1.56 | 0 | 0 | -
```
All 20 cells completed with 0 failed searches; the full table is in the
run's JSON.
</details>
## Acceptance notes
- **First files to read:**
1. `bench/instrument.mjs` — `classifyEngineRead`, which decides what
counts as the permission re-check, and `timedPool`, which reproduces
`pg.Pool#query`'s checkout, statement and release.
2. `bench/run.mjs` — `isolateScope`, the derived scope-predicate pass,
and its stated method.
3. `bench/instrument.test.mjs` — the pins over the real adapter and
service.
- The bench composes its own service over synthetic data (ObjectQL +
SqlDriver, no security plugin), so the re-check reads every row it asks
for. It cannot yet point at an already-indexed source in a kit
deployment (the BrightRule source on A4); part 2 has to decide that.
- At concurrency 10–20, the smoke run's time goes mostly to waiting for
one of the pool's 4 connections. That is the topic's B2 (pool size from
settings), not new scope.
- No changeset: no published file moves (`skip-changeset`).
- Seat routing (2026-11-30T08:16Z), part 2 composition: B — on A4 the
bench composes the source itself at 60k×1024; an existing-source option
(A) may follow after objectstack-ai#38700 only if needed.
- Seat routing (2026-11-30T08:16Z), scope predicate: keep the labelled
DERIVED number (`--isolate-scope`); no store seam under objectstack-ai#38692's files.
## Verification
Two-minute check, against any PostgreSQL where the role can `CREATE` and
the `vector` extension is available:
```bash
pnpm --filter '@objectstack/knowledge-pgvector...' build
node packages/plugins/knowledge-pgvector/bench/run.mjs --pg-url postgres://USER@HOST:5432/DB --passages 500 --scopes 10,none --concurrency 1,5 --searches 20 --isolate-scope
```
Expected: a markdown table with four rows, every `ok` equal to `n`, the
10% rows showing `… (derived)` in the last column and the unscoped rows
`NOT MEASURED`; the JSON path printed on stderr. Both schemas are
dropped at the end.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxbXQcnpisuAAJRr8yNr
<!-- signed: repo:objectstack@os-warren · os-warren ·
session_01JQwxbXQcnpisuAAJRr8yNr -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5bb397d commit cb8d853
4 files changed
Lines changed: 1407 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
0 commit comments