All posts by Ganesh Natarajan

Introducing Amazon OpenSearch Memory: Persistent memory for AI agents

Post Syndicated from Ganesh Natarajan original https://aws.amazon.com/blogs/big-data/introducing-amazon-opensearch-memory-persistent-memory-for-ai-agents/

Today, we are announcing the general availability of Amazon OpenSearch Memory, a new capability built on Amazon OpenSearch Serverless for adding persistent memory to AI agents. OpenSearch Memory stores agent interactions as searchable events, derives useful memories, and retrieves relevant context across sessions. You can give agents long-term memory without provisioning infrastructure or building separate extraction, indexing, consolidation, and retrieval systems.

AI agents need memory when an interaction depends on information from an earlier session. A support agent might recall a customer’s open case and product configuration, a coding agent needs repository conventions and prior decisions, and a personal assistant keeps a user’s preferences. An agent that restarts or hands off a conversation also needs the exact turns that came before. Passing the complete conversation history to the model becomes slower and more expensive as that history grows, and the relevant information can be difficult to find.

Building a memory system requires more than storing transcripts. You must capture events, extract facts and summaries, generate embeddings, reconcile new information with existing memories, retrieve the right context, isolate data, and enforce retention and deletion policies. You must also operate the infrastructure and evaluate whether the retrieved memories improve agent responses.

OpenSearch Memory manages these functions as one serverless capability. Your application writes conversation events after each turn and searches for relevant memories and events before generating a response. OpenSearch Memory stores the original events verbatim, makes them searchable within seconds, and asynchronously derives structured memories. It handles extraction, embedding, indexing, consolidation, retrieval, data isolation, and retention.

How OpenSearch Memory works

The architecture has two boundaries: your application and OpenSearch Memory. Your AI agent connects through an AWS SDK, an AWS Model Context Protocol (MCP) server, a hook, or a supported framework integration. The following diagram shows how your application writes events to a space, how OpenSearch Memory derives memories using an Amazon Bedrock model that you choose, and how your application retrieves context. Extraction and embedding costs are included in OpenSearch Memory pricing. For details, see Amazon OpenSearch Service pricing.

Amazon OpenSearch Memory architecture: an application writes events to a space, an Amazon Bedrock model derives memories, and the application retrieves context

Figure 1: How an application writes events to an Amazon OpenSearch Memory space, derives memories with an Amazon Bedrock model, and retrieves context

OpenSearch Memory organizes data in a space, the AWS resource that serves as a memory store. A space contains the following:

  • Events, which are the original interactions written by your application.
  • Memories, which are facts, preferences, and summaries derived from those events.

Every request names an actor, the end user the data belongs to. An optional session ID groups events from one conversation. A condition key on the agent’s AWS Identity and Access Management (IAM) role can limit which actors the agent can act for, and event reads and searches can be limited to one session. Data in a space is encrypted with AWS Key Management Service (AWS KMS), and you can use your own customer managed key. AWS CloudTrail logs API calls to a space, and Amazon CloudWatch reports its metrics.

The write and retrieval paths operate independently:

  1. After each interaction, your application writes the conversation turn to a space as an event. OpenSearch Memory stores the event verbatim (CreateEvent) and indexes it for keyword, semantic, and hybrid search. Events are available to read immediately and become searchable within seconds.
  2. In the background, the memory strategies configured on the space extract memories from these events.
  3. OpenSearch Memory compares each new memory with the existing ones and adds, updates, or skips it, so stored memories stay current.
  4. Before the agent responds, your application retrieves context: memories about the user from past conversations, the exact turns of the current or earlier conversations, or both. Your application adds the retrieved context to the model’s prompt.

Benchmarking OpenSearch Memory with LongMemEval

In this evaluation, the configured OpenSearch Memory workflow gave the answering model about one-twelfth as many input tokens as the full conversation history (about 13,500 compared with 167,000 per question). It preserved most of its answer accuracy: 93.0% compared with 95.2%.

We used LongMemEval-S to evaluate whether a complete memory workflow could help an AI assistant answer questions that depend on earlier conversations. The public benchmark contains 500 questions about information distributed across approximately 50 chat sessions for one user (Wu et al., ICLR 2025). It evaluates the final answers produced using retrieved memories, rather than memory extraction alone.

For this evaluation, we configured the OpenSearch Memory workflow as follows:

  1. We wrote the benchmark conversations to OpenSearch Memory as events.
  2. The space’s default memory strategies, for facts and session summaries, derived and consolidated memories from those events.
  3. For each question, the answering model received the top 30 memories and events from hybrid search.
  4. Claude Opus 5.5 answered each question from those results and, in a separate call, graded each answer against the benchmark’s reference answer.

Claude Haiku 5.5 extracted memories, and Amazon Titan Text Embeddings created the embeddings. Each result comes from one run, with a 95% confidence range of 2 to 3 points either way. To limit grading bias, Opus 5.5 graded each answer in a separate call that saw only the question, the reference answer, and the answer.

