BuildRiot
Sign in

Article · AI

Test recall, isolation, updates and deletion in MongoDB’s Vercel AI SDK memory

MongoDB’s Vercel AI SDK integration adds persistent memory with configurable retention. This guide outlines a small assistant and four acceptance tests for transcript replay, tenant isolation, corrected facts and deletion.

A lamp-lit miniature desk illustrates assistant memory tests through replayed conversations, separate blue and lavender drawers, corrected fact cards, and a paper shredder.
Illustration: BuildRiot (AI-generated)

Key takeaway

Stored information does not automatically become useful context for the next model call. Developers need to inspect what reaches the model, enforce ownership, resolve conflicting facts and define what forgetting removes.

Start with the boundary between storage and recall

MongoDB announced persistent memory for Vercel AI SDK applications on November 5, 2026, with automatic vector-index creation and embedding-dimension detection. Its minimal example gives the model tools for saving and searching memories, leaving the model to decide when to use them. Making storage available therefore does not ensure that every useful fact reaches it. A dependable assistant needs checks at capture, retrieval and answer generation. Sources: MongoDB

Build a developer-preferences assistant that remembers an editor, programming language and deployment region. Add a deterministic lookupBuild tool that returns a synthetic build ID and status, creating evidence to trace through storage and replay. Use synthetic identities and facts so failures can be inspected without exposing personal information. The exercises below are proposed acceptance tests, not measured results; the integration’s behavior under these conditions remains unverified.

Pin the implementation and set retention

Start with MongoDB’s TypeScript command-line tutorial. It uses tsx, environment variables, a scoped ToolLoopAgent and separate runs to demonstrate persistence. Resolve the published package version: the changelog records 1.0.0, while the indexed npm listing showed 0.5.0 and an older deletion signature. That discrepancy does not establish which version is currently available from npm. The changelog says 1.0.0 introduced no runtime changes beyond 0.6.0. It excludes the separate /eve provider from production readiness and stability guarantees. Pin one AI SDK major: v7 uses runtimeContext and onEnd. The changelog says the earlier context-based hook could silently save no transcript. Sources: MongoDB Developer, MongoDB, npm

  1. Record the resolved package version, AI SDK major, model identifier, embedding model and database configuration.
  2. Derive an opaque memory-owner ID from authenticated tenant membership and user identity, then verify session ownership.
  3. Run the tutorial’s persistence check in two separate processes before changing session behavior.
  4. Record request IDs, generation messages, stored document IDs, retrieved IDs and reconstructed model input.
  5. Choose retention settings and preserve them alongside the test corpus.
  6. Record topology.keepHistory for each run. Set topology.keepHistory: true for historical-recall tests; test default update-in-place behavior separately. Sources: MongoDB Developer

The table below shows the different retention defaults across the five memory tiers. The reference describes four policies: no expiry, fixed time to live, expiry below an importance threshold and dynamic expiration. Dynamic expiration is calculated on writes and can optionally refresh on reads. The semantic-memory example expires entries below importance 6 after 604,800 seconds, or one week. Choose policies for the assistant’s purpose, then test them rather than assuming all information ages out together. Sources: MongoDB

Table

Default retention by memory tier

Memory tierPurposeDefault retention
SessionConversation turns24 hours from created_at
ScratchpadTemporary working notes1 hour from created_at
EpisodicEvents and outcomes1 year from stats.last_retrieved
SemanticEntity facts and preferencesNo automatic expiry
ProceduralWorkflows and instructionsNo automatic expiry
The defaults use different expiration clocks, and two tiers have no automatic expiry.Source: MongoDB

Compare stored history with the next model input

After the initial persistence check, move session persistence to runtime hooks. The repository recommends hook-driven sessions for production. It says they cannot be combined with tool-driven sessions for the same session. It documents hiding session commands while keeping storage available. Hook mode loads history and persists the user prompt plus assistant and tool messages after generation. However, loadSession() restores only user and assistant turns. Tool turns remain audit records rather than standalone provider tool results, avoiding orphan-result errors. Sources: MongoDB Developer

Send ten numbered prompts, then trigger two build lookups in one generation. Compare generation output, database records and reconstructed model input. Make a lookup return a value the assistant does not repeat verbatim, restart the process and ask for that value. If the answer is missing, inspect all three evidence sets before calling it storage loss. Repeat with a duplicated request ID, an interrupted stream, failed final persistence, concurrent requests and history longer than the configured window. Count missing and duplicate records, measure completion-to-storage latency and identify eligible information omitted from replay.

