feat(memory): add SQLite and MySQL short-term memory backends#48
Open
wucm667 wants to merge 1 commit intovolcengine:mainfrom
Open
feat(memory): add SQLite and MySQL short-term memory backends#48wucm667 wants to merge 1 commit intovolcengine:mainfrom
wucm667 wants to merge 1 commit intovolcengine:mainfrom
Conversation
- 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
Contributor
There was a problem hiding this comment.
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
sqliteandmysqlshort-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
wantDBurlis populated but never asserted, so this test doesn't verify DSN generation/credential encoding whenDBUrlis empty. Add an assertion against the generated DSN (e.g.,tt.config.DBUrlafter callingNewMysqlSTMBackend, or by capturing the argument passed tomysql.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 updatedtt.config.DBUrl(or capturing the dialector argument passed intodatabase.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(viagorm.io/driver/sqlite) introduces a CGO dependency, which can break builds in environments whereCGO_ENABLED=0or 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.
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
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) whenDBUrlis emptymemory/short_term_memory_backends/sqlite_backend_test.go— unit tests for the SQLite backendmemory/short_term_memory_backends/mysql_backend.go— MySQL backend; accepts either a pre-builtDBUrlor individual fields (host/port/user/password/database); URL-encodes credentials automatically to handle special charactersmemory/short_term_memory_backends/mysql_backend_test.go— unit tests for the MySQL backendModified files
common/consts.go— addDATABASE_SQLITE_DBURLandDATABASE_MYSQL_*env key constantsconfigs/database.go— addSqliteandMysqlfields toDatabaseConfig; map env vars inMapEnvToConfigconfigs/configs.go— initializeSqliteandMysqlconfig structs inSetupVeADKConfigmemory/short_term_memory.go— extendNewShortTermMemoryServicefactory withBackendShortTermSQLiteandBackendShortTermMySQLcasesgo.mod/go.sum— addgorm.io/driver/sqlite v1.6.0andgorm.io/driver/mysql v1.6.0Usage
SQLite via environment variables:
MySQL via environment variables:
Or via
config.yaml:Testing
Notes
BackendShortTermSQLiteandBackendShortTermMySQLbackends already available in the Python SDKpostgresql_backend.go)github.com/bytedance/mockey; no real database required