feat: support custom memory types via MemoryType::Custom(String)#79
Open
allengaoo wants to merge 1 commit intomatrixorigin:mainfrom
Open
feat: support custom memory types via MemoryType::Custom(String)#79allengaoo wants to merge 1 commit intomatrixorigin:mainfrom
allengaoo wants to merge 1 commit intomatrixorigin:mainfrom
Conversation
The built-in MemoryType enum (6 variants) was too restrictive for
downstream applications that need domain-specific memory categories
(e.g. `brand_theme`, `layout_catalog`, `writing_style`).
Previously, any unrecognized memory_type string sent to the REST API
was rejected with HTTP 422, forcing every integration to shoehorn
their semantics into the 6 built-in types.
Changes:
- Add `Custom(String)` variant to `MemoryType` enum
- Make `FromStr` infallible — unknown strings become `Custom(name)`
- Hand-implement `Serialize`/`Deserialize` to preserve flat string
representation in JSON (e.g. `"brand_theme"`, not `{"Custom":"brand_theme"}`)
- Widen `memory_type` column from `VARCHAR(20)` to `VARCHAR(64)` to
accommodate longer custom type names
- Add `is_builtin()` helper method
- Update all call sites to use infallible `.parse::<MemoryType>().unwrap()`
- Add tests for custom type roundtrip and serde
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
Custom(String)variant toMemoryTypeenum, allowing downstream applications to define domain-specific memory categories (e.g.brand_theme,layout_catalog,writing_style) without modifying Memoria source codeFromStrinfallible — unrecognized strings are accepted asCustom(name)instead of returningInvalidMemoryTypeerror (HTTP 422)memory_typeDB column fromVARCHAR(20)toVARCHAR(64)to accommodate longer custom type namesMotivation
When integrating Memoria into a PPT generation agent, we needed domain-specific memory types (
brand_theme,layout_catalog,writing_style,component_pattern) to store structured knowledge extracted from PowerPoint templates and style profiles. The current hardcoded 6-variant enum rejected these types with HTTP 422, forcing all custom semantics to be shoehorned into generic types likeprofileorsemantic, which breaks type-filtered retrieval.Changes
memoria-core/src/types.rsCustom(String)variant, hand-implement Serialize/Deserialize for flat JSON representation, make FromStr return Infallible, add is_builtin() helpermemoria-storage/src/store.rsmemoria-api/src/models.rsmemoria-api/src/routes/governance.rsmemoria-mcp/src/tools.rsBackward Compatibility
InvalidMemoryTypeerror variant is retained inMemoriaErrorfor backward compat but is no longer produced byFromStr"brand_theme", not{"Custom":"brand_theme"})Test plan
cargo test -p memoria-core— all 12 tests pass including new test_custom_type_roundtrip and test_custom_type_serde_roundtripcargo build --release— zero warnings