Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

abhiaiyer91
Copy link
Contributor

@abhiaiyer91 abhiaiyer91 commented Jul 11, 2025

Couple things happening in here to set the stage for future changes.

  1. MastraCompositeStorage

This takes existing storage adapters and allows the user to create a composite of them by delegating different primitives to different storage adapters.

new MastraCompositeStorage({ stores: { traces: new LibSQLStore(), conversations: new PostgresStore() } })
  1. Domain specific storage interfaces

Introduce interfaces for each domain

{
    traces: MastraTracesStorage;
    conversations: MastraConversationsStorage;
    workflows: MastraWorkflowsStorage;
    scores: MastraScoresStorage;
  };

This would allow Storage adapters to implement the relevant piece instead of all if irrelevant.

Copy link

codesandbox bot commented Jul 11, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Jul 11, 2025

⚠️ No Changeset found

Latest commit: 86c313f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
assistant-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 7:02am
mastra-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 7:02am
openapi-spec-writer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 7:02am

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 implementing MastraCompositeStorage 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

Comment on lines 169 to 173
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.`,
);
Copy link
Contributor

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

Suggested change
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(_);

Comment on lines +205 to +207
async getTraces(args: StorageGetTracesArg): Promise<any[]> {
return this.#stores.traces.getTraces(args);
}
Copy link
Contributor

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[]

Suggested change
async getTraces(args: StorageGetTracesArg): Promise<any[]> {
return this.#stores.traces.getTraces(args);
}
async getTraces(args: StorageGetTracesArg): Promise<Trace[]> {
return this.#stores.traces.getTraces(args);
}

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.

1 participant