Skip to content

Conversation

@Nsuccess
Copy link

This PR implements MySQL database integration for MemU, enabling memory data synchronization with MySQL for import, export, and backup use cases.

Changes
New Files
MySQL Database Module (src/memu/database/mysql/):

init.py - Module entry point with build_mysql_database() factory
mysql.py - MySQLStore class implementing the Database interface
session.py - SessionManager for MySQL connection handling
schema.py - SQLAlchemy model generation and caching
models.py - SQLModel definitions for MySQL tables
migration.py - DDL management (create/validate modes)
Repository Layer (src/memu/database/mysql/repositories/):

base.py - MySQLRepoBase with JSON embedding serialization
resource_repo.py - Resource CRUD operations
memory_category_repo.py - Category CRUD operations
memory_item_repo.py - Memory item CRUD with vector search
category_item_repo.py - Category-item relationship management
Documentation:

docs/mysql-integration.md - Setup guide, configuration, usage examples
Tests:

tests/test_mysql.py - 17 unit tests covering all components
Modified Files
src/memu/app/settings.py - Added mysql to MetadataStoreConfig.provider literal
src/memu/database/factory.py - Added MySQL provider branch in build_database()
Implementation Details
Architecture
Follows the existing Postgres pattern for consistency
Uses SQLModel/SQLAlchemy for ORM
Embeddings stored as JSON TEXT (MySQL lacks native vector type)
Brute-force cosine similarity for vector search
Configuration
from memu.app.settings import DatabaseConfig, MetadataStoreConfig

config = DatabaseConfig(
metadata_store=MetadataStoreConfig(
provider="mysql",
dsn="mysql+pymysql://user:password@localhost:3306/memu_db",
)
)
Database Schema
Creates 4 tables: resources, memory_items, memory_categories, category_items

Testing
All 17 tests pass:

pytest tests/test_mysql.py -v
==================================== 17 passed ====================================
Checklist
Complete MySQL integration that can be run in practice
Vector storage support (via JSON serialization + local cosine search)
Documentation with setup and usage instructions
Unit tests for all components
No breaking changes to existing functionality
Closes #163

@ankaisen
Copy link
Collaborator

@Nsuccess Thanks for your PR! Could you please resolve the merge conflicts?

@Nsuccess
Copy link
Author

@ankaisen Done! Merge conflicts resolved — Included both MySQL and SQLite providers.

@Nsuccess Nsuccess force-pushed the feature/mysql-database-integration branch from b0b80cc to a8ce007 Compare January 13, 2026 14:50
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.

[2026NewYearChallenge]Database Integration——MySQL

2 participants