new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Providers · all subjects

mem0/capabilities

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Mem0 memory retrieval functions

The Mem0 provider offers three memory management functions: `retrieveMemories()` retrieves memory context formatted as a system prompt, `getMemories()` returns raw memories as an array of objects, and `addMemories()` adds user memories to enhance contextual responses. For standalone use of these functions, either set `MEM0_API_KEY` as an environment variable or pass it directly in the function call.

Adding memories with addMemories

```ts await addMemories(messages, { user_id: 'borat', mem0ApiKey: 'm0-xxx', }); ``` This example shows how to add memories for a specific user, requiring a LanguageModelV4Prompt and user identification.

Retrieving memories with retrieveMemories

```ts await retrieveMemories(prompt, { user_id: 'borat', mem0ApiKey: 'm0-xxx', }); ``` This example shows how to retrieve memories for a specific user, with the response formatted as a string with system prompt context.

Getting raw memories with getMemories

```ts await getMemories(prompt, { user_id: 'borat', mem0ApiKey: 'm0-xxx', }); ``` This example shows how to get raw memories in the form of an array of objects for a specific user.

Generate text with memory context

```ts import { generateText } from 'ai'; import { createMem0 } from '@mem0/vercel-ai-provider'; const mem0 = createMem0(); const { text } = await generateText({ model: mem0('gpt-4.1', { user_id: 'borat' }), prompt: 'Suggest me a good car to buy!', }); ``` This example demonstrates using the generateText function with a Mem0-wrapped model that includes memory context for the specified user.

Stream text with memory context

```ts import { streamText } from 'ai'; import { createMem0 } from '@mem0/vercel-ai-provider'; const mem0 = createMem0(); const { textStream } = streamText({ model: mem0('gpt-4.1', { user_id: 'borat', }), prompt: 'Suggest me a good car to buy! Why is it better than the other cars for me? Give options for every price range.', }); for await (const textPart of textStream) { process.stdout.write(textPart); } ``` This example demonstrates streaming text responses with memory context using the streamText function.

Generate responses with tools call

```ts import { generateText } from 'ai'; import { createMem0 } from '@mem0/vercel-ai-provider'; import { z } from 'zod'; const mem0 = createMem0({ provider: 'anthropic', apiKey: 'ant••••••ey', mem0Config: { user_id: 'borat', }, }); const prompt = 'What the temperature in the city that I live in?'; const result = await generateText({ model: mem0('claude-3-5-sonnet-20240620'), tools: { weather: tool({ description: 'Get the weather in a location', inputSchema: z.object({ location: z.string().describe('The location to get the weather for'), }), execute: async ({ location }) => ({ location, temperature: 72 + Math.floor(Math.random() * 21) - 10, }), }), }, prompt: prompt, }); console.log(result); ``` This example demonstrates using generateText with tool calls and memory context, using Anthropic as the LLM provider.

Get sources from memory

```ts const { text, sources } = await generateText({ model: mem0('gpt-4.1'), prompt: 'Suggest me a good car to buy!', }); console.log(sources); ``` The generateText and streamText functions can return a `sources` property that provides information about the memory sources used in the response.

Mem0 supported LLM providers

The Mem0 provider supports the following LLM providers with their configuration values: OpenAI (openai), Anthropic (anthropic), Google (google), Groq (groq), and Cohere (cohere). OpenAI is the default provider.

Tools call support in Mem0

The Mem0 AI SDK now supports Tools Call functionality, enabling the use of tools with memory-enhanced language models.

Structured message format with memory

```ts import { generateText } from 'ai'; import { createMem0 } from '@mem0/vercel-ai-provider'; const mem0 = createMem0(); const { text } = await generateText({ model: mem0('gpt-4.1', { user_id: 'borat' }), messages: [ { role: 'user', content: [ { type: 'text', text: 'Suggest me a good car to buy.' }, { type: 'text', text: 'Why is it better than the other cars for me?' }, ], }, ], }); ``` This example demonstrates using generateText with a structured message format containing multiple text content items, with memory context for the specified user.

Give your agent this brain