Coding with AI

The new MongoDB integration for the Vercel AI Software Development Kit brings persistent memory to AI applications.

MongoDB adds persistent Atlas memory to Vercel AI Software Development Kit apps, with five memory types, vector search, and retention modes.

Key Takeaways

  • MongoDB has released an open-source integration, `@mongodb-developer/vercel-ai-memory`, that adds persistent memory to AI apps and agents built with the Vercel AI SDK, using MongoDB Atlas as the storage layer.
  • The package removes the need for developers to build custom memory infrastructure, such as database schemas, data cleanup jobs, and vector search, by storing app memories as Atlas documents that persist across sessions, users, and restarts.
  • It supports five memory types—session, semantic, procedural, episodic, and scratchpad—each with different lifespans and retrieval behaviors, while semantic and procedural memories are versioned to preserve changes over time.
  • Memory retention is configurable through four modes—`none`, `ttl`, `ttl+importance`, and `dynamic`—and includes model-driven forgetting via `memory_forget` so users can explicitly ask the app to remove specific memories.
  • The production release adds features such as reliable transcript saving through AI SDK hooks, tenant isolation via fields like `tenant_id`, customizable collection and index naming, and compatibility with any AI SDK model under an Apache 2.0 license.

MongoDB has released an open source integration that gives applications and agents built with the Vercel AI SDK a persistent memory store in MongoDB Atlas. The package, published on npm as `@mongodb-developer/vercel-ai-memory` under the Apache 2.0 license, is generally available now and works with AI SDK v6 and v7 on any MongoDB Atlas cluster. It was announced by Ajay Tandon, Nasir Qureshi, and Pavel Duchovny.

Why the Vercel AI SDK needs a memory layer

The Vercel AI SDK is a TypeScript toolkit for building AI applications. It handles calling models, streaming responses, using tools, and running agents that work through multi-step tasks. What it does not include is a database for persisting memories between runs. Without one, an AI application starts every conversation with no knowledge of the last: it does not know who the user is, what they asked yesterday, or what it learned along the way.

Developers who want memory today have to build their own tooling. That typically means designing a database schema, writing jobs to clear out old data, and setting up vector search so the application can find relevant past information by semantic meaning rather than exact keywords. The new package is aimed at removing that work: once installed, it connects a Vercel AI SDK application to MongoDB Atlas and stores the application's memories as documents, so they persist across sessions, users, and restarts.

Five kinds of memory, each with its own lifespan

The integration automatically categorizes memories into five types, each retained for a different length of time and retrieved differently:

  • Session: the conversation an application or agent has in each session, so it can follow what the user just said.
  • Semantic: facts about people, entities, and preferences, so users do not have to repeat themselves.
  • Procedural: workflows and instructions, so the application carries out tasks the way they were defined.
  • Episodic: key events and outcomes, so the application can recall what happened before. Kept for one year of inactivity by default.
  • Scratchpad: temporary notes for work in progress. These expire after an hour and can be promoted to episodic memory if they turn out to matter.

Semantic and procedural memories are versioned, so history is preserved when a fact changes. The semantic, procedural, and episodic tiers use MongoDB Vector Search, which finds stored memories by meaning rather than by exact keywords. The integration creates the vector indexes automatically and detects embedding dimensions at startup, and developers can use any AI SDK embedding model, including Voyage AI, OpenAI, Cohere, or Google.

Retention is a balancing act

Each memory category has its own retention policy, so short-lived notes expire quickly while long-term facts stay longer. The package ships with defaults for every category, and developers can customize them. The reasoning is practical: keeping memories indefinitely can degrade retrieval performance and raise costs, while deleting them too early makes applications forget important context.

To help developers find the right balance, the integration offers four retention modes: `none` (never expire), `ttl` (expire after a set time), `ttl+importance` (expire after a set time unless the memory is marked important), and `dynamic`, where developers define their own forgetting period. There is also model-driven forgetting: with `memory_forget`, the model can delete a specific memory when a user says "forget that," with removal usually happening within about 60 seconds.

Because memories live in MongoDB Atlas, an application's operational data, its memory, and the vector search that retrieves it all run on one platform. Developers can secure, monitor, and scale a single database instead of bolting on a separate vector store or memory service alongside it.

What changes in production

The production release adds controls that matter once an application leaves the prototype stage:

  • Reliable session history: by default the model decides when to save and read conversation turns, so it can occasionally skip one. For production, AI SDK hooks let the application's own code load and save the transcript at every turn, so every user, assistant, and tool message is saved exactly once.
  • Separate data per customer: developers can add a filter field such as `tenant_id` to vector indexes to limit each search to a single customer's memories.
  • Application names and layout: collections and indexes can be renamed to match an existing application schema, and indexing can be turned off for unused categories.
  • Open source: the Apache 2.0 license applies, and the package works with any AI SDK model.

Getting started

Adding memory to an existing Vercel AI SDK project takes three steps, according to the documentation. First, install the package and its peer dependencies with `npm install @mongodb-developer/vercel-ai-memory ai mongodb`. Second, create a memory instance with an Atlas connection string and an embedding model. Third, pass the memory tools to the application, scoped to a user and session.

A minimal example from the announcement creates the memory instance with an OpenAI embedding model (`text-embedding-3-small`) and passes it into a `ToolLoopAgent` running `gpt-4.1`, scoped to `userId: 'alice'` and `sessionId: 'sess-001'`. From there, the model decides when to save and when to search for memories.

What to watch

The release positions MongoDB Atlas as a single store for both application data and AI memory, which could simplify stacks for teams already running Atlas. The open questions are the ones that always accompany managed memory: how retrieval quality holds up as memory volumes grow, how much the vector search and storage add to running costs at scale, and whether model-driven forgetting behaves predictably enough for production use. Developers can evaluate those for themselves, since the package is open source and the documentation is public.

Comments (0)

  1. No comments yet. Be the first to share what worked for you.

Leave a comment

Comments are reviewed before they appear. Your email address is not published.