refactor: delegate memory models and table creation to memu-py#19
refactor: delegate memory models and table creation to memu-py#19
Conversation
- Add BaseModel with KSUID primary keys and automatic timestamps - Implement Memory model with pgvector support for embeddings - Add MemoryCreate, MemoryRead, MemoryUpdate schemas - Migrate from SQLAlchemy DeclarativeBase to SQLModel - Update database.py to use SQLModel - Add comprehensive unit tests for BaseModel and Memory - Add svix-ksuid dependency for KSUID generation All changes pass make check (ruff, mypy, deptry, pre-commit)
There was a problem hiding this comment.
Pull request overview
Implements new SQLModel-based data modeling foundations (a shared BaseModel with KSUID primary keys + timestamps) and introduces a Memory model with pgvector embeddings, along with corresponding create/read/update schemas and unit tests.
Changes:
- Replace the previous SQLAlchemy
DeclarativeBaseapproach with a SQLModelBaseModel(KSUID IDs + timestamps). - Add
Memorytable/model andMemoryCreate/MemoryRead/MemoryUpdateschemas with pgvector + JSONB fields. - Update database module exports and add unit tests; introduce
svix-ksuiddependency.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
app/models/base.py |
Introduces SQLModel-based BaseModel with KSUID primary key and timestamp fields. |
app/models/memory.py |
Adds Memory table + schemas, including pgvector embedding and JSONB links. |
app/models/__init__.py |
Re-exports models/schemas for simpler imports. |
app/database.py |
Switches exports toward SQLModel to align with the migration. |
tests/test_base_model.py |
Adds unit tests for KSUID IDs and timestamp defaults. |
tests/test_memory.py |
Adds unit tests for Memory model and schemas. |
pyproject.toml |
Adds svix-ksuid dependency. |
uv.lock |
Locks svix-ksuid and transitive dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Critical fixes addressing Copilot feedback: - Add Base alias in base.py for Alembic backward compatibility - Fix timezone-aware datetimes (use datetime.now(timezone.utc) instead of utcnow()) - Add onupdate lambda for automatic updated_at refresh - Fix links type annotation from bare list to list[Any] - Export both Base and SQLModel from database.py - Correct ksuid import (lowercase ksuid() function) Test fixes: - Update test files to use timezone.utc instead of UTC - Fix KSUID length assertion (40 chars, not 27) - Ensure all datetime comparisons are timezone-aware All tests now pass (20/20) and make check succeeds.
…existence Assert against SQLModel Field metadata (model_fields[].index) rather than hasattr() checks that would pass even if indexes were removed.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Set nullable=False on content Column to match required str type - Import app.models in alembic/env.py so metadata is populated - Fix bare list to list[Any] in MemoryUpdate schema
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove redundant index=True on primary key (PG indexes PKs by default) - Add sa_type=DateTime(timezone=True) to happened_at field - Update test to reflect primary key no longer has explicit index flag
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use Python logging framework instead of traceback.print_exc() so error output respects log levels and integrates with log aggregation tools in production.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ents - Add detailed NOTE comment explaining target_metadata = None in alembic/env.py and how to re-enable autogenerate for server tables. - Assert full OPENAI_API_KEY error message in test_env_validation.py. - Narrow test_health.py exception catch to (RuntimeError, ImportError). - Update psycopg deptry comment to reflect actual usage. - Remove stale pydantic_core from DEP003 ignore list.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Settings docstring now shows full resolution order: init kwargs > environment variable > .env file > default. - Add 'config' to hatch wheel packages so the built wheel includes the config package at runtime.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaced hand-rolled DATABASE_HOST/USER/PASSWORD/NAME fallback with Settings().DATABASE_URL which reads the same POSTGRES_* variables as the application and already normalises the DSN prefix.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…parser interpolation error
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 18 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Remove server-side memory model definitions and Alembic migrations in favor of
memu-py's built-in database management (
ddl_mode: "create"). The server nowacts purely as a wrapper — it configures and initializes
MemoryServicefrommemu-py, which handles all ORM models, table creation, and schema management
internally.
Changes
Added
config/settings.py— centralizedSettings(pydantic-settings) declaring allenvironment variables with typed defaults (
DATABASE_*,EMBEDDING_*,TEMPORAL_*,STORAGE_PATH, etc.)config/memu.py—build_memu_config()/build_memu_llm_profiles()toconstruct memu-py configuration from
Settingsapp/services/memu.py—create_memory_service()factorytests/test_memu_config.py— tests for the new config buildersModified
alembic/env.py— removedapp.modelsimports; settarget_metadata = Noneapp/main.py— added module docstring; extracted exception messages tovariables (EM101/EM102)
tests/test_env_validation.py— movedimport osto top level; addedcheck=Falsetosubprocess.runtests/test_health.py— usedHTTPStatus.OKinstead of magic200;narrowed exception catch from
Exceptionto(ImportError, RuntimeError)pyproject.toml— changedmemu-pytomemu-py[postgres]; removedsqlmodel,sqlalchemy,pgvector,ksuid,pendulum,openai(providedtransitively by memu-py); updated deptry ignore rules
Motivation
The previous implementation duplicated model definitions that memu-py already
provides, causing import errors (
app.models.basedid not exist) andarchitectural misalignment. Per review feedback, the server should rely on
memu-py for all memory-related schema management.