Supermemory

Supermemory is a long-term memory platform that adds persistent, self-growing memory to your AI applications. The Supermemory provider for the AI SDK enables you to build AI applications with memory that works like the human brain:

  • Persistent Memory: Long-term storage that grows with each interaction
  • Semantic Search: Find relevant memories using natural language queries
  • Automatic Memory Management: AI automatically saves and retrieves relevant information
  • Easy Integration: Simple setup with existing AI SDK applications
  • Memory Router: Direct integration with language model providers
  • Free Tier Available: Get started with a free API key

Learn more about Supermemory's capabilities in the Supermemory Documentation.

Setup

The Supermemory provider is available in the @supermemory/tools module. You can install it with:

pnpm
npm
yarn
bun
pnpm add @supermemory/tools

Provider Instance

You can obtain your Supermemory API key for free at https://console.supermemory.ai.

There are two ways to integrate Supermemory with your AI applications:

1. Using Supermemory Tools

Import and use Supermemory tools with your existing AI SDK setup:

import { supermemoryTools } from '@supermemory/tools/ai-sdk';

2. Using the Memory Router

Use the Memory Router for direct integration with language model providers:

import { createAnthropic } from '@ai-sdk/anthropic';
const supermemoryRouter = createAnthropic({
baseUrl: 'https://api.supermemory.ai/v3/https://api.anthropic.com/v1',
apiKey: 'your-provider-api-key',
headers: {
'x-supermemory-api-key': 'supermemory-api-key',
'x-sm-conversation-id': 'conversation-id',
},
});

Examples

Here are examples of using Supermemory with the AI SDK:

generateText with Tools

import { generateText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';
import { supermemoryTools } from '@supermemory/tools/ai-sdk';
const openai = createOpenAI({
apiKey: 'YOUR_OPENAI_KEY',
});
const { text } = await generateText({
model: openai('gpt-4-turbo'),
prompt: 'Remember that my name is Alice',
tools: supermemoryTools('YOUR_SUPERMEMORY_KEY'),
});
console.log(text);

streamText with Automatic Memory

import { streamText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';
import { supermemoryTools } from '@supermemory/tools/ai-sdk';
const openai = createOpenAI({
apiKey: 'YOUR_OPENAI_KEY',
});
const result = streamText({
model: openai('gpt-4'),
prompt: 'What are my dietary preferences?',
tools: supermemoryTools('YOUR_SUPERMEMORY_KEY'),
});
// The AI will automatically call searchMemories tool
// Example tool call:
// searchMemories({ informationToGet: "dietary preferences and restrictions" })
// OR
// addMemory({ memory: "User is allergic to peanuts" })
for await (const chunk of result.textStream) {
console.log(chunk);
}

Using Memory Router

import { streamText } from 'ai';
import { createAnthropic } from '@ai-sdk/anthropic';
const supermemoryRouter = createAnthropic({
baseUrl: 'https://api.supermemory.ai/v3/https://api.anthropic.com/v1',
apiKey: 'your-provider-api-key',
headers: {
'x-supermemory-api-key': 'supermemory-api-key',
'x-sm-conversation-id': 'conversation-id',
},
});
const result = streamText({
model: supermemoryRouter('claude-3-sonnet'),
messages: [
{ role: 'user', content: 'Hello! Remember that I love TypeScript.' },
],
});

For more information about these features and advanced configuration options, visit the Supermemory Documentation.

Additional Resources