refactor(database,app): unify INDEX/MEMORY/SKILL on Resource + Entry backbone#446
Open
sairin1202 wants to merge 2 commits into
Open
refactor(database,app): unify INDEX/MEMORY/SKILL on Resource + Entry backbone#446sairin1202 wants to merge 2 commits into
sairin1202 wants to merge 2 commits into
Conversation
…backbone Replace the MemoryCategory/MemoryItem/CategoryItem model with a single lane-tagged backbone: Resource (raw inputs and generated lane docs), Entry (searchable atoms), and ResourceEntry (membership edges). Storage, memorize, retrieve, CRUD, and the markdown projection now share one symmetric pipeline parameterized by lane across the inmemory, sqlite, and postgres backends. Also prune historical dead code: legacy JSON prompts (PROMPT_LEGACY), the superseded non-workflow retrieval methods, unused SQL base helpers, and other orphaned wrappers. See docs/adr/0006-unified-resource-entry-lane-backbone.md. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors memU’s storage and app layers to a unified lane-based backbone, replacing the historical MemoryCategory/MemoryItem/CategoryItem model with Resource + Entry + ResourceEntry across all backends and workflows, and aligning the markdown exporter + docs with that architecture (ADR 0006).
Changes:
- Introduces lane-tagged
Resource(raw + generated docs) and lane-taggedEntry(searchable atoms), linked viaResourceEntrymembership edges. - Updates SQLite/Postgres/InMemory repositories and protocols to use the new backbone (incl. lane-filtered list/clear/vector-search APIs).
- Removes legacy prompt blocks and prunes unused/obsolete code paths; updates tests and documentation to match the new data model.
Reviewed changes
Copilot reviewed 68 out of 68 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tool_memory.py | Updates tool-memory tests to use Entry/entry_kind instead of MemoryItem/memory_type. |
| tests/test_sqlite.py | Updates debug printing to the new response field names (title, entry_kind, text). |
| tests/test_openrouter.py | Updates debug printing to the new response field names (title, entry_kind, text). |
| tests/test_memory_fs_synthesis.py | Updates synthesis wiring/tests to new Resource.summary + Entry.text model and lane="source". |
| tests/test_memory_files.py | Updates memory-fs seeding/export assertions to new repos (resource_repo, entry_repo, resource_entry_repo) and slugs. |
| tests/test_folder_memorize.py | Updates folder memorize tests to create/link Entry and ResourceEntry instead of item/category relations. |
| tests/test_backend_conformance.py | Updates cross-backend conformance tests to validate Entry + ResourceEntry behavior and lane-scoped clears. |
| src/memu/utils/tool.py | Updates tool-memory helpers to operate on Entry (entry_kind == "tool"). |
| src/memu/utils/references.py | Removes legacy fetch_referenced_items helper. |
| src/memu/prompts/memory_type/skill.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/prompts/memory_type/profile.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/prompts/memory_type/knowledge.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/prompts/memory_type/event.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/prompts/memory_type/behavior.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/prompts/category_summary/category.py | Removes PROMPT_LEGACY, keeps block-based prompt format. |
| src/memu/memory_fs/exporter.py | Refactors exporter to read memory docs from Resource(lane="memory") and entries from EntryRepo. |
| src/memu/database/state.py | Updates shared DB state cache fields to entries + relations only (no categories/items). |
| src/memu/database/sqlite/sqlite.py | Rewires SQLite store to ResourceRepo + EntryRepo + ResourceEntryRepo. |
| src/memu/database/sqlite/schema.py | Updates SQLite schema model container to Resource + Entry + ResourceEntry. |
| src/memu/database/sqlite/repositories/resource_repo.py | Expands resource table to include lane/doc fields and adds doc helpers + lane filtering. |
| src/memu/database/sqlite/repositories/resource_entry_repo.py | Adds SQLite membership-edge repository implementation. |
| src/memu/database/sqlite/repositories/memory_category_repo.py | Removes obsolete SQLite category repository. |
| src/memu/database/sqlite/repositories/entry_repo.py | Adds SQLite entry repository implementation (incl. ref_id lookup and lane-filtered vector search). |
| src/memu/database/sqlite/repositories/category_item_repo.py | Removes obsolete SQLite category-item relation repository. |
| src/memu/database/sqlite/repositories/base.py | Replaces in-memory “matches_where” helpers with lane-filter helpers for DB queries. |
| src/memu/database/sqlite/repositories/init.py | Updates SQLite repository exports for new repos. |
| src/memu/database/sqlite/models.py | Replaces category/item models with Entry + ResourceEntry and expands Resource columns. |
| src/memu/database/sqlite/init.py | Builds scoped SQLite SQLAlchemy models and wires them into SQLiteStore. |
| src/memu/database/repositories/resource.py | Updates ResourceRepo protocol with lane filtering and doc helpers (get_or_create_doc, update_resource). |
| src/memu/database/repositories/resource_entry.py | Adds protocol for entry↔resource membership edges. |
| src/memu/database/repositories/memory_item.py | Removes obsolete MemoryItemRepo protocol. |
| src/memu/database/repositories/memory_category.py | Removes obsolete MemoryCategoryRepo protocol. |
| src/memu/database/repositories/entry.py | Adds EntryRepo protocol (lane filtering + ref_id + vector search). |
| src/memu/database/repositories/category_item.py | Removes obsolete CategoryItemRepo protocol. |
| src/memu/database/repositories/init.py | Updates repo exports to Entry/ResourceEntry/Resource. |
| src/memu/database/postgres/schema.py | Updates Postgres schema model container to Resource + Entry + ResourceEntry. |
| src/memu/database/postgres/repositories/resource_repo.py | Updates Postgres ResourceRepo implementation for lanes/docs and lane-filtered vector search. |
| src/memu/database/postgres/repositories/resource_entry_repo.py | Adds Postgres membership-edge repository implementation. |
| src/memu/database/postgres/repositories/memory_item_repo.py | Removes obsolete Postgres MemoryItem repo. |
| src/memu/database/postgres/repositories/memory_category_repo.py | Removes obsolete Postgres MemoryCategory repo. |
| src/memu/database/postgres/repositories/entry_repo.py | Adds Postgres EntryRepo implementation (pgvector + local fallback + salience). |
| src/memu/database/postgres/repositories/category_item_repo.py | Removes obsolete Postgres category-item repo. |
| src/memu/database/postgres/repositories/base.py | Removes unused merge helpers and legacy in-memory where matching. |
| src/memu/database/postgres/repositories/init.py | Updates Postgres repository exports for new repos. |
| src/memu/database/postgres/postgres.py | Rewires Postgres store to ResourceRepo + EntryRepo + ResourceEntryRepo. |
| src/memu/database/postgres/models.py | Replaces legacy category/item SQLModels with PostgresEntryModel + PostgresResourceEntryModel. |
| src/memu/database/postgres/init.py | Updates Postgres DB builder wiring for new models. |
| src/memu/database/models.py | Introduces Lane, expands Resource fields, adds Entry + ResourceEntry, removes legacy models. |
| src/memu/database/interfaces.py | Updates DB protocol to expose entry_repo + resource_entry_repo and caches. |
| src/memu/database/inmemory/repositories/resource_repo.py | Updates in-memory resource repo for lane/docs and adds get_resource + lane filtering. |
| src/memu/database/inmemory/repositories/resource_entry_repo.py | Adds in-memory membership-edge repository implementation. |
| src/memu/database/inmemory/repositories/memory_item_repo.py | Removes obsolete in-memory MemoryItem repo. |
| src/memu/database/inmemory/repositories/memory_category_repo.py | Removes obsolete in-memory MemoryCategory repo. |
| src/memu/database/inmemory/repositories/entry_repo.py | Adds in-memory EntryRepo implementation (incl. salience and ref_id lookup). |
| src/memu/database/inmemory/repositories/category_item_repo.py | Removes obsolete in-memory CategoryItem repo. |
| src/memu/database/inmemory/repositories/init.py | Updates in-memory repository exports for new repos. |
| src/memu/database/inmemory/repo.py | Rewires in-memory store to ResourceRepo + EntryRepo + ResourceEntryRepo. |
| src/memu/database/inmemory/models.py | Updates scoped in-memory models to Entry + ResourceEntry. |
| src/memu/database/inmemory/init.py | Updates in-memory DB builder wiring for new models. |
| src/memu/database/init.py | Updates public exports to Entry/ResourceEntry/Resource repositories and records. |
| src/memu/app/service.py | Removes legacy category-init plumbing and old provider summary helper. |
| src/memu/app/memory_files.py | Ensures memory-fs builder lists only lane="source" resources for raw file descriptions. |
| src/memu/app/crud.py | Updates CRUD pipeline to list/clear/update entries and memory-doc resources; uses ResourceEntryRepo for links. |
| docs/architecture.md | Updates architecture docs to describe the lane-based backbone and new repository contracts. |
| docs/adr/0006-unified-resource-entry-lane-backbone.md | Adds ADR describing the unified Resource+Entry lane model. |
Comments suppressed due to low confidence (1)
src/memu/utils/tool.py:60
- Docstring arg description still says "MemoryItem" after the refactor to Entry, which is misleading for callers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
46
to
48
| if item.entry_kind != "tool": | ||
| msg = "add_tool_call can only be used with tool type memories" | ||
| raise ValueError(msg) |
| @@ -193,10 +196,11 @@ def test_add_tool_call_wrong_type(self): | |||
|
|
|||
Comment on lines
+94
to
+96
| if existing: | ||
| return self._row_to_relation(existing) | ||
|
|
Comment on lines
+71
to
+76
| result: list[ResourceEntry] = [] | ||
| for row in rows: | ||
| rel = self._row_to_relation(row) | ||
| result.append(rel) | ||
| if not any(r.id == rel.id for r in self.relations): | ||
| self.relations.append(rel) |
Wire the index and skill lanes (previously model-only) into the full
memorize/retrieve pipeline on the unified Resource + Entry backbone, and
give each lane its own entry types instead of sharing the memory set.
- models: add "skill" to Lane and RETRIEVAL_LANES (index/memory/skill)
- prompts: add per-lane entry types (index=description, skill=tool/log)
and a LANE_ENTRY_TYPES table
- settings: clean break to per-lane LaneConfig (enabled/grouping/entry_types/
summary), enable index/memory/skill by default
- memorize: loop over enabled lanes; support per_resource (index, 1:1 docs)
and adaptive (memory/skill, grouped + summarized) grouping
- retrieve: single-pass per-lane recall for both rag and llm methods,
returning {lanes: {index, memory, skill}, resources} with backward-compatible
top-level categories/items mirroring the memory lane
- docs: ADR 0006 -> Accepted; architecture.md updated for three lanes
- tests: per-lane persistence + per-lane recall conformance across backends
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Consolidates
index,memory, andskillonto a single Resource + Entry, lane-tagged backbone (ADR 0006) and wires the previously model-onlyindexandskilllanes into the full memorize/retrieve pipeline. Each lane now runs the same code path but with its own entry types and grouping strategy, instead of all sharing the memory entry set.lane-taggedResource/Entry/ResourceEntryreplace the formerMemoryCategory/MemoryItem/CategoryItem.Lane = source/index/memory/skill;RETRIEVAL_LANES = index/memory/skill. Migrated across all three backends (inmemory,sqlite,postgres).index=description,memory=profile/event/knowledge,skill=tool/log(newLANE_ENTRY_TYPEStable + prompt modules).LaneConfig(enabled/grouping/entry_types/ summary settings) underMemorizeConfig.lanes; index/memory/skill enabled by default.per_resourcegrouping (index, 1:1 description docs) andadaptivegrouping (memory/skill, LLM-grouped + summarized docs).ragandllmmethods, returning{lanes: {index, memory, skill}, resources}with backward-compatible top-levelcategories/itemsmirroring the memory lane.architecture.mdupdated.Test plan
ruff check src tests— cleanmypy src/memu— clean (150 files)pytest(126 passed, 1 skipped)inmemory/sqlitetest_rag_recall_lanes_returns_per_lane_shape)