Skip to main content

About Vercel AI SDK with Memory

Vercel AI SDK is an open-source toolkit from the team behind Vercel and Next.js. It provides a unified developer experience for building AI-powered applications with memory capabilities.

Key Features for Memory Integration

  • Easy integration with multiple model providers (OpenAI, Anthropic, etc.)
  • Support for streaming responses for real-time chat UIs
  • Type-safe APIs with excellent TypeScript support
  • Built-in support for persistent user preferences and conversation history
  • Ready-to-use React/Next.js hooks for managing conversation state
By using the AI SDK with Alchemyst memory, you can avoid handling low-level APIs directly and focus on creating seamless AI-driven experiences with persistent context.

How Memory Works

The AI SDK memory integration allows you to:
  • Store user preferences: Keep track of user-specific settings and preferences
  • Maintain conversation context: Remember important details across sessions
  • Personalize experiences: Build applications that adapt to individual users
  • Enable long-term memory: Create AI assistants that recall past interactions
The Alchemyst memory tools work seamlessly with the AI SDK’s modular architecture:
  • Core API: A unified way to call LLMs and handle outputs
  • Provider Adapters: Packages like @ai-sdk/openai let you plug in specific providers
  • Memory Tools: Add, retrieve, and manage user memories
  • UI Utilities: Hooks such as useChat make it easy to build interactive experiences

Memory Management Examples

Basic Memory Setup

This example shows how to configure memory-only tools with proper groupName structure:
memorySetup.ts
Best Practice: Use hierarchical groupName structure like ["domain", "category", "specific"] for better organization. Maximum 3 layers for 90% of queries.

Storing User Preferences

This example demonstrates storing user preferences in memory:
storePreferences.ts

Retrieving User Preferences

Later, retrieve and use the stored memory:
retrievePreferences.ts

Personalized Chat Assistant

A complete example using memory for personalization:
personalizedAssistant.ts

Memory with Streaming

Handle streaming responses while managing memory:
memoryStreaming.ts

Bulk Memory Operations

For storing multiple user preferences efficiently, use bulk operations:
bulkMemoryOperations.ts
Performance Tip: For 1000+ operations, batch in groups of 1000 for optimal performance. Sequential operations for 1000 docs take ~30s, while batched operations take ~3s (10x faster).

Error Handling for Bulk Operations

robustBulkMemory.ts

When to Use Memory

Use Vercel AI SDK with Alchemyst memory when you need to:
  • Build personalized experiences: Remember user preferences, settings, and habits
  • Create multi-session applications: Maintain context across different sessions
  • Implement user profiles: Store and retrieve user-specific information
  • Enable conversation continuity: Remember previous interactions and context
  • Track user journey: Keep a history of user interactions and decisions
For more details, check out the official Vercel AI SDK documentation

Tool Configuration

If you don’t have an Alchemyst API Key, you can get one in the Alchemyst Settings page