Repository navigation
Fix #1382: [Feature Request] 知识库 List 接口 - list knowledgebases / list kb documents - #1981
Memtensor-AI wants to merge 1 commit into
Conversation
Adds two missing client methods to `MemOSClient` so callers can enumerate knowledgebases and the documents inside one, addressing issue #1382. Without these the SDK could create / delete a knowledgebase and fetch a file by id, but not discover what KBs or files exist — a hard dependency for bulk-delete and UI-picker flows. - New `list_knowledgebases(page, size)` → POST /list/knowledgebase - New `list_knowledgebase_documents(knowledgebase_id, page, size)` → POST /list/knowledgebase-file - New response models `MemOSListKnowledgebaseResponse` and `MemOSListKnowledgebaseFileResponse` with loose `extra="allow"` schemas so server-side additions never break the SDK - Page/size validation guard (`_validate_page_size`) raises ValueError before any HTTP call, matching the existing validation pattern - 17-case pytest suite in `tests/api/test_client_knowledgebase_list.py` covers happy path, validation rejection, retry recovery and retry exhaustion (all mocked `requests.post` — no live calls) Refs: #1382
✅ Automated Test Results: PASSEDNo applicable test scope for the changed files — automated tests skipped. Changed paths do not map to any configured scope (env.yaml source_mapping). Manual review recommended. Branch: |
🤖 Open Code ReviewTarget: PR #1981 🔍 OpenCodeReview found 35 issue(s) in this PR. 1.
|
Description
Adds the missing knowledgebase list APIs to
MemOSClient(issue #1382). Two new client methods —list_knowledgebases(page, size)callingPOST /list/knowledgebase, andlist_knowledgebase_documents(knowledgebase_id, page, size)callingPOST /list/knowledgebase-file— fill the previously missing enumeration capability that the SDK needed for downstream bulk-delete and UI-picker flows. Endpoint naming mirrors the existingcreate/,delete/,add/,get/verbs already used by the SaaS contract; pagination follows the 1-basedpage+sizepattern fromget_memorywith1 <= size <= 100validated before any HTTP call. Two new Pydantic response models (MemOSListKnowledgebaseResponseandMemOSListKnowledgebaseFileResponse) wrap looseextra="allow"data containers so server-side schema additions never break the SDK, and they reuse the existingFileDetailfor KB document entries.Implementation lives in
src/memos/api/product_models.py(4 new classes, 66 lines) andsrc/memos/api/client.py(2 new methods + shared_validate_page_sizehelper, 100 lines). A new 17-case pytest suite attests/api/test_client_knowledgebase_list.py(242 lines) was written TDD-first: it covers happy paths, request-shape verification (URL, JSON body, auth header), validation rejection ofknowledgebase_id="", out-of-rangepage/size, retry recovery after two transientrequests.ConnectionErrors, and final-retry exhaustion. All 17 tests pass; running them alongsidetests/api/test_server_router.pyandtests/api/test_cube_endpoints.pyyields 45 passed / 0 failed. Pre-existing failures intests/api/test_mcp_serve.py(missing pytest-asyncio in this environment) reproduce on the untouched base branch and are unrelated.ruff check+ruff formatclean.make openapiregeneration is not needed — the change is purely client-side; no FastAPI router undersrc/memos/api/routers/was touched.OPSP path: Feature Quick-Change (additive, no API surface beyond the SDK methods, no migration, no architectural impact). Artifacts archived to
memos-autodev-specs/2026-06-29-1382-...(commitc9b58deonmain). Branchbugfix/autodev-1382pushed tooriginat commit0013b17b; reviewers @MatthewZhuang @CarltonXiang @syzsunshine219 @World-controller.Related Issue (Required): Fixes #1382
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist