Skip to content

feat(memory): add SQLite and MySQL short-term memory backends#48

Open
wucm667 wants to merge 1 commit intovolcengine:mainfrom
wucm667:feat/short-term-memory-sqlite-mysql
Open

feat(memory): add SQLite and MySQL short-term memory backends#48
wucm667 wants to merge 1 commit intovolcengine:mainfrom
wucm667:feat/short-term-memory-sqlite-mysql

Conversation

@wucm667
Copy link
Contributor

@wucm667 wucm667 commented Mar 2, 2026

Summary

Add SQLite and MySQL backends for short-term memory in VeADK-Go, closing the feature gap with the Python SDK.

Changes

New files

  • memory/short_term_memory_backends/sqlite_backend.go — SQLite backend; falls back to an in-memory database (file::memory:?cache=shared) when DBUrl is empty
  • memory/short_term_memory_backends/sqlite_backend_test.go — unit tests for the SQLite backend
  • memory/short_term_memory_backends/mysql_backend.go — MySQL backend; accepts either a pre-built DBUrl or individual fields (host/port/user/password/database); URL-encodes credentials automatically to handle special characters
  • memory/short_term_memory_backends/mysql_backend_test.go — unit tests for the MySQL backend

Modified files

  • common/consts.go — add DATABASE_SQLITE_DBURL and DATABASE_MYSQL_* env key constants
  • configs/database.go — add Sqlite and Mysql fields to DatabaseConfig; map env vars in MapEnvToConfig
  • configs/configs.go — initialize Sqlite and Mysql config structs in SetupVeADKConfig
  • memory/short_term_memory.go — extend NewShortTermMemoryService factory with BackendShortTermSQLite and BackendShortTermMySQL cases
  • go.mod / go.sum — add gorm.io/driver/sqlite v1.6.0 and gorm.io/driver/mysql v1.6.0

Usage

SQLite via environment variables:

DATABASE_SQLITE_DBURL=/path/to/veadk.db
svc, err := memory.NewShortTermMemoryService(memory.BackendShortTermSQLite, nil)

MySQL via environment variables:

DATABASE_MYSQL_HOST=127.0.0.1
DATABASE_MYSQL_PORT=3306
DATABASE_MYSQL_USER=root
DATABASE_MYSQL_PASSWORD=secret
DATABASE_MYSQL_DATABASE=veadk
svc, err := memory.NewShortTermMemoryService(memory.BackendShortTermMySQL, nil)

Or via config.yaml:

database:
  sqlite:
    db_url: /path/to/veadk.db
  mysql:
    host: 127.0.0.1
    port: "3306"
    user: root
    password: secret
    database: veadk

Testing

go test -v -race ./memory/short_term_memory_backends/...
go test -v -race ./memory/...

Notes

  • Mirrors the BackendShortTermSQLite and BackendShortTermMySQL backends already available in the Python SDK
  • Follows the same patterns as the existing PostgreSQL backend (postgresql_backend.go)
  • Tests mock the GORM layer with github.com/bytedance/mockey; no real database required

- Add SQLite and MySQL env key constants in common/consts.go
- Extend DatabaseConfig with Sqlite and Mysql fields in configs/database.go
- Initialize Sqlite and Mysql config in SetupVeADKConfig (configs/configs.go)
- Implement SqliteBackendConfig and NewSqliteSTMBackend with default in-memory fallback
- Implement MysqlBackendConfig and NewMysqlSTMBackend with URL-encoded credentials
- Extend NewShortTermMemoryService factory with BackendShortTermSQLite and BackendShortTermMySQL cases
- Add unit tests for both new backends using mockey mocks
- Add gorm.io/driver/sqlite v1.6.0 and gorm.io/driver/mysql v1.6.0 to go.mod
Copilot AI review requested due to automatic review settings March 2, 2026 03:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds SQLite and MySQL implementations for the short-term memory session store to bring VeADK-Go closer to feature parity with the Python SDK, including config/env wiring and backend selection in the short-term memory factory.

Changes:

  • Introduces new sqlite and mysql short-term memory backends using GORM drivers.
  • Extends configuration/env mapping to support SQLite/MySQL connection settings.
  • Updates the short-term memory backend factory to route to the new backends; adds module dependencies for the new DB drivers.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
memory/short_term_memory_backends/sqlite_backend.go New SQLite STM backend with in-memory fallback when DBUrl is empty.
memory/short_term_memory_backends/sqlite_backend_test.go Unit tests for the SQLite backend wiring/mocking.
memory/short_term_memory_backends/mysql_backend.go New MySQL STM backend with DSN construction and credential escaping.
memory/short_term_memory_backends/mysql_backend_test.go Unit tests for the MySQL backend wiring/mocking.
memory/short_term_memory.go Adds sqlite/mysql backend options to the STM service factory.
configs/database.go Adds SQLite/MySQL fields to DatabaseConfig and maps env vars into them.
configs/configs.go Initializes SQLite/MySQL config structs in global setup.
common/consts.go Adds env key constants for SQLite and MySQL settings.
go.mod / go.sum Adds GORM SQLite/MySQL drivers and their transitive deps.
Comments suppressed due to low confidence (3)

memory/short_term_memory_backends/mysql_backend_test.go:32

  • wantDBurl is populated but never asserted, so this test doesn't verify DSN generation/credential encoding when DBUrl is empty. Add an assertion against the generated DSN (e.g., tt.config.DBUrl after calling NewMysqlSTMBackend, or by capturing the argument passed to mysql.Open/database.NewSessionService).
	tests := []struct {
		name      string
		config    *MysqlBackendConfig
		wantDBurl string
		wantErr   bool
	}{

memory/short_term_memory_backends/sqlite_backend_test.go:47

  • The "empty db url uses in-memory" case doesn't assert that the fallback DSN (file::memory:?cache=shared) was actually applied. Consider asserting the updated tt.config.DBUrl (or capturing the dialector argument passed into database.NewSessionService) to ensure the intended behavior is covered.
		{
			name: "empty db url uses in-memory",
			config: &SqliteBackendConfig{
				CommonDatabaseConfig: &configs.CommonDatabaseConfig{
					DBUrl: "",
				},
			},
		},

go.mod:82

  • Adding github.com/mattn/go-sqlite3 (via gorm.io/driver/sqlite) introduces a CGO dependency, which can break builds in environments where CGO_ENABLED=0 or when cross-compiling. If CGO-free builds are a goal for this repo, consider a pure-Go SQLite driver alternative or document the CGO requirement for the SQLite backend.
	github.com/jtolds/gls v4.20.0+incompatible // indirect
	github.com/klauspost/cpuid/v2 v2.2.9 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	github.com/mattn/go-sqlite3 v1.14.22 // indirect
	github.com/mitchellh/mapstructure v1.5.0 // indirect

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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