(Update) Vercel AI SDK Memory Saving Algo (#2082)

This commit is contained in:
Saket Aryan
2024-12-15 11:14:16 +05:30
committed by GitHub
parent 400b1f4eac
commit 763f804277
7 changed files with 78 additions and 16 deletions

View File

@@ -81,10 +81,15 @@ you must either set `MEM0_API_KEY` as an environment variable or pass it directl
Example:
```typescript
await addMemories(messages, { user_id: "borat", mem0ApiKey: "m0-xxx" });
await retrieveMemories(prompt, { user_id: "borat", mem0ApiKey: "m0-xxx" });
await addMemories(messages, { user_id: "borat", mem0ApiKey: "m0-xxx", org_id: "org_xx", project_id: "proj_xx" });
await retrieveMemories(prompt, { user_id: "borat", mem0ApiKey: "m0-xxx", org_id: "org_xx", project_id: "proj_xx" });
await getMemories(prompt, { user_id: "borat", mem0ApiKey: "m0-xxx", org_id: "org_xx", project_id: "proj_xx" });
```
### Note:
`retrieveMemories` enriches the prompt with relevant memories from your profile, while `getMemories` returns the memories in array format which can be used for further processing.
## Usage Examples
### 1. Basic Text Generation with Memory Context
@@ -199,6 +204,7 @@ for await (const textPart of textStream) {
- `createMem0()`: Initializes a new mem0 provider instance with optional configuration
- `retrieveMemories()`: Enriches prompts with relevant memories
- `addMemories()`: Add memories to your profile
- `getMemories()`: Get memories from your profile in array format
## Configuration Options
@@ -225,4 +231,4 @@ We also have support for `agent_id`, `app_id`, and `run_id`. Refer [Docs](https:
- Requires proper API key configuration for underlying providers (e.g., OpenAI)
- Memory features depend on proper user identification via `user_id`
- Supports both streaming and non-streaming responses
- Compatible with all Vercel AI SDK features and patterns
- Compatible with all Vercel AI SDK features and patterns