We compared the OpenSearch Memory workflow with two baselines: retrieving raw conversation turns with BM25 keyword search, and supplying the complete conversation history to the answering model. Claude Opus 5.5 answered and graded all three.

Context supplied to the answering model What the comparison measures Answer accuracy Context tokens per question
OpenSearch Memory: top 30 results from memories and events The configured extraction, consolidation, and hybrid retrieval workflow 93.0% Approximately 13,500
BM25: top 30 raw conversation turns Keyword retrieval without memory extraction or consolidation 88.6% Approximately 22,700
Full conversation history Answering with all conversation turns 95.2% Approximately 167,000

For agents with long-running conversations, this approach can reduce model input costs and preserve room in the context window without discarding information from earlier sessions. The workflow also scored 4.4 percentage points higher than BM25 retrieval over raw conversation turns. These results reflect the tested setup, including its memory strategies, models, and retrieval settings, and do not represent every possible OpenSearch Memory configuration.

Getting started with Amazon OpenSearch Memory

You can create your first space from the Amazon OpenSearch Service console or the AWS SDK. The following sections walk through both.

Launch OpenSearch Memory from the console

You can create a space and inspect its events and memories in the Amazon OpenSearch Service console. The following video shows the steps.

  1. In the Amazon OpenSearch Service console, under Memory, choose Spaces, and then choose Create Space.
  2. Choose Easy create, enter a space name, and choose Create Space. Easy create adds a Semantic and a Summary strategy and uses service defaults for encryption and expiry. Choose Standard create to set these yourself.
  3. Wait for the status to change from Creating to Active. The Memory strategies tab shows the strategies on the space.
  4. After your agent writes events, open the Events tab and enter an actor ID to see each conversation. The Memories tab shows the memories extracted from those events.

Walkthrough with the AWS SDK

This walkthrough adds memory to a customer support agent. The agent needs to remember account details, prior case history, and user preferences across sessions.

Prerequisites

To follow this walkthrough, you need the following:

  • An AWS account with permissions to create and use OpenSearch Memory spaces.
  • Python 3.10 or later and the AWS SDK for Python (Boto3) 1.44.4 or later.
  • One of the supported AWS Regions: US East (N. Virginia), US West (Oregon), Asia Pacific (Tokyo), or Europe (Frankfurt).

1. Create a space

You start by creating a space for the support agent. This is a one-time setup. The space defines what the service extracts, how long it keeps data, and how it encrypts it.

import boto3

REGION = "us-east-1"
osm = boto3.client("opensearchmemory", region_name=REGION)

space = osm.create_space(
    name="customer-support-agent",
    memoryStrategies=[
        {"type": "SEMANTIC", "name": "facts-and-preferences"},
        {"type": "SUMMARY", "name": "session-summaries"},
    ],
    eventExpiryDays=90,       # keep raw events for 90 days (1-365)
    memoryExpiryDays=365,     # keep memories for 1 year (0 = never expire)
    # extractionModelId="anthropic.claude-opus-5-5",  # optional; Claude Haiku 5.5 by default
    # encryptionConfiguration={"kmsKeyArn": "..."},  # optional customer managed AWS KMS key; can only be set here
)
space_id = space["spaceId"]

# The space starts in CREATING. The waiter returns once it is ACTIVE and raises if it reaches FAILED.
osm.get_waiter("space_active").wait(spaceId=space_id)

2. Write events after each turn

After each agent turn, you write an event. The call returns after the event is stored, and extraction runs in the background.

def conversational(turns):
    """Build a CreateEvent payload from [(role, text), ...]."""
    return {"conversational": {"unified": {"source": {"object": {
        "messages": [{"role": role, "content": {"text": text}} for role, text in turns]
    }}}}}

event = osm.create_event(
    spaceId=space_id,
    actorId="user-42",           # the end user
    sessionId="session-007",     # one stable ID per conversation
    payload=conversational([
        ("USER", "I'm calling again about Case #78234. It's still not resolved."),
        ("ASSISTANT", "I've escalated Case #78234 to billing. Your reference is ESC-5521, and billing will reply within 48 hours."),
    ]),
    metadata={"channel": "phone"},   # optional metadata, copied onto derived memories
)
event_id = event["event"]["eventId"]

Extraction freshness: Memories appear after the service processes the events in the background, so for a brand-new user, a memory search (step 3) can return nothing at first. Events don’t wait. They are readable as soon as the write returns and searchable within seconds. An agent that restarts or hands off the conversation can resume the session from its events right away. Use ListEvents to find the session’s recent events, and BatchGetEvent or GetEvent to read them. By default, ListEvents returns a session’s events newest first, so the following slice reads the most recent turns. Pass the sort parameter to return them oldest first instead.

# Resume the session: read its latest turns
recent = osm.list_events(spaceId=space_id, actorId="user-42", sessionId="session-007")
turns = osm.batch_get_event(
    spaceId=space_id,
    eventIds=[e["eventId"] for e in recent["events"][:10]],   # up to 10 IDs per call
)

