Skip to content

feat(memory-core): add L1 atomic memory import API with dedup - #1178

Open
elementlo wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
elementlo:feat/l1-memory-import
Open

elementlo wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
elementlo:feat/l1-memory-import

Conversation

@elementlo

@elementlo elementlo commented Aug 27, 2026

Copy link
Copy Markdown

Add a user-driven L1 atomic memory import path that bypasses the
L0->L1 distillation pipeline, letting users bulk-write personal
memory records (from markdown/json/txt files or JSON arrays) directly
into the L1 atomic layer for model recall.

MemoryCore kernel

  • v2-router.ts: add handleAtomicCreate handler, register /atomic/create
    route (dual-mounted on /v2 and /v3), batch create up to 500 records
    per request with server-generated record_id (m_{timestamp}_{hex})
  • Dedup on create: before writing, search existing L1 memories with a
    3-tier fallback — vector search (searchL1Vector) -> FTS
    (searchL1Fts) -> exact content match (queryL1Records, works in
    standalone mode without embedding/FTS5). Modes: skip / update,
    configurable threshold (default 0.85). Isolated by team+agent+user.
  • generated/schemas.ts + types.ts: atomicCreateRequestSchema /
    atomicCreateDataSchema and AtomicCreateRequest / AtomicCreateData
    types (with dedup field and skipped/updated response counters)
  • v2-schemas.ts: re-export the new schemas and types

MemoryPanel

  • chat-memory.ts: POST /chat-memory/import-memories route accepting a
    JSON array or file text (.md/.json/.txt), parsed then forwarded to
    /v3/atomic/create
  • chat-memory-import-parser.ts (new): markdown/JSON/TXT parser, splits
    by ## heading or paragraph
  • web: standalone ImportMemories page as a left-menu item (parallel to
    Chat Memory, not a tab inside it) — ImportMemoriesPanel supports
    paste/upload, live parse preview, optional dedup, and lists existing
    L1 memories after import

SDK

  • TypeScript: createMemories method + V3AtomicCreateRequest/Record/
    Dedup/Data types
  • Python: create_memories method (sync + async)

Design decisions

  • Isolation inherits the V3 router's team+agent+user triple check
  • Soft classification via type + scene_name (aligned with existing L1
    model); no URI namespace
  • handleAtomicUpdate untouched (keeps update-only semantics; create
    goes through the new endpoint)

Tested

  • skip mode: identical content -> created=0, skipped=1
  • update mode: identical content -> created=1, updated=1, id reused
  • distinct content -> created=1
  • user isolation: other-user cannot query test-user's memories
  • MemoryCore typecheck 0 errors; tsx boots on 8420

Add a user-driven L1 atomic memory import path that bypasses the
L0->L1 distillation pipeline, letting users bulk-write personal
memory records (from markdown/json/txt files or JSON arrays) directly
into the L1 atomic layer for model recall.

## MemoryCore kernel

- v2-router.ts: add handleAtomicCreate handler, register /atomic/create
  route (dual-mounted on /v2 and /v3), batch create up to 500 records
  per request with server-generated record_id (m_{timestamp}_{hex})
- Dedup on create: before writing, search existing L1 memories with a
  3-tier fallback — vector search (searchL1Vector) -> FTS
  (searchL1Fts) -> exact content match (queryL1Records, works in
  standalone mode without embedding/FTS5). Modes: skip / update,
  configurable threshold (default 0.85). Isolated by team+agent+user.
- generated/schemas.ts + types.ts: atomicCreateRequestSchema /
  atomicCreateDataSchema and AtomicCreateRequest / AtomicCreateData
  types (with dedup field and skipped/updated response counters)
- v2-schemas.ts: re-export the new schemas and types

## MemoryPanel

- chat-memory.ts: POST /chat-memory/import-memories route accepting a
  JSON array or file text (.md/.json/.txt), parsed then forwarded to
  /v3/atomic/create
- chat-memory-import-parser.ts (new): markdown/JSON/TXT parser, splits
  by ## heading or paragraph
- web: standalone ImportMemories page as a left-menu item (parallel to
  Chat Memory, not a tab inside it) — ImportMemoriesPanel supports
  paste/upload, live parse preview, optional dedup, and lists existing
  L1 memories after import

## SDK

- TypeScript: createMemories method + V3AtomicCreateRequest/Record/
  Dedup/Data types
- Python: create_memories method (sync + async)

## Design decisions

- Isolation inherits the V3 router's team+agent+user triple check
- Soft classification via type + scene_name (aligned with existing L1
  model); no URI namespace
- handleAtomicUpdate untouched (keeps update-only semantics; create
  goes through the new endpoint)

## Tested

- skip mode: identical content -> created=0, skipped=1
- update mode: identical content -> created=1, updated=1, id reused
- distinct content -> created=1
- user isolation: other-user cannot query test-user's memories
- MemoryCore typecheck 0 errors; tsx boots on 8420

Signed-off-by: zhanglongzhan <lawliet.zhan@outlook.com>
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you so much for your attention and contribution! We will arrange an internal review for this PR shortly, and all feedback will be shared right here in the discussion.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants