Skip to content

knowledge-pgvector: an open vector store on PostgreSQL — tables, exact search, listing, chunks #37100

Description

@os-bob

maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000 (phase 2 row 8); boundary cloud ADR-0119 D5 (objectstack-ai/cloud#4968: 「都放开源」); maintainer 2026-11-24 「用fable评审,并分拆第二阶段的任务」. Reviewed by an independent Fable pass before filing.
Grading: area:ai · Feature · p2 (topic) · reach: self-hosted deployments on PostgreSQL · evidence: read.

维护者速读

  • 做什么:新增开源包 knowledge-pgvector。自建部署用 PostgreSQL 时,不装外部检索引擎也有向量检索,多组织的数据互不串。
  • 要知道的:
    • 数据库要装 pgvector 扩展。
    • 要配置嵌入服务商,文本会发给它。
    • 换模型后要重建,重建期间检索暂不可用(重建在另一张卡)。
  • 谁受益:企业版和开源版的 PostgreSQL 部署;BrightRule 可以删掉自己写的 pgvector 代码。
  • 需要你做的:无(它依赖的 CI 镜像卡要你手工合并)。

What

  1. packages/plugins/knowledge-pgvector (new, Apache-2.0), rewritten from BrightRule's store (objectstack-ai/brightrule src/qa/vector/pgvector-store.ts, adapter.ts), not lifted.
  2. Storage: one table per vector dimension, knowledge_vec_d<dim>: source_id, generation, chunk_id, document_id, source_record_id, organization_id, content, doc_hash, chunk_hash, metadata jsonb, embedding vector(<dim>); created only when a new dimension appears. A generation table: source_id, generation, fingerprint, dim, model, state, created_at. Check the table names cannot collide with object tables, and that schema-drift checks do not report them (state the result).
  3. Connection: its own small pool built from the platform database's connection settings when that database is PostgreSQL (state how the settings are read), else a configured URL. No pooled connection is held across an embed call. State the schema, and which database is used when organizations have separate databases.
  4. Missing vector extension or DDL right: the adapter does not register its tables; knowledge calls answer a readable error carrying the SQL to run by hand; healthCheck is false; boot continues.
  5. Search: exact scan (HNSW documented as an operator step, with its dimension limit). Organization filter in SQL from service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097's organizationIds. Today's opaque metadata-equality filter applied in SQL before ranking.
  6. Fingerprint: the one ADR: knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split and record-level return; knowledge_source becomes a governed type #37001 defines (model + dimensions + split config + split algorithm version + content recipe), computed by the service and handed to the adapter (member per ADR: knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split and record-level return; knowledge_source becomes a governed type #37001; this card is its reader). IEmbedder.model? lands here (the fingerprint reads it); embedder-openai fills it. A stored fingerprint that differs from the current one marks the source as needing a rebuild, and search answers a clear "rebuild needed" error until knowledge-pgvector: a changed fingerprint builds a new generation and switches to it #37101's build runs.
  7. Unchanged content (same chunk_hash, computed by the adapter over the text it embeds) updates metadata only, no re-embedding.
  8. Implements listDocuments (service-knowledge: adapters list their documents; a complete reindex skips unchanged documents and purges the ones its source no longer has; one contract test suite #37096), accepts chunks (service-knowledge: one service-layer splitter (whole / recursive / markdown, Chinese-aware), the chunk channel and the split key #37098). Plugin option queryPrefix for asymmetric models (BGE).
  9. The service-knowledge: adapters list their documents; a complete reindex skips unchanged documents and purges the ones its source no longer has; one contract test suite #37096 contract suite runs in CI against PostgreSQL with pgvector (CI: the PostgreSQL job runs on an image with the pgvector extension #37095); no skip path. Tests use a fixed fake embedder.
  10. Docs: content/docs/protocol/knowledge.mdx (lines 87 and 430 say "planned" / "Phase 3"), content/docs/ai/knowledge-rag.mdx; the content column is as sensitive as the source data and is in backups.

Acceptance

Out of scope

Blocked-by: #37001, #37096, #37098, #37095, #37097.
Parent: #37000. Reader: domain:server lane (packages/plugins/knowledge-*).
Dedupe: pgvector 5 (open: #37000, #37001, a seat post — no card) · knowledge generation fingerprint 12 (open: #37000, #37001, a seat post).

Activity

  1. added theissue type on Nov 24, 2026
  2. added
    priority:p2
    area:ai
    on Nov 24, 2026
  3. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: first touch 2026-11-24T20:35Z

  4. added
    domain:server
    pm:blocked
    on Nov 24, 2026
  5. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    Scope note (2026-11-24T21:24Z), from the reviews of the knowledge-platform ADR (PR #37119: contract review 7144861870, L1 7144881422), verified against origin/main. Area: a4-K.

  6. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Seat note: surface addition · 2026-11-24T21:25Z · verified in the contract review of ADR-0161 (PR #37119, 7144861870): packages/services/service-knowledge KnowledgeService.search today logs an adapter error and continues, and the tool then tells the model nothing matched — so this card's "rebuild needed" refusal would reach the caller as an empty answer. This card therefore also changes search so an adapter refusal surfaces as a refusal, with a pin; its claim declares that file beside packages/plugins/knowledge-*.

  7. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    Update to scope note 7144903681 (2026-11-24T21:55Z), after the knowledge-platform ADR's third review (PR #37119 head 4fa0cdc, contract review 7145549687 PASS). Area: a4-K.

    • Item 8 lands whole, once: the ADR's K8 item 8 (fingerprint function, beginBuild / completeBuild, indexStatus, the recipe hash, with IEmbedder.model and the descriptor's model and dimensions) lands whole in whichever of this card and service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099 merges first, with knowledge-memory as the reference. If this card is first, it carries all of item 8 and its suite cases (including one holding beginBuild and completeBuild as a pair).
    • The several-sources answer is now settled by the ADR (K7 rule 5): the searchable sources answer, each refused source is named with its code, the call is refused whole only when none can be searched. What stays here is the carrier: where IKnowledgeService.search reports the refused sources (this card, or a card split from it for the service's lane).
    • Unchanged from 7144903681: the catch in KnowledgeService.search must let a coded refusal through, so this card's surface includes packages/services/service-knowledge/src/knowledge-service.ts.
  8. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    One more case for this card's suite (2026-11-24T22:09Z), from the L1 of PR #37129 (#36992, comment 7145865808). Area: a4-K.

    • reindexSource now walks a source in id order (orderBy id asc, id > cursor). That order was checked once on SQLite, not on PostgreSQL; a PostgreSQL column with a non-C collation is where the engine's sort and its $gt could disagree. Since this card brings the first real PostgreSQL to the knowledge suite, add one reindex-over-a-real-driver case here: mixed-case and numeric-looking ids, every row indexed once, none skipped.
  9. added
    pm:queue
    and removed
    pm:blocked
    on Nov 25, 2026
  10. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    Claim: PM loop round 2 (epic #37000 owner seat, card thread)
    Session: session_01JQwxbW5anP6GDaVi5LKi2U
    Thread session: session_01JQwxbX5BF433x8ooJNQVRp
    Account: os-warren
    Branch: claude/project-thread-vcp8s3
    Worktree: objectstack (the card thread's own checkout)
    Domain: domain:server
    Seat: repo:cloud#1
    File surface: packages/plugins/knowledge-pgvector/** (new), packages/plugins/knowledge-memory/**, packages/plugins/embedder-openai/**, packages/services/service-knowledge/**, packages/spec/src/contracts/knowledge-adapter.ts and packages/spec/src/contracts/embedder*.ts, content/docs/** knowledge pages, .changeset/. CI wiring for the pgvector suite only if the existing PostgreSQL job (pgvector image since #37095) cannot run it; a .github/workflows/** edit makes the PR Tier H (maintainer approval) and is stated in the report (stop on breach; explain in the report)
    Container & model: L, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate; floor sonnet · default opus · ceiling fable), effort: high
    Clause-②: yes
    Metadata-protocol: none
    Responsibility: n/a — not a defect card
    Thread-read: 7169815087
    Premise: holds (Blocked-by #37001, #37096, #37098, #37095, #37097 all closed; read 17:45Z)
    Serial constraints cleared: #37103 (this seat, branch claude/project-thread-oc6nsu) edits KnowledgeService.search in packages/services/service-knowledge/src/knowledge-service.ts; overlap-check before each push, the second to land merges main. ADR-0161 Execution: K8 item 8 (fingerprint and recipe hash, descriptor model/dimensions, parts a/b/c, their contract-suite cases, knowledge-memory as reference) lands whole here because #37099 waits on PR #37265. #37107 and #37101 build behind these members and are held until this merges. Maintainer ruling 7168239918 on #37304 (Q1 = B): per-package store keying reaches this adapter in #37304 if this lands first; build nothing for it here.

    Ownership: maintainer 2026-11-25 13:49Z, 「#4 只负责在手任务,你接手专题剩余任务」; unlocked by triage 17:41Z. Clause-② yes: the adapter-contract members owe a contract review at the ceiling tier before the queue.

  11. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 25, 2026
  12. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbX5BF433x8ooJNQVRp
    os-dev-report

    {
      "issue": 37100,
      "status": "done",
      "branch": "claude/project-thread-vcp8s3",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37337",
      "session": "session_01JQwxbX5BF433x8ooJNQVRp",
      "premise_still_valid": true,
      "summary": "New package @objectstack/knowledge-pgvector: passages and vectors in PostgreSQL + pgvector in its own schema os_knowledge (generation table + one passage table per width), exact cosine scan with the organization and metadata filters in SQL before ranking, chunk-hash skip of re-embedding, listDocuments in byte order, readable SERVICE_UNAVAILABLE with the SQL when the extension or schema rights are missing (boot continues, healthCheck false). K8 item 8 lands whole: service-side fingerprint + recipe hash on every adapter call, beginBuild/completeBuild around a complete reindex, indexStatus, IEmbedder.model, coded KNOWLEDGE_REBUILD_REQUIRED refusals that search names per source (searchWithRefusals; search_knowledge adds refused), knowledge-memory as the generations reference, 9 new contract-suite cases. CI: two steps in Temporal Conformance run the package's live-postgres files (Tier H: .github/workflows/ci.yml).",
      "tests": "head 4ab06c2f, local PG16+pgvector: knowledge-pgvector Test Files 4 passed, Tests 48 passed (OS_EXPECT_LIVE_DIALECT_MATRIX=1); no URL 7 passed | 41 skipped; flag without URL 3 named failures. service-knowledge Tests 291 passed (12 files); knowledge-memory 43 passed; embedder-openai 31 passed; typecheck green x4. Ablations (trap-restored): org filter removed 6 failed | 42 passed; chunk-hash skip removed 1 failed | 47 passed; search fingerprint check removed 4 failed | 44 passed; restored 48 passed.",
      "gates": "dispatch-gates --commands: 167 run, 162 exit 0; check-tenant-audit-census exit 1 fixed in b505ecc5 (re-run 0); exit 3 NOT MEASURED (prerequisite refusals): check-plugin-teardown-shape --self-test (shallow clone), check:skill-examples, check:dual-build-cjs-loads, check:published-readme-exports (full build). Note: the gate run overlapped commits 2dda2561..b505ecc5. CI at 4ab06c2f when written: 29 success, 9 skipped, 30 in progress, 0 failed; earlier-head reds (engine-double contract, llms.txt count, test-source alias, system-context census, test type error) each fixed by a later commit.",
      "dogfood_battery": "n/a — no ! in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2 relay strokes — pr_create (POST /repos/objectstack-ai/objectstack/pulls + assignees), issue_patch PR #37337 body",
      "open_questions": [
        {
          "question": "Where does the refused-sources report live? KnowledgeService.search keeps its signature (K9 rule 3); searchWithRefusals is a class method that search_knowledge reads structurally.",
          "options": [
            "A keep it on the class (this PR)",
            "B add an optional IKnowledgeService.searchWithRefusals? member with a K9 dated note"
          ],
          "recommendation": "A, until a second consumer needs it"
        },
        {
          "question": "The PR edits .github/workflows/ci.yml (two Temporal Conformance steps + one temporal_live path), which makes it Tier H.",
          "options": [
            "A keep the CI edit here (the card's acceptance needs the suite in CI on real PG)",
            "B split the CI edit into its own PR"
          ],
          "recommendation": "A"
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: #37335 (#37103) — once it merges, pgvector hits must carry docHash (K8 item 3) and headingPath (item 14); heading_path is already stored; whoever lands second merges main · noted, not filed"
      ]
    }

    Generated by Claude Code

  13. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    ACCEPT → PR #37337 comment 7174823480 (round 3: L1 ACCEPT + contract review PASS at head 065c98f; rounds 1 and 2 REWORK 7172706810, 7174494844). Tier H (ci.yml and over 3000 lines): handed to the approver (comment 7175354882, pm:awaiting-merge), stays draft. The two new live-PostgreSQL CI steps have not yet run in CI; the landing seat reads the queue entry's run. #37107 starts when this merges.

  14. removed
    pm:dispatched
    on Nov 25, 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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions