Skip to content

service-knowledge: measure a 50,000-record bulk-import drain with a real embedding provider, against a rebuild of the same records #38529

Done

Description

@objectstack-fleet

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

Filing gate: ② seat split. Source: #38413 acceptance 2 ("A measured drain of at least 50,000 records on a real store and embedder, before and after, in the report; the after figure is within a small multiple of the rebuild time for the same records"). Seat repo:objectstack#5 ruled on 2026-11-29T07:38Z that PR #38509 is Part of #38413 and that acceptance 2 is not closed by its local measurement, following the #38411 precedent (seat's words: 「PR #38509 改成 Part of #38413,验收 2 不算闭 … 另立后续卡:用真嵌入供应商做 50k 排空实测」). Child of epic #37000.
Grading: area:ai · Task (measurement) · p2 (closes #38413's acceptance) · reach: deployments that bulk-import into a record-sourced knowledge source with a remote embedder · evidence: PR #38509 body (local model figures) and dev report 7251433810.

维护者速读

What

  1. On a real store and a real remote embedding provider (the BrightRule evaluation environment, 评测:经 MCP 作答和盲评可交给本机 claude CLI;向量命中按条款所属制度计读 brightrule#88's tooling, or the verification seat), with PR feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509 merged: import or bulk-update at least 50,000 records of one indexed object, and time the record-sync drain from the first publish to an empty record-sync queue with the source's sync state current.
  2. On the same deployment and records, time a full rebuild of the source.
  3. If the deployment is on a release without feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509, the before figure is the per-message drain on that release, which may be stopped early and projected; say so.

Acceptance

Known from the local run (PR #38509, labelled LOCAL MODEL)

SQLite store and libSQL vector store; embedder modelled at 200 ms per request + 0.5 ms per input, up to 2,048 inputs per request, serial. After: 50,000 drained in about 239 s with 500 requests; rebuild: about 142 s with 500 requests (about 1.7x); before: 4.8 messages/s (projected about 2.9 h). Because after and rebuild send the same number of serial requests, a slower provider should move the ratio toward 1; that is not measured. Per-row claim and settle writes (contract review 7252567666, N1) may show on a remote store.

Blocked-by: #38509
Not in scope: code changes (a finding goes to its own card).
Dedupe: knowledge drain real embedder 7 (none on this; #38413 itself) · record-sync drain measurement 8 (none on this) · knowledge 50,000 drain 1 (#38413 itself).

Activity

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

    @objectstack-fleet
    ContributorAuthor

    triage#1 · zhuangjianguo · session_01QsR2jRH2X4frz9bBiZHNk4

    Triage: a measurement on packages/services/service-knowledge with a real embedding provider · area:ai · domain:server · Task · p2 (it closes acceptance 2 of #38413, which it blocks) · pm:blocked (the body's Blocked-by: #38509, an open PR) · size M. Rationale: the card had no triage audit and no type. Type set to Task at this touch.

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

    @objectstack-fleet
    ContributorAuthor

    triage#1 · zhuangjianguo · session_01QsR2jRH2X4frz9bBiZHNk4

    Unlocked by the unlock scan: the body's Blocked-by: #38509 merged (a5fe764), so pm:blocked → pm:queue.

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

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · zhuangjianguo · session_01QsR2jTsdScTh3o2fSjbxSz

    Claim: PM loop round 3
    Session: session_01QsR2jTsdScTh3o2fSjbxSz
    Thread session: session_01QsR2jQrcqKfy7NuQRoeKzX
    Account: zhuangjianguo
    Branch: claude/project-thread-ybli6g
    Worktree: objectstack-issue-38529
    Domain: domain:server
    Seat: repo:objectstack#1
    Area: o1-know
    File surface: packages/services/service-knowledge/ read only, no file changed — a measurement on origin/main; report comments on #38529 and #38413 only; one-off scripts stay in the scratchpad (stop on breach; explain in the report)
    Container & model: M, mode:thread, model: default (no path-derived mandate; no code change), effort: high
    Clause-②: no — no code change
    Metadata-protocol: none
    Responsibility: n/a — not a defect card
    Thread-read: 7254400087
    Premise: holds (#38509 merged a5fe764; the maintainer supplied a real embedding provider through the Vercel AI Gateway as an environment variable, and ruled the store a local Turso (libSQL) instance in the container)
    Serial constraints cleared: the surface is read only and changes no file, so an in-flight claim on packages/services/service-knowledge/ does not wait on it, nor it on them; none

  7. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 29, 2026
  8. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · zhuangjianguo · session_01QsR2jQrcqKfy7NuQRoeKzX
    2026-11-29T13:09Z · measurement report for #38529 (acceptance 2 of #38413): a 50,000-record import drained with a real embedding provider, against a rebuild of the same records

    维护者速读

    • 结论:用真实向量化服务(经 Vercel AI Gateway 的 OpenAI text-embedding-3-small)实测,导入 5 万条后检索追上用了 9.5 分钟,同样数据整体重建 9.9 分钟,比值 0.96;关掉积压对账只走批量同步时是 13.4 分钟,比值 1.36。两种都在「重建时间的小倍数」之内,死信 0。
    • 发现一处浪费:默认配置下积压对账与批量同步同时跑完了全部数据,向量化请求数和写入量都是重建的两倍(987 次对 503 次)。原因是 fix(service-knowledge): widen the record-sync covered margin to the queue lease #38577 把“可跳过”的时间余量放宽到 30 秒,而这次导入只用了 34 秒,所以对账一条也跳不过。建议席位另立卡。
    • 存储按您的要求用容器内本地 Turso(libSQL 文件),不是远程库。
    • 要你做的:无。

    Setup

    • Code: origin/main 30141766 (contains feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509 a5fe7645 and fix(service-knowledge): widen the record-sync covered margin to the queue lease #38577). No code change; a one-off harness outside the repo.
    • Store: local Turso. The data and the queue are on TursoDriver with a file: URL (local mode, which runs on better-sqlite3). The vectors are on KnowledgeTursoPlugin with a file: URL (@libsql/client). Both are files in the container; no remote libsql:// database was used.
    • Embedder: OpenAIEmbedder from packages/plugins/embedder-openai, baseUrl https://ai-gateway.vercel.sh/v1, model openai/text-embedding-3-small, 1,536 dimensions. A gateway model name is not in the known-model tables, so maxBatchSize: 2048 and maxInputTokens: 8192 (OpenAI's documented caps) and dimensions: 1536 were set explicitly. Requests go through the container's egress proxy, so the latencies below include it.
    • Kernel: ObjectQLPlugin, QueueServicePlugin({ adapter: 'db' }) with default options, KnowledgeServicePlugin with one object source (contract_clause, content title + body, no where), buildAtBoot: false. sys_knowledge_sync_state was registered, so the sync state below is the durable one.
    • Records: 50,000 generated clause records, 90 to 140 words each. They split into 100,667 passages (about 2 per record), 7.54 M tokens per full embedding.
    • Import: a complete build over the empty table first (the index is current), then ql.insert in arrays of 500, which publishes one record-sync message per record. The drain is timed from the first publish to a queue with no pending or running message.
    • Rebuild: the drained data file copied, a fresh vector store, rebuildSource(…, { trigger: 'operator' }), timed to its end.

    Results

    run time embed requests (attempts) inputs adapter docs written dead letters sync state after
    drain, default (batch + backlog reconcile) 568.6 s 985 (987) 101,305 99,551 0 current, build done, failures 0
    drain, batch only (backlog reconcile off) 805.7 s 501 (502) 100,717 50,000 0 current, failures 0
    full rebuild, same 50,000 records 591.4 s 503 (503) 100,667 50,012 n/a current, build done
    • Ratio, drain over rebuild: 0.96 with the default configuration, 1.36 for the batch path alone. Acceptance 2's "within a small multiple of the rebuild time" holds in both. The LOCAL MODEL in PR feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509 gave 1.7, and the card expected a slower real provider to move the ratio toward 1. It did: 1.36 for the batch path alone.
    • Embed latency (per request of about 200 inputs): p50 691 / 832 / 781 ms and p95 1,165 / 1,107 / 1,039 ms for the default drain, the batch-only drain and the rebuild.
    • Failed requests: 2 in the default drain and 1 in the batch-only drain were network errors that the embedder's resilientFetch retried. None reached the queue: 0 dead letters, 0 failed syncs.
    • Import: 34.3 s and 35.3 s for the 50,000 inserts. The drain clock starts at the first publish, so it includes them.
    • Batch-only outcomes: 50,000 synced and 0 covered, in 501 handler calls (499 of 100 messages, plus one of 75 and one of 25).

    Where the time went

    Batch only, 805.7 s:

    Rebuild, 591.4 s: embed 406 s (69 %), writes about 168 s, reads about 17 s.

    The batch-only drain is 214 s slower than the rebuild:

    • 118 s of queue claim and settle;
    • about 54 s of embed latency (the same request count, at a higher p50 in that run);
    • about 42 s of extra write time.

    With the default configuration, the backlog reconcile began 6 s after the first publish. It walked all 49,551 records it found, so it is a second full build running beside the batch path. The two embed streams run at once, which is why the drain beats the batch-only time and lands slightly under the rebuild.

    Finding for the seat (no card filed here)

    With the default configuration, every record was embedded through two paths: 985 requests against the rebuild's 503, and 99,551 documents written against 50,000. The duplicated inputs mostly went unsent (101,305 inputs against 100,667 passages), because each path finds the passages the other already wrote. The requests and the writes were still doubled.

    The reason: a message completes as covered only when it was published at least RECORD_SYNC_COVER_MARGIN_MS (30 s since #38577) before the build began (knowledge-service.ts, the publishedAt < startedAt - RECORD_SYNC_COVER_MARGIN_MS check). This import published all 50,000 messages within 34 s, and the reconcile began 6 s after the first one, so the rule covered none of them. The batch path synced every message the reconcile had already indexed.

    This run did not count outcomes; the batch-only run did. That the default run covered none of its messages follows from the margin rule and the timestamps. Because the backlog reconcile starts as soon as about 5,000 messages wait, it begins early in any bulk import, and no message published less than 30 s before it began, or after, can be covered. So for a typical import the reconcile is pure extra work. It does not change acceptance 2, but on a paid provider it doubles the requests and the writes. Two possible fixes are to not schedule the backlog reconcile while every waiting message is inside the margin, or to cover by the walk's own read of each row. The choice is the seat's.

    Deviations

    • The order names the embedder option maxInputsPerRequest. The option is maxBatchSize, set to 2048.
    • The store is a local Turso (libSQL file) in the container, on the maintainer's word, not a remote database. Per-statement network round trips to a remote libsql:// store are not measured; review N1's per-row writes would cost more there.
    • Item 3 (a before figure) does not apply: the deployment includes feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509.
    • The rebuild's data file was copied with 75 queue rows still marked running. The rebuild boot reclaimed and synced them, which accounts for 12 extra adapter documents. It is negligible against 50,000.
    • The batch-only run turns the backlog reconcile off by stubbing considerBacklogReconcile in the harness, because no plugin option turns it off (reconcile: false governs the scheduled reconcile only).
    • Node's built-in fetch needs NODE_USE_ENV_PROXY=1 in this container. Without it, one request took 28 s.
    • Only the embeddings endpoint was called with the gateway key: no chat or LLM call.
  9. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · zhuangjianguo · session_01QsR2jTsdScTh3o2fSjbxSz

    2026-11-29T13:19Z · Done, with no PR: a measurement card. The report is 7256340769 (#38413 got 7256348494). Acceptance 2 holds: drain ÷ rebuild is 0.96 on the default configuration and 1.36 on the batch path alone, both a small multiple. The out-of-scope finding is filed as #38591. Claim 7255569219 closes with this comment; pm:dispatched comes off and the card closes as completed.

  10. removed
    pm:dispatched
    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

Labels

area:aidomain:serverpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions