Skip to content

feat: implement knowledge-base plugin with revisioned chunks and Dashboard - #2658

Merged
Zxf-xufeng merged 78 commits into
masterfrom
codex/knowledge-base-plugin
Nov 21, 2026
Merged

Zxf-xufeng merged 78 commits into
masterfrom
codex/knowledge-base-plugin

Conversation

@Zxf-xufeng

@Zxf-xufeng Zxf-xufeng commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Which issue or RFC does this PR close?

Implements RFC #2570; refs #2440, #2441, #2442, #2443 and #2444. Uses the public plugin contracts from #2659 and #2660.

Dependency integration: #2710 is merged into this branch at 16ab67ae0, together with master at c1a1bc42e. #2710 owns the shared CI/cache/test-sharding changes and the SQLite usage-recorder setup-expiry fix. CI validates this combined branch. Merge #2710 into master first, then refresh this branch and verify the final diff before merging the plugin; the dependency is not a separate knowledge-base implementation of those core fixes.

Rationale for this change

Users need to import Markdown and standalone text images, search selected knowledge bases, and maintain chunks with revision evidence. One business plugin owns the document family. Each knowledge base is a core Scope; organizational spaces, defaults and membership are plugin-owned data.

What changes are included in this PR?

  • Copy-installable plugins/knowledge-base: OpenDAL local snapshots, immutable original and processing Sources, RapidOCR, structural Markdown chunking, and public cursor/Supervisor consumption.
  • Four plugin domain tables plus derived search projections in framework-provisioned plugin storage. Compact document manifests publish immutable chunk results. Synchronous edits and chunk removals create a new revision and evidence Source; forget changes lifecycle and preserves history.
  • Permission-checked hybrid retrieval, exact citations, current-result filtering, generic search/Prepared Context, pinned processing requests, retry reconciliation and per-file import receipts.
  • Plugin APIs and an OceanBase-component Dashboard for spaces/defaults, libraries, browser upload and local import, processing status, chunk browsing/editing, reprocessing, forgetting and cross-library retrieval. Document operations use the public Artifact bridge with revision preconditions.
  • Accepted browser uploads and local-directory imports enter the existing processing watcher, including successful entries in a partially failed batch. Completion tracking survives closing the receipt dialog and leaving the document tab; publication invalidates displayed retrieval, preserves query criteria and prompts a fresh search.
  • Chunk batch-get rejects duplicate IDs with HTTP 422; valid requests preserve input order.
  • Batch document forget/reprocess and atomic chunk removal. Navigation clears incompatible selections and rejects stale responses; published changes invalidate displayed retrieval results. Reprocessing protects manual edits unless explicitly authorized to replace them.
  • Bilingual usage guides, plugin frontend sources and generated assets, plugin regressions and optional dependencies.
  • A dedicated Main-workflow job and required result-gate entry. CI admission covers plugin files and the transitive dependency closure of its optional extra/test group; unrelated core dependency changes do not force the plugin job. Explicit full validation still includes it.

The knowledge-base implementation uses public framework APIs and plugin-private storage. Outside the plugin directory, its own changes are limited to the frontend, guides/tests, optional dependencies and generated locks, type-check/license configuration, and plugin CI admission/job. The branch also includes the explicitly merged #2710 dependency, whose shared CI, usage-accounting and related test changes remain visible against master until that PR lands. The upgrade-support review preserves current master's schema declaration and #2710's accounting rationale with a recalculated combined digest; this merge adds no migration. The generic Dashboard implementation is inherited unchanged from master.

Are there any user-facing changes?

Install powercontext[server,knowledge-base] and copy the plugin into the Server plugin directory. Server and Worker share a local snapshot directory. SQLite, embedded SeekDB and OceanBase MySQL tenants use framework-provided dedicated storage. Independent deployments sharing a SQL tenant must isolate plugin databases/accounts.

The plugin uses its own pinned BAAI/bge-small-zh-v1.5 embedding configuration. Host navigation and global Scope selection are unchanged. No core columns or generated HTTP contract change. PDF/Office, generated answers, remote storage, restoration, permanent cleanup, online model switching and large-corpus performance guarantees are outside this release.

