-
Notifications
You must be signed in to change notification settings - Fork 931
Composite Storage - use different storage adapters for diff primitives #5864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Introduces a composite storage adapter that enables using different storage backends for distinct data types, allowing for optimized storage strategies per data category.
- Added
packages/core/src/storage/composite.ts
implementingMastraCompositeStorage
that routes operations to specialized storage adapters based on data type (traces, conversations, workflows, scores) - Modified
packages/core/src/storage/base.ts
to remove deprecated static table names and improve method signatures for better integration with composite storage - The implementation allows mixing storage backends (e.g., using Redis for traces while keeping conversations in PostgreSQL) for performance optimization
3 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile
throw new Error( | ||
`Resource working memory is not supported by this storage adapter (${this.constructor.name}). ` + | ||
`Supported storage adapters: LibSQL (@mastra/libsql), PostgreSQL (@mastra/pg), Upstash (@mastra/upstash). ` + | ||
`To use per-resource working memory, switch to one of these supported storage adapters.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Unreachable code: Error thrown after return statement
throw new Error( | |
`Resource working memory is not supported by this storage adapter (${this.constructor.name}). ` + | |
`Supported storage adapters: LibSQL (@mastra/libsql), PostgreSQL (@mastra/pg), Upstash (@mastra/upstash). ` + | |
`To use per-resource working memory, switch to one of these supported storage adapters.`, | |
); | |
return this.#stores.conversations.updateResource(_); |
async getTraces(args: StorageGetTracesArg): Promise<any[]> { | ||
return this.#stores.traces.getTraces(args); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: getTraces return type should be Trace[] instead of any[]
async getTraces(args: StorageGetTracesArg): Promise<any[]> { | |
return this.#stores.traces.getTraces(args); | |
} | |
async getTraces(args: StorageGetTracesArg): Promise<Trace[]> { | |
return this.#stores.traces.getTraces(args); | |
} |
…ai/mastra into mastra-composite-storage
Couple things happening in here to set the stage for future changes.
This takes existing storage adapters and allows the user to create a composite of them by delegating different primitives to different storage adapters.
Introduce interfaces for each domain
This would allow Storage adapters to implement the relevant piece instead of all if irrelevant.