Writing memories directly: You can also write a memory directly with CreateMemory. Use it to import what you already know, such as preferences from an existing customer relationship management (CRM) system, or to let the agent save its own findings. The service embeds and stores the memory under the strategy that you name.

# Import a preference from your CRM
osm.create_memory(
    spaceId=space_id,
    name="facts-and-preferences",   # a strategy name declared on the space
    actorId="user-42",
    content="The user prefers to be contacted by email.",
)

# Let the agent save its own finding about this user's case
osm.create_memory(
    spaceId=space_id,
    name="facts-and-preferences",
    actorId="user-42",
    content="Case #78234 is waiting on a manager approval code for the annual-plan refund.",
    metadata={"writtenBy": "support-agent"},   # marks agent-written memories so you can review or correct them later
)

The added metadata here keeps a record of which memories the agent wrote, so you can audit them later. Agent-written memories persist across sessions and feed later prompts, so review or correct them, for example by filtering on the writtenBy metadata, before you rely on them.

3. Search memories before each response

Before generating a response, you search the space for memories about this user and add them to the agent’s system prompt.

results = osm.search_memories(
    spaceId=space_id,
    actorId="user-42",            # every search is scoped to one actor
    query={
        "hybrid": {
            "queries": [
                {"match": {"memory_text": "Case #78234 open cases and account status"}},
                {"neural": {"memory_vector": {
                    "query_text": "open cases and account status", "k": 10}}},
            ]
        }
    },
    maxResults=10,
)

context = "\n".join(m["content"] for m in results["memories"])
# Add `context` to the agent's system prompt

In this support scenario, the keyword half of the query surfaces the exact case number from a prior session. The semantic half retrieves related context, such as the user’s preferred contact method and what the case is waiting on. The user doesn’t need to repeat themselves. Each turn adds two calls to your agent loop: one search before it responds, one write after.

Each result also carries sourceEventIds, the events the memory was derived from, so you can trace any fact back to the conversation that produced it.

Search the conversation itself: Memories capture what a conversation means. Events keep the conversation itself: every turn, verbatim, with who said it. To find an exact phrase, such as a commitment the agent made earlier in the conversation, search the events:

hits = osm.search_events(
    spaceId=space_id,
    actorId="user-42",
    sessionIds=["session-007"],   # optional: search only this conversation
    query={"match_phrase": {"text": "reply within 48 hours"}},
    maxResults=5,
)
snippets = [e["matchedContent"] for e in hits["events"]]   # the exact turns, with who said what

4. Let consolidation keep facts current

Users’ facts change. Consolidation handles the change without extra code.

# Session 1
osm.create_event(spaceId=space_id, actorId="user-42", sessionId="s-001",
    payload=conversational([("USER", "I'm based in New York.")]))

# Session 10, weeks later, after the user moves
osm.create_event(spaceId=space_id, actorId="user-42", sessionId="s-010",
    payload=conversational([("USER", "I just relocated to Seattle last week.")]))

# Once session 10 is processed, SearchMemories returns one updated memory,
# "The user was based in New York and relocated to Seattle ...",
# instead of keeping the old and new facts side by side.

Consolidation is on by default for every strategy. To keep an append-only history instead, set consolidationEnabled to False in the strategy’s configuration:

{"type": "SEMANTIC", "name": "facts-and-preferences", "configuration": {"consolidationEnabled": False}}

Clean up

To avoid incurring future charges, delete the space when you no longer need it. Deletion is permanent.

osm.delete_space(spaceId=space_id)
osm.get_waiter("space_deleted").wait(spaceId=space_id)

Get started today

Amazon OpenSearch Memory is generally available today in four AWS Regions: US East (N. Virginia), US West (Oregon), Asia Pacific (Tokyo), and Europe (Frankfurt). For pricing, including storage, retrieval, and extraction, see Amazon OpenSearch Service pricing. To start building, use the AWS SDK, the MCP server, or the OpenSearch Memory skills for Kiro, Claude Code, and Codex.

With OpenSearch Memory, your agents keep context across sessions without you building or operating a memory system.

To learn more, see OpenSearch Memory in the Amazon OpenSearch Service Developer Guide.

 


About the authors

Ganesh Natarajan

Ganesh Natarajan

Ganesh is a Senior Manager of Product Management for Amazon OpenSearch Service at AWS. He’s obsessed with building AI agents and making them run better.

Rishabh Agrawal

Rishabh Agrawal

Rishabh is a Senior Engineer at AWS, working on Amazon OpenSearch Service with a focus on agentic AI, memory systems, and intelligent retrieval. Previously, he worked on Amazon Bedrock and Amazon Personalize, building scalable AI and machine learning infrastructure. His interests include applied AI research and open source technologies.

Aruna Govindaraju

Aruna Govindaraju

Aruna is an Amazon OpenSearch Specialist Solutions Architect and has worked with many commercial and open source search engines. She is passionate about search, relevancy, and user experience. Her expertise with correlating end-user signals with search engine behavior has helped many customers improve their search experience.