How was this change tested?

  • Reproduced the review defects before the fixes: duplicate chunk IDs returned HTTP 200 with repeated items, and displayed v1 retrieval remained visible after an accepted import published v2.
  • uv run --no-sync pytest tests/knowledge_base tests/e2e/test_knowledge_base*.py tests/e2e/test_plugin_pages.py -q — 48 passed, 7 skipped, including real Chromium Dashboard regressions against isolated Servers. New coverage exercises browser upload and local-directory import, partial acceptance, closing the dialog/tab navigation, publication invalidation, preserved query criteria and fresh v2 retrieval. API coverage verifies duplicate rejection and valid batch ordering.
  • uv run --no-sync pytest tests/test_ci_cache.py tests/test_ci_changes.py tests/test_ci_pipeline.py tests/test_ci_shard_collection.py tests/test_workflow_actions.py tests/builtin/runtime/test_model_usage_recorder.py -q — 330 passed, 5 skipped on the combined branch.
  • make check, final uv run --no-sync prek run -a, explicit plugin ty check, frontend production build and git diff --check passed.

Optional native SQL/real-model cases were not exercised in this review-fix validation. Existing local test-instance data was untouched. CI is rerun on the combined branch; its remote result must be checked separately from these local results.

AI usage statement

OpenAI Codex assisted with implementation, review fixes, regression tests, documentation and validation.

@jasper-yl

jasper-yl commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Regarding the changes to builtin/plugins/storage.py, see the note on RFC #2570: #2570 (comment) . Three-backend ctx.storage will be implemented on the framework side following #2549; please remove that part from this PR.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 3079efca9579d349cbfa72b5068ea09318034750. Three reproduced correctness issues need fixes: import-root containment under directory replacement, recovery after default-space access revocation, and conflict-status recovery after cursor commit. Details are attached inline.

@jasper-yl

jasper-yl commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

On the framework changes in this PR: please do not merge them yet

Besides the knowledge-base plugin, this PR changes the plugin framework (src/powercontext/plugins.py, builtin/plugins/{host,storage,writer}.py, server/dashboard/). These changes affect every plugin, and we would like to implement and review them separately on the framework side. Please remove the changes under src/powercontext/ from this PR. Item by item, with the RFC text amended in #2659:

Change Conclusion
Three-backend ctx.storage Implemented on the framework side following RFC #2549; see the note on #2570. The plugin can use the framework's ctx.storage or connect to its own database.
Evidence keeps the caller's submitted content (submitted_content) The direction is right: RFC #2549 already requires storing the content the caller submitted, and master deviates from it. The framework will fix this; #2659 states it explicitly.
Dashboard forwarding of generic Artifact operations (artifact_actions) Provided by the framework: a plugin page can call all generic Artifact APIs of its plugin's family, with no declaration. See the amendment to RFC #2579 in #2659.
tx.put(expected_state_version=...) The problem is real (forget does not change the revision). The framework will check it automatically: for an Artifact the plugin read outside the transaction, a write is checked against both the revision and the governance state version it read, and the plugin passes no parameter.
ctx.require("artifact.write", scope_id, artifact_id=...) Agreed. The framework will adopt it and RFC #2579 will state it.
Binding access to the transaction connection inside the write transaction Being reproduced. Once confirmed, the framework will fix it with a test.

On the storage database name: the code comment says hashing avoids aliases between a-b and a_b. Plugin names are validated with ^[a-z][a-z0-9-]{0,63}$, which does not allow underscores, so replacing - with _ cannot alias and no hash is needed; a hashed name also prevents deployers from pre-creating the database as the RFC describes. Several deployments sharing one instance, and long plugin names exceeding the database name limit, will be handled in the framework implementation and RFC.

Review comments on the plugin itself (plugins/knowledge-base/, docs, and tests) will follow separately. Once the framework PRs are merged, the plugin can use these capabilities directly, and the plugin-side design does not need to change.

@jasper-yl

jasper-yl commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Following up on "binding access to the transaction connection inside the write transaction" from the previous comment: reproduced, confirmed as a framework defect, and we will fix it.

