Repository navigation
Conversation
jasper-yl
force-pushed
the
feat/knowledge-base-plugin
branch
from
November 12, 2026 07:55
c0c14c8 to
25f4125
Compare
One plugin directory shows the plugin interfaces end to end: every knowledge base is a Scope the plugin creates, every file a document Artifact. Uploads wait for a parser unless the knowledge base has a default; processing and chunk edits are Sources the plugin defines, so every revision records what produced it. Generation parses Markdown, text, and PDF into content-addressed chunk sets, embeds them with the Server's model, and search and question answering run in the plugin's own routes. The ui directory is its Dashboard page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jasper-yl
force-pushed
the
feat/knowledge-base-plugin
branch
from
November 12, 2026 09:23
e8c02b5 to
94df366
Compare
…irst revision commits Generation marks a submission before its write commits, so a new document had no Artifact for a moment and dropped out of the listing. The acceptance test also waited on a condition that an empty listing satisfied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir revision commits Marking before the commit let a document look ready at its old revision, so the page reported a successful edit as dropped. A submission whose mark was lost is recognized from the revision it produced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Closing: based on the fork-only framework branch, which upstream replaced with oceanbase#2616. The branch is kept. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 是什么
在插件框架分支(
feat/plugin-framework)之上,只加入一个知识库(RAG)插件,用来展示一个完整的插件怎么写。差异里只有插件本身、它的端到端测试和 pypdf 开发依赖,没有框架代码。插件对应 RFC oceanbase#2549(插件接口)和 oceanbase#2579(热加载、插件接口与页面)。
怎么读
建议按这个顺序:
README.zh.md:插件做什么、怎么部署、在 Dashboard 和接口中怎么用。插件开发的通用说明在框架 PR feat(plugins): plugin framework — Artifact plugins, plugin APIs, and Dashboard pages #6 的教程docs/zh/docs/develop/plugins.md。examples/plugins/knowledge_base/plugin.py末尾的plugin = ArtifactPlugin(...):整个插件的声明。family="document":每个文件对应一个documentArtifact。inputs=Inputs(source_types=..., projections={...}):消费哪些 Source 类型、每种类型按哪个 Projection 交付;on_sources=True表示有新 Source 就处理。definitions=(...):插件自带的两个 Source 定义(上传 / 重新解析请求、切块编辑)。api=PluginApi(routes=...):插件自己的 HTTP 接口,挂在/v1/plugins/knowledge-base/api/...。pages=PluginPages(...):Dashboard 页面,静态文件在ui/。create=create:工厂函数,拿到ctx(专属存储、模型、请求辅助方法)后返回插件对象。DocumentUploadDefinition、ChunkEditDefinition):Source 记录"用户要求做什么"——上传记录文件摘要和解析方式,编辑记录编辑人、基于的版本和保存的切块组。文件和切块本身存在插件自己的存储里。KnowledgeBasePlugin的各方法):create_knowledge_base调ctx.scopes.create建 Scope,再在插件库里记映射;响应里不出现 Scope。ctx.allowed/ctx.require按调用者检查 Scope 权限;建库、删库要server.admin。process_documents再用ctx.sources.submit提交 Source。ctx.reads(scope_id);写:ctx.writer(scope_id),只在ctx.require("scope.contribute")之后可用。_search做关键词(BM25)+ 向量混合检索;ask用ctx.models.generate调 Server 配置的生成模型。generate:后台处理。按 Source 类型分支:上传就解析、切块、生成向量;编辑就检查文档仍在被编辑的版本。慢的工作在事务外做,最后在一个writer.transaction()里写新版本,并引用对应的 Source 作为出处。forget_artifact、restore_artifact:让通用 Artifact 接口的遗忘、恢复对document生效。kb_store.py(插件自己的表:知识库、原文件、提交记录、按内容寻址的切块组和向量)、kb_parsers.py(解析器注册表与 PDF 提取)、kb_text.py(分词、BM25、排序融合)。ui/:页面运行在沙箱 iframe 里,通过powercontextPluginClient()请 Dashboard 转发请求,只能调用本插件声明的路由,拿不到用户会话。tests/e2e/test_knowledge_base_plugin.py:启动真实 Server 走完整流程——建库、批量上传后统一选择解析方式、撤销上传、检索、问答、编辑切块(含编辑出处和并发编辑冲突)、恢复版本、换解析方式重新处理、PDF 按页切块、跨知识库检索。插件之外需要部署者做的
requirements.txt只是说明,core 不会读取)。没装时插件不接受 PDF,其他格式不受影响。验证
uv run pytest tests/e2e/test_knowledge_base_plugin.py uv run ruff check examples/plugins/knowledge_base && uv run ty check examples/plugins/knowledge_base另外在 Chromium 中配合真实 OpenAI 模型(text-embedding-3-small、gpt-4.1-mini)手动走过 Dashboard 页面的上传、处理、编辑、问答流程。
AI 使用说明
代码、测试和本说明由 Claude Code(Claude Opus 5.5)在作者的指导下编写,作者审阅设计决定;测试与手动验证由 Claude Code 执行并核对结果。
🤖 Generated with Claude Code