Define the boundary for any exactly-once assertion. MongoDB’s announcement uses that language without establishing request-level idempotency across retries, crashes or concurrency. Treat a successful answer followed by failed persistence as a separate application outcome. Define an explicit recovery policy. Record what the user experienced alongside what the database eventually stored. Sources: MongoDB

Test authorization across reads and mutations

Create two tenants with the same local user name, alice, and session name, session-1. Give each a different random canary fact, then add a second user within the first tenant. The reference allows additional vector-filter fields, including tenant_id, but index configuration alone does not prove authorization across operations. The changelog reports fixes for cross-user deletion and scratchpad promotion. It also reports session and scratchpad reads scoped by user and session. It says missing scope now fails closed, except for an explicit demo-only shared-default option. The reference still describes default scope values, so pass explicit, server-verified scope. Sources: MongoDB Developer, MongoDB

Test all five memory tiers separately. Attempt another owner’s identifiers, exact and paraphrased canary searches, deletion by a known foreign document ID and promotion of a foreign scratchpad. Include absent, empty, whitespace and malformed scope, plus documents missing expected tenant metadata. Put an instruction to cross scopes inside a retrieved memory to test the application boundary. Require zero unauthorized records returned or modified. Inspect returned IDs and database changes rather than only the assistant’s response. A passing result supports those tested cases, not a universal isolation claim.

Separate current facts from preserved history

MongoDB’s announcement says semantic and procedural memories preserve versions. The changelog specifies that these saves update in place by default; preserving history requires topology.keepHistory: true. Semantic, procedural and episodic memories use vector retrieval. Preserving history does not establish which version will support a present-tense answer. Sources: MongoDB, MongoDB Developer

Test current-fact recall separately with default update-in-place behavior and with history enabled. In one session, tell the assistant that the preferred deployment region is Frankfurt. In another, correct the preference to Dublin, then restart before asking which region the next deployment should use.

For the run with topology.keepHistory: true, ask separately which region was preferred before. Then repeat using the phrase European Union hosting preference. Give the older fact higher importance or retrieve it more recently to test whether ranking overwhelms the correction. Capture retrieved versions, ranking, timestamps and answers to distinguish competing records from incorrect interpretation. Score current-fact accuracy, contradictions and appropriate abstention separately for each configuration. Score historical accuracy only for the history-enabled run. If current-state resolution must be deterministic, maintain an application-owned fact key and an explicit policy for superseding old facts.

Measure forgetting through physical removal

Put one synthetic fact into a user message, an assistant paraphrase, a semantic entry, an episode and a scratchpad, then request forgetting. The indexed npm documentation says memory_forget targets a memory type and ID and sets expire_at to the current time. A later time-to-live (TTL) sweep removes the document; check this behavior against the pinned release. MongoDB’s database manual says expiration does not guarantee immediate deletion. Cleanup can be delayed by load, and documents without a valid indexed date do not expire. Record request receipt, operation acknowledgment, exclusion from retrieval and physical absence as distinct timestamps. Sources: npm, MongoDB

Probe immediately, after the expected sweep interval, under load and after a restart using collection reads and semantic search. Include old and current versions, duplicate extractions, important memories exempt from expiry and dynamic retention refreshed by reads. Test a concurrent request already holding the fact and a later extraction pass over the original transcript. Define whether the application promises removal of one record or erasure of the fact across representations. For broader erasure, add immediate retrieval suppression, links between derived memories and source messages, and controls against re-extraction. Account separately for logs, caches, exports and backups.

Before deployment, publish separate storage, retrieval and answer-quality results alongside the exact configuration and inspectable failures. Repeat model-dependent cases and compare the same answer model with full-transcript and no-memory baselines. Report cold-start and warm-request latency with sample counts, token usage and embedding calls. Make each failed assertion actionable. Identify whether the fix belongs in capture, authorization, fact resolution or deletion handling.

Attribution

Sources

  1. 1MongoDBIntroducing the MongoDB Vercel AI SDK Integration: Persistent Memory for AI ApplicationsSource published (UTC)
  2. 2MongoDB Developervercel-ai-memory changelog
  3. 3MongoDBIntegrate MongoDB with the Vercel AI SDK
  4. 4MongoDB DeveloperMongoDB-backed persistent memory for the Vercel AI SDK
  5. 5MongoDBGet Started with the MongoDB Vercel AI SDK Integration
  6. 6npm@mongodb-developer/vercel-ai-memory
  7. 7MongoDBTTL Indexes

Read the original source for full details and context.

Report a problem

Links, dates or what you expected. Do not include passwords or private data.

More on AI

All AI stories
Test recall, isolation, updates and deletion in MongoDB’s Vercel AI SDK memory · BuildRiot