Reproduction: on this PR's head (3079efc), remove only the access binding in PluginArtifactWriter.transaction and change nothing else. On a SQLite deployment with enforced access, a user change whose put carries source_refs makes the generic PUT return 500 after about 5 seconds, with AccessUnavailableError from the host process; with the binding in place the same tests pass. The fix and a regression test will be in a framework PR, and we will implement the other five items as well.

@Zxf-xufeng

Zxf-xufeng commented Nov 15, 2026 •

Copy link
Copy Markdown
Member Author

Addressed the framework ownership feedback in 6080d1b. The PR diff against master now contains no src/powercontext/ or framework developer-documentation changes. Dedicated storage, original edit-payload evidence, transaction-bound authorization, Artifact write checks, governance race protection and the generic Dashboard bridge belong to #2659/#2660.

The plugin uses the upstream client.artifacts bridge and writer governance tracking; it no longer declares artifact_actions or passes expected_state_version to put. SQL storage follows the framework’s plugin-name namespace. Optional OCR/model and browser-test dependencies are isolated from the default development dependency group. The follow-up 3adae70 runs plugin type checks explicitly in plugin CI; default-environment make check also passes without those optional dependencies.

The RFC and usage guides state the dependency explicitly. Integration was verified against #2660 at 2ffa8a8f; native SeekDB/OceanBase acceptance was not rerun against that head. This PR should merge after the framework prerequisites. The Dashboard navigation race also has browser coverage that fails on the original implementation. No additional blocking plugin-scope issue was found in the final review.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasper-yl

jasper-yl commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Framework-side confirmation: the prerequisites are merged and nothing is outstanding at the framework boundary

#2659 and #2660 are both on master (#2660 merged as c143960). Thank you for moving the framework changes out and for revalidating after merging master.

We checked the framework-related parts at 33d88884a:

  • The branch contains c143960, and its diff against master has no changes under src/powercontext/.
  • The plugin uses the merged interfaces: the page reaches documents through client.artifacts, storage goes through ctx.storage, and replacing an existing document first calls ctx.require("artifact.write", scope_id, artifact_id=...). It no longer declares artifact_actions or passes expected_state_version to put.
  • Outside the plugin, the changes are limited to CI configuration, the optional dependencies in pyproject.toml, and lock files.

This covers the framework boundary only and is not a full review of the plugin's own logic; @hidb4ai's review stands for that.

Two items remain before merge, both already stated in your description:

  1. CI is still running on the current head.
  2. Real OceanBase acceptance has not been rerun against this master. Three-backend ctx.storage is newly merged, so we suggest running it before merge. If it helps, we can run tests/knowledge_base/test_sql_backends.py on our OceanBase CE 4.3.5 environment.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed b75c066646eff4e1aa99d552db7f453249f94280. I did not reproduce a remaining correctness defect in the updated canonical-caller storage or plugin API handlers. Native storage upgrade, real Server routes and restart behavior were checked. The remaining cross-PR coordination and stale scope description are covered in the existing discussion. This feature adds plugin tables and APIs, so approval remains a manual decision under the requested review criteria.

@frf12 frf12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 6d4ca1250cdc4e58734b7c8ed0126db41e8632f0. The earlier CI admission concern is addressed: plugin-related changes and full validation select this suite; core/framework-only changes do not.

Two reproduced findings are attached below. Please address the import-completion refresh issue; the duplicate-ID validation discrepancy is non-blocking. The documented #2710 merge prerequisite and subsequent CI rerun still apply.

Comment thread frontend/knowledge-base/src/hooks.ts Resolved
@AlexStocks

Copy link
Copy Markdown
Contributor

@Zxf-xufeng 为何这个 pr 的 github ci 全部失败了?

@Zxf-xufeng

Copy link
Copy Markdown
Member Author

@AlexStocks Regarding your CI question: the latest Main run was intentionally cancelled while we wait for #2710. The current checks show 28 cancelled, 14 skipped and 1 successful; these are not all failing tests.

We removed the duplicated core usage-accounting fix and unrelated CI changes from this knowledge-base PR to keep its scope limited to the plugin. #2710 owns the shared fixes and remains open. The intended order is to merge #2710, synchronize this branch with master to include those fixes, and then rerun the full CI suite on the updated head. CI is paused until that dependency is incorporated; we are not rerunning the current head or duplicating the core fixes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants