Building an AI-powered application often requires more than sending a user's question to a large language model. The application may need to remember previous conversations, understand user preferences, retrieve information from older sessions, and use that information when answering new questions. Without persistent memory, an AI assistant may behave as if every conversation is its first interaction. It can answer the current question, but it may not remember decisions, preferences, or important details shared earlier.
Developers usually solve this problem by building a separate memory system. This can involve storing conversations in a database, generating embeddings, maintaining a vector index, extracting important information with an AI model, and retrieving relevant records when a new question arrives. Each component needs configuration, monitoring, security, and maintenance. As the application grows, managing the entire pipeline can become a significant development task.
Amazon OpenSearch Memory provides a managed alternative. It is a capability in Amazon OpenSearch Service designed to give AI agents persistent memory across conversations and sessions. An application sends conversations, structured information, or documents as events. OpenSearch Memory stores those events, extracts useful information, creates searchable memories, and makes them available through search operations.
The important difference is that developers do not have to provision a separate vector database or manually build the complete extraction and indexing pipeline. They create a memory space, configure memory strategies, send events, and search the resulting memories. This article explains how the service works and how developers can use it to build applications that remember useful information without managing vector infrastructure themselves.
What Is Amazon OpenSearch Memory?
Amazon OpenSearch Memory is a fully managed memory service for AI agents and applications. It stores incoming information as events and uses configured memory strategies to extract facts, summaries, and other useful details. These extracted details are stored as memories that applications can search later.
For example, imagine building a customer support assistant. During the first conversation, a customer explains that they are using a particular product version and have an unresolved billing issue. The application sends that conversation to OpenSearch Memory. The service stores the original event and extracts useful information, such as the product version, the issue category, and the current case status.
When the customer returns in another session, the application can search the customer's existing memories. It can retrieve the relevant case information and provide it to the AI model as context. The customer does not need to explain the entire situation again.
OpenSearch Memory manages several operations that would otherwise require separate infrastructure:
Event storage: Stores conversations, structured information, and supported document content.
Memory extraction: Identifies useful facts and information from stored events.
Embedding generation: Creates the representations needed for semantic search.
Indexing: Makes events and memories searchable.
Memory consolidation: Updates existing memories when new information changes an earlier fact.
Retrieval: Finds relevant memories using keyword, semantic, or hybrid search.
The service is serverless from the application developer's perspective. There are no OpenSearch clusters to provision for this memory workflow, no instance types to select, and no indexes that developers must create and maintain for the managed memory service. AWS manages the extraction model calls and the underlying memory processing.
This does not mean that developers can ignore application architecture. They still need to decide what information to store, how to identify users, when to retrieve memories, and how to protect the information. OpenSearch Memory manages the infrastructure, but the application remains responsible for using memory correctly.
Understand Spaces, Events, and Memories
Before integrating OpenSearch Memory into an application, it is important to understand its three main building blocks: spaces, events, and memories. Each one has a different responsibility.
A space is the main resource that stores events and extracted memories. It also defines the memory strategies, retention settings, extraction configuration, and encryption settings used by the application. You can think of a space as the memory environment for an application. For example, a customer support application can have one space, while a separate coding assistant can use another space with different memory strategies.
An event represents information submitted by your application. It can contain conversation messages, structured JSON data, or supported documents stored in Amazon S3. The original event is retained as submitted, which means the application can retrieve the source information later instead of depending entirely on the extracted memory.
A memory is the information extracted from one or more events or written directly by an application. It can represent a user preference, a fact, a session summary, or a domain-specific record. A memory also maintains references to the events from which it originated. This relationship is useful because an application can retrieve the original event when it needs to verify the information behind a particular memory.
Consider this example:
Event:
User: I prefer vegetarian food.
Assistant: I can recommend vegetarian meals.
Extracted memory:
The user prefers vegetarian food.
The original conversation is the event. The extracted statement is the memory. Later, the application can search for food preferences without reading the entire conversation again.
The distinction matters because events and memories serve different purposes. Events preserve the original information, while memories provide a more useful representation for future retrieval.
How OpenSearch Memory Extracts and Stores Information
OpenSearch Memory follows an asynchronous processing model. When an application sends an event, the service stores it first. Memory extraction happens afterward in the background. This separation helps prevent the extraction process from becoming part of the application's immediate response path.
The processing workflow generally follows these steps:
The application sends an event containing conversation messages, structured information, or document content.
OpenSearch Memory stores the event and returns an event identifier.
Configured memory strategies collect information from the event.
When an extraction trigger is reached, the service calls its extraction model and generates candidate memories.
The service consolidates new information with existing memories when consolidation is enabled.
The resulting memories are indexed and become available through search operations.
This asynchronous design has an important consequence. A successful event creation does not mean that its extracted memories are immediately searchable. The original event becomes available first, while memory extraction and indexing take additional time.
For example, an application may send a conversation and receive a successful response from the CreateEvent operation. If it immediately calls SearchMemories, the response may not contain the new fact because extraction has not completed yet. With the default configuration, extraction commonly happens after the session becomes idle. The application should account for this delay instead of assuming that every new event produces an immediately searchable memory.
Choose the Right Memory Strategy
A memory strategy defines what kind of information OpenSearch Memory should extract from incoming events. A space can use multiple strategies, and each strategy processes the same events independently.
OpenSearch Memory provides three main strategy types.
SEMANTIC Strategy
The SEMANTIC strategy extracts facts and preferences that may remain useful across multiple conversations. These can include user preferences, product information, recurring requirements, and other important details.
For example, a travel assistant may receive the following conversation:
User: I usually prefer direct flights.
User: I also prefer an aisle seat.
A semantic strategy can extract memories such as:
The user prefers direct flights.
The user prefers aisle seats.
These facts can then be retrieved when the user plans another trip.
SUMMARY Strategy
The SUMMARY strategy creates a summary of a conversation session. Instead of retrieving every message from a long conversation, the application can search for a shorter description of what happened.
For example, a customer support conversation may contain several messages about a payment failure. The summary could retain the main problem, the troubleshooting steps, and the current status.
This is useful when an AI agent needs to continue work from an earlier session without sending the entire conversation history to the language model.
CUSTOM Strategy
The CUSTOM strategy is useful when the application needs information that does not fit the built-in fact extraction or session summary patterns. Developers provide instructions describing what information should be extracted.
For example, an order management assistant may need to remember order IDs, delivery dates, payment status, and unresolved delivery problems. A custom strategy can describe the required information so that the extraction process focuses on those business-specific details.
A space can have up to ten strategies. For most applications, starting with SEMANTIC and SUMMARY is a reasonable approach. Add a CUSTOM strategy when the application has a clear requirement for extracting specialized information.
Create an OpenSearch Memory Space
The first step in an integration is creating a space. You can create and manage spaces through the AWS Management Console, AWS CLI, SDKs, or the OpenSearch Memory API.
The following example creates a space with a semantic strategy and a summary strategy:
aws opensearchmemory create-space \
--region us-east-1 \
--name customer-support-memory \
--memory-strategies \
'[{"type":"SEMANTIC","name":"user-facts"},{"type":"SUMMARY"}]'
The command creates a space named customer-support-memory. The semantic strategy is named user-facts, while OpenSearch Memory generates a name for the summary strategy.
The response includes the space ID and its current status. A newly created space may initially have a status of CREATING. You must wait until its status becomes ACTIVE before sending events.
You can use the AWS CLI waiter for this:
aws opensearchmemory wait space-active \
--region us-east-1 \
--space-id sp-02864597b164
Replace the example space ID with the ID returned by your CreateSpace operation.
A space is a resource that can incur charges. For that reason, clean up test spaces that are no longer required, especially when experimenting with different memory strategies.
Send Conversations as Events
After the space becomes active, the application can send information using the CreateEvent operation. Every event belongs to an actor and a session.
The actor identifies the person or entity that the information is about. In a customer-facing application, this will usually be an application-level user identifier. The session identifies one conversation or interaction.
It is important to use stable actor IDs and reuse the same session ID for every event belonging to the same conversation. If each message is sent with a different session ID, the service may treat the messages as separate conversations. This can reduce the quality of session summaries and memory extraction.
The following example represents a conversation event:
{
"spaceId": "sp-02864597b164",
"actorId": "customer-123",
"sessionId": "support-session-001",
"payload": {
"conversational": {
"unified": {
"source": {
"object": {
"messages": [
{
"role": "USER",
"content": {
"text": "I am using product version 4.2 and my payment failed twice."
}
},
{
"role": "ASSISTANT",
"content": {
"text": "I can help investigate the payment issue."
}
}
]
}
}
}
}
}
}
Save the request as event.json and submit it using the AWS CLI:
aws opensearchmemory create-event \
--region us-east-1 \
--cli-input-json file://event.json
The service returns an event ID after storing the event. The event can be retrieved even before the extraction process finishes.
In a real application, the conversation should be sent to OpenSearch Memory as it happens rather than waiting until the entire conversation is finished. This allows the service to collect messages and process them according to the configured extraction triggers.
The AWS SDKs also support client tokens for request retries. Using the SDK's built-in retry behavior helps prevent an unsuccessful network response from accidentally creating duplicate events.
Search Memories Without Managing Embeddings
One of the biggest advantages of OpenSearch Memory is that developers do not have to generate and manage embeddings themselves for its supported semantic search workflow.
An embedding is a numerical representation of text that captures information about its meaning. Traditional vector search systems use embeddings to compare a query with stored content. Developers commonly need to select an embedding model, generate vectors, store them, create a vector index, and maintain the search pipeline.
OpenSearch Memory handles the embedding and indexing operations for its managed memory search capabilities. The application sends a natural-language query, and the service performs the required semantic search.
It supports three useful search approaches.
Keyword Search
Keyword search is useful when the application knows the exact words or phrases it wants to find.
For example:
{
"match": {
"memory_text": "payment failed"
}
}
This searches memory text for the supplied terms. It is useful for searching known product names, case references, or specific phrases.
Semantic Search
Semantic search finds information based on meaning rather than requiring an exact word match.
For example, an application may search with:
{
"neural": {
"memory_vector": {
"query_text": "What payment problems has this customer experienced?",
"k": 10
}
}
}
The application does not have to create the query embedding itself. OpenSearch Memory handles that part of the search process.
This is useful when users express the same problem in different ways. A customer may describe an issue as a failed payment, an unsuccessful transaction, or a card being declined. Semantic search can help find related memories even when the wording is different.
Hybrid Search
Hybrid search combines keyword and semantic search. This can improve retrieval when both exact terms and meaning are important.
For example:
{
"hybrid": {
"queries": [
{
"match": {
"memory_text": "payment"
}
},
{
"neural": {
"memory_vector": {
"query_text": "What payment issues has the customer reported?",
"k": 10
}
}
}
]
}
}
The search combines exact keyword matching with semantic similarity. This is particularly useful for AI agents because users do not always repeat the same words when referring to an earlier issue.
Search Memories for a Specific User
OpenSearch Memory requires an actor ID when searching memories. This is an important part of its multi-user design because a search is scoped to one actor rather than searching every user's memories together.
The following command searches memories belonging to a particular user:
aws opensearchmemory search-memories \
--region us-east-1 \
--space-id sp-02864597b164 \
--actor-id customer-123 \
--query '{"match": {"memory_text": "payment"}}'
The response contains matching memories ranked by relevance. It can include the memory content, memory type, strategy name, relevance score, timestamps, and source event identifiers.
The source event identifiers are especially useful. If an application needs to verify why a particular fact was extracted, it can use those identifiers to retrieve the original event. This helps avoid treating an extracted memory as unquestionable truth.
SearchMemories can also restrict results to particular memory strategies. For example, an application that needs a user's preferences can search the SEMANTIC strategy instead of returning session summaries and unrelated custom records.
The service supports additional query types, including bool, range, and term, which can help combine relevance searches with metadata and time filters. However, it supports a subset of the OpenSearch Query DSL rather than every query feature available in a standard OpenSearch cluster. Developers should check the supported query types before designing a search workflow around a specific DSL feature.
Keep Memory Information Updated
A memory system must handle changing information correctly. Suppose a user initially says that they live in Delhi but later explains that they have moved to Mumbai. A simple append-only system may store both statements and return conflicting information in future searches.
OpenSearch Memory supports memory consolidation to handle this situation. When consolidation is enabled, the service compares newly extracted information with existing memories for the same actor and strategy. It can add a new memory, update an existing memory, or skip a candidate that duplicates information already stored.
This is particularly useful for long-running assistants. User preferences, customer details, product configurations, and operational information can change over time. Consolidation helps keep the current memory useful instead of allowing every new conversation to create another copy of the same fact.
However, consolidation should not replace historical recordkeeping when the application needs a complete history of changes. If the requirement is to retain every version of a business record, store that history in an appropriate system of record and use OpenSearch Memory as a retrieval layer.
Use OpenSearch Memory With an AI Agent
OpenSearch Memory does not automatically make decisions for an AI agent. The application still needs to decide when to save information and when to retrieve it.
A typical integration follows this flow:
A user sends a message to the application.
The application identifies the user and the current conversation session.
The application searches OpenSearch Memory for relevant information.
The application adds the retrieved memories to the context sent to the AI model.
The AI model generates a response using the current message and relevant historical context.
The application sends the new conversation turn to OpenSearch Memory as an event.
This design separates memory management from response generation. The application does not need to send every previous message to the language model. Instead, it retrieves a smaller set of relevant memories and includes them when they help answer the current question.
It is also important to control how much memory is included in a prompt. Retrieving too many unrelated memories can increase token usage and make the model's response less focused. Use relevant search strategies, actor scoping, and appropriate result limits to keep the context useful.
Security and Data Isolation
Memory systems often contain personal preferences, customer information, support history, and internal operational details. Security must therefore be part of the integration design from the beginning.
OpenSearch Memory uses AWS Identity and Access Management to control access to spaces and their operations. IAM policies can limit which principals can create spaces, send events, search memories, or manage stored information.
Actor-level isolation is particularly important. Every application user should have a stable actor ID, and the application must ensure that one user cannot request another user's actor ID when searching or retrieving memories.
AWS provides the osm:actorId IAM condition key to help restrict access to specific actors. This adds a security control beyond relying only on application code to pass the correct identifier.
The service encrypts stored data at rest and supports AWS-owned keys by default, with an option to use a customer-managed AWS KMS key. Requests use TLS 1.2 or later.
Developers should also avoid placing sensitive personal information in metadata fields. Metadata is intended for attributes used to filter or organize records, such as a channel or tenant identifier. The actual content belongs in the event payload.
Manage Retention and Processing Delays
Events and memories have separate retention settings. Events can be retained from 1 to 365 days, while memories can be retained from 1 day to 10 years or indefinitely. The application should choose these values based on its business requirements and data retention policies.
Keeping events longer can be useful when the application needs to inspect original conversations or reprocess information. However, it also means retaining more source data. Memories may need a different retention period because they contain extracted information rather than the full original interaction.
Processing delays also need to be considered. CreateEvent returns when the event has been stored, not when every memory has been extracted and indexed. The default extraction behavior uses triggers such as message counts and session idle time. A short conversation may therefore need to become idle before its memories are generated.
If an application needs a memory immediately, it should not assume that a newly submitted event is already available through SearchMemories. The application can retrieve the original event directly or use an appropriate direct memory-writing workflow when it already knows the fact that needs to be stored.
Best Practices for Production Applications
Use one space per application rather than creating a separate space for every user.
Keep development and production memory spaces separate.
Start with SEMANTIC and SUMMARY strategies before introducing custom extraction.
Use stable actor IDs and reuse session IDs throughout a conversation.
Send conversation turns as they happen rather than batching everything at the end.
Use hybrid search when both exact terms and related meanings matter.
Restrict searches to the memory strategies required by the current operation.
Apply IAM permissions and actor-level isolation to prevent cross-user data access.
Set event and memory retention periods according to business and compliance requirements.
Treat extracted memories as useful context, not as an authoritative replacement for business records.
Account for asynchronous extraction when designing application response flows.
Monitor service usage and costs, including space storage and extraction model calls.
Summary
Amazon OpenSearch Memory makes it easier to add persistent memory to AI-powered applications without building and managing a separate vector infrastructure. Applications send conversations, structured information, and supported documents as events. The service stores those events, extracts useful information through memory strategies, consolidates changing facts, and makes the resulting memories available through search.
The main building blocks are spaces, events, and memories. SEMANTIC strategies extract facts and preferences, SUMMARY strategies retain session context, and CUSTOM strategies support application-specific information. Developers can retrieve information using keyword, semantic, and hybrid queries without managing the embedding and indexing pipeline themselves.
However, a successful integration still requires careful decisions about actor IDs, session management, memory strategies, retention, security, and asynchronous processing. When these areas are designed properly, OpenSearch Memory can reduce infrastructure work and help AI agents provide more useful responses across multiple conversations.
Join the conversation! Your thoughts help the community grow.