What is the Memory System?

What is the Memory System?

All About the Memory System

icon
The Memory System is a new, premium feature that automatically stores and retrieves key information from your Adventure, helping keep the AI on track. Auto Summarization and the Memory Bank make up the Memory System. Press here to jump ahead and learn about how you can enable these features in your Adventure →

Memory is such an important part of AI Adventures. The core promise of AI Dungeon is that you can have ultimate freedom to be who you want to be and that the choices you make truly matter. But if the AI forgets those choices after a few thousand tokens, then those choices actually become meaningless, breaking the power of that promise.

With the new Memory System, we’re taking an important step toward providing an experience in which the AI can more reliably recall important details of your plot and story, letting you create deeper, richer, and more meaningful Adventures in AI Dungeon.

Example of the Memory System in the game screen featuring the Memory Bank in the Context Viewer and Auto Story Summary in the settings sidebar.
Example of the Memory System in the game screen featuring the Memory Bank in the Context Viewer and Auto Story Summary in the settings sidebar.

How the Memory System Works: Overview

The Memory System has been adapted from Heroes and utilizes various AI technologies, such as summarization models, embeddings, vectors, and embedding models. It’s made up of two major features: Auto Summarization and the Memory Bank.

Major Technical Constraint: AI Context Length

One of the biggest limitations of using AI large language models is limited context length, which is the amount of information the AI can process when generating its next output. Each model has its own max context length limit, and we also have tier limits in AI Dungeon since the longer your context length is, the higher the cost for the AI to generate a response. Context length is a real, unavoidable constraint that we have to work within.

In AI Dungeon, we construct the context we send to the AI by combining text from your story with AI Instructions, Plot Essentials (formerly called “Memory”), Author’s Note, and relevant Story Cards. The AI processes this information and generates the next action in your adventure.

Eventually, the amount of content in your story exceeds the amount of text we can send to the AI. We have to cut portions of text, usually by removing the oldest parts of your story text. Since text is cut, it can feel like the AI is “forgetting” important details of your story since those details were unable to be sent to the AI.

The Memory System is meant to combat these context length technical constraints and provide you with a better AI experience during your Adventures.

Inspired By the Human Brain

As we considered what information should be part of the Memory System, we found ourselves seeking inspiration from how the human brain works. When our brains store and recall information, we use two strategies. The first is by compressing memories, where we take a large chunk of information and distill it to remember the most important parts. The second is memory retrieval, where some memories stored in our brain only come to mind when they are relevant to our current context.

For instance, once you finish reading this blog post, it’s unlikely that you’ll be able to recall it word for word in its entirety, but you’ll probably be able to recall the high-level concepts, big changes, and parts that matter to you. This is compressed memory.

You also have a retrieval system that will bring important memories to your mind when they’re relevant. If you hear the word “fire hydrant,” your brain retrieves memories about what a fire hydrant is. You might think of its color and shape, its function and purpose, or any specific memories you have involving one.

Both memory compression and memory retrieval are important parts of enabling your brain to remember what’s important and have the right context when it needs it.

These two features of our Memory System are extremely useful in AI Dungeon, too. The story equivalent to a compressed memory is summarization, which will compress a section of the story to just the high-level information about the setting, characters, and events. Being able to retrieve more detailed memories is important, too, since that lets the AI remember important details when they’re relevant in the current context.

What are AI Dungeon Memories?

icon
The purpose of the Memory System is to compress, store, and retrieve memories to give the AI both a high-level perspective and the ability to recall specific details.

For AI Dungeon, a Memory is an AI-generated summary of a small set of your previous story actions. The summarized Memory retains key plot details but without the illustrative prose that is common in AI Dungeon adventures, making it more information-dense than the text of your adventure.

A new Memory is created by taking four of your previous actions (and the AI’s responses) and sending them to an AI model trained to summarize stories. This summary output from the AI is a Memory.

When starting a new adventure, we’ll wait until you are 8 actions deep into your adventure, and then we’ll summarize the oldest four actions (actions 1-4 of your adventure) into your first Memory. This means your first four actions will be summarized and stored as a Memory, but your most recent four actions are not. Then, after you take four more actions (now you’re up to 12 actions), we’ll summarize the previous 4 as a new memory (actions 5-8). This means your first 8 actions have been converted into two separate memories and your 4 most recent actions have not been. You are free to make edits or undo your last four actions without it impacting memories.

This cycle repeats indefinitely, and a new memory is created every four actions.

Two Complimentary Features: Auto Summarization and Memory Bank

Memories are used by the two major features that make up the new Memory System: Auto Summarization and the Memory Bank. These two features work together to recall important information, giving the AI the ability to remember the high-level overview and to remember specific relevant details, just like our brains do.

Auto Summarization keeps a running overview of your story’s plot to help the AI track the overall direction of your story. We do this by appending new memories to your Story Summary, a new Plot Component we’re adding to support this feature. After several memories are added to the Story Summary, we’ll re-summarize it by sending it to our summarization AI model. Because the summary will have the overall context of your story, it will help keep the AI on track and make sure it doesn’t lose the plot.

The Memory Bank stores and intelligently retrieves relevant memories and includes them in the context. In practice, it acts like an automatic Story Card system since it saves important details from the story and then dynamically inserts them into the context when they are relevant to your current action. Whereas the Auto Summarization feature is meant to keep track of the overall plot and story direction, the Memory Bank might recall important details like your dog’s name, where you found the Sword of Demons, or that Rangers are allergic to horses and only ride cows.

How Auto Summarization Works

New Plot Component: Story Summary

As mentioned, there is a new Plot Component called Story Summary where the Auto Summarization feature will store the summary it maintains for your Adventure.

You can add Story Summary to Scenarios and Adventures through the
You can add Story Summary to Scenarios and Adventures through the + Add Plot Component button.
icon
Although Auto Summarization is a paid feature, free players can still add and use this new Plot Component to curate a summary of your Adventure manually.

Like other Plot Components, the Story Summary can be used by our content creators for Scenarios. It could be used to include backstory information for yourself or other players to use (if you publish content), and it will be utilized by the Auto Summarization feature, if enabled in the Adventure.

You can also add
You can also add Story Summary as a Plot Component during Scenario creation.

We’ve also added Story Summary to the Context Viewer so you can track how many tokens of context it’s using for each generation.

See how many tokens your Story Summary takes up through the Context Viewer.
See how many tokens your Story Summary takes up through the Context Viewer.
icon
Remember: Story Summary is part of the total context. A longer Story Summary will take up more tokens and should be used sparingly if you have limited context.

Auto-Updating the Story Summary with Memories

With Auto Summarization enabled, each time a new Memory has been created, it will be appended to the Story Summary Plot Component. Once the Story Summary gets long enough, we’ll pass it to our summarization model and compress the summary. This will ensure that the Story Summary continues to be an information-dense overview of the entire story plot.

This process will continue throughout your adventure, with new memories appended and then re-summarized automatically.

Auto Summarization for Existing Adventures

icon
The Auto Summarization will work best for new Adventures since the summary feature will dynamically update from the beginning of the Adventure.

For existing stories, we’ll summarize the last 8000 tokens of your Adventure when you take your first action with Auto Summarization enabled. Or, if you prefer, you could manually summarize the story, and the AI will take that into account for all future summarizations.

Summaries and Editing

icon
Even with Auto Summarization enabled, you can edit the Story Summary manually.

You may want to edit the automatically created summary to correct any errors or add additional clarifying details. Although the Auto Summarization overwrites your existing summary, your edits ARE sent to the summarization AI, so they should be incorporated in the new summary.

Only edits to your most recent four actions, including changes, undos, redos, and erases, will be considered by the AI for the Auto Summarization. Any changes to previous actions, including the use of Erase to Here, will not update the summary. We will, however, update any corresponding memories stored in the Memory Bank by summarizing the action set that creates that memory. If you make changes earlier in your adventure, and those changes would have an impact on the summary, you’ll need to update the Story Summary manually.

This is due to the limitations and costs of the summarization AI model. Like all models, we are constrained by context size for the summarization. Many adventures would extend far beyond the available context limit, so regenerating a summary based on edits wouldn't be possible in many cases. Making new summarization calls for every historical change could also become very expensive.

How the Memory Bank Works

Embeddings and Vectors

The Memory Bank uses AI technologies that will be new to many of you. To explain how the Memory Bank stores and retrieves relevant memories, you’ll need a basic understanding of embeddings, vectors, and embedding models.

Embeddings represent how similar words and phrases are by mapping them in a multidimensional space. They are created by passing text into specialized embedding language models, which return a vector of numbers as a result.

You can then do simple math to compare how similar different vectors are to each other. For example “water” would be more similar to “liquid” than it would be to “solid”. You can also compare phrases and questions. For example, “Who is Sir Theo?” might match closest with the phrase, “Sir Theo introduces himself to you as the knight who slew the evil dragon of Larion”. These two phrases might also match closely to other passages about Sir Theo or the dragon of Larion. But none of those phrases would likely match very closely to the phrase “Sarah was a forest ranger.”

This lets us build a memory retrieval system. First, we store a bunch of memories in the Memory Bank with both their text and the embedding vector of that text. Then, when we want to find relevant memories, we decide what text we want to use to look up memories (for our system, we use the most recent action). We get the embedding vector for that lookup query, and we compare it against all the vectors in our memory bank and get a relevance score.

A higher score means it’s more similar to the query, and a lower score means it’s less similar. This lets us decide which memories are relevant to the current events in your story and should be included in the context sent to the AI when generating the story.

Now, we’re ready to talk about AI Dungeon’s new Memory Bank Feature.

Embedding Models: Storing and Retrieving Memories

With the Memory Bank, each Memory (an AI-generated summary of your four past actions) is embedded and stored. As you continue to take more actions, your Memory Bank starts to fill with more memories.

When you start a new story, your Memory Bank will be empty. As you take actions, and memories are created, they will begin to fill your available memory slots. Initially, no memories will be used since your entire adventure history will fit in the context. Once your story has reached the point where it can no longer fit your whole adventure into the context window, we start to retrieve memories from the Memory Bank. We do this by using an embedding model to rank all of your memories by relevance to your current story.

You can see your Memory Bank through the Context Viewer. Here, the Memory Bank is starting to fill up, and memories are being used as the full Adventure no longer fits within the context window.
You can see your Memory Bank through the Context Viewer. Here, the Memory Bank is starting to fill up, and memories are being used as the full Adventure no longer fits within the context window.

Then, we take the most relevant memories and include them in the context being sent to the AI for the next action of the story. For example, if you are just returning to the town of Castlebrook, the AI will find all the memories related to Castlebrook, remember what happened the last time you were here, and include the most relevant in the context. These are called “Used Memories.”

Use the
Use the Explore Memories button in the Context Viewer to see your memories. Then use the Timeline or Relevance tabs for different views of your Used and Stored Memories.

Before including a Memory in the context, we also check to see whether the Memory is included in its full text within the Story Summary. This check prevents the text of a Memory from appearing twice in the context.

The Memory Bank will be allocated a portion of the context window, similar to how we allocate space to Plot Essentials (formerly called Memory), Author’s Note, and Story Cards. Based on the context space available, we’ll include as many of the top memories as will fit from your Memory Bank.

Once your Memory Bank has been filled and a new memory has been created, we remove the least used memories to make room for the new addition. These removed memories are called “Forgotten Memories”. Just like with human memory, very old memories might stay in the Memory Bank forever if they have been used frequently.

Context Viewer showing the state where your Memory Bank is full and memories are being utilized, but some are being forgotten to make room for new ones.
Context Viewer showing the state where your Memory Bank is full and memories are being utilized, but some are being forgotten to make room for new ones.

The larger your Memory Bank, the more room you have to store memories that could be used in your story, increasing the accuracy of the AI storyteller.

As you play, the AI will continually curate the most important and relevant memories from your story and intelligently include them in the context being sent to the AI when they are relevant, improving the overall experience.

How to Enable the Memory System

Opt-in Experimental Feature

The Memory System could be one of the most foundational changes to AI Dungeon in recent history. Although we’ve tested it thoroughly internally and with our Alpha testers, we anticipate that as you all start playing with it and give us feedback, we may need to adjust parts of the experience. There could also be unintended behaviors we haven’t encountered yet, or edge cases we didn’t consider. The design might need adjustments to be clearer or more helpful to you.

To avoid any unintended player frustration, we’re launching this first into Beta and then into Production as an opt-in Experimental feature.

icon
Both the Memory Bank and Auto Summarization are toggled OFF by default, so make sure to toggle them ON under the game screen settings sidebar by going to GameplayAI ModelsMemory System.

Once these features have been enabled in one Adventure, they’ll be enabled for every Adventure until you toggle them off again.

Make sure to toggle ON the Memory Bank and Auto Summarization settings under the Memory System section before playing.
Make sure to toggle ON the Memory Bank and Auto Summarization settings under the Memory System section before playing.
icon
Note: It may take a few turns for the Story Summary to show up as a Plot Component once Auto Summarization has been enabled, and it may take even longer for memories to start being stored in or used from the Memory Bank.

How Your Membership Tier Affects the Memory System

All subscribers have access to the Auto Summarization feature. For the Memory Bank, each tier has a set number of memories that can be stored:

Membership Tier
Memory Bank
Adventurer
25
Champion
50
Legend
100
Mythic
200

Why Isn’t the Memory System Available to Free Players?

Because the Auto Summarization feature requires another AI call, it’s currently cost-prohibitive to offer the Memory System to free players. Our hope is that we can offer the Memory System to everyone in the future. We’ve done this before with other features that were Premium only, then made available to all players over time. Examples include unlimited AI calls, image generation, multiple AI model options, advanced settings (now Model Settings), and even Premium AI (with promo actions).

Key Differences from the Heroes Memory System

Those familiar with the Heroes memory system will see similarities with this new Memory System for AI Dungeon. The work done on Heroes directly inspired and informed the new Memory System. There are some important differences and adaptations we made to implement it for AI Dungeon.

The Heroes experience is a much more traditional RPG experience. We track important stats like health, quests, inventory, levels, and player characteristics, which are stored in a “game state.” We didn't bring this part over since AI Dungeon is a collaborative storytelling experience.

We also made some adjustments to account for the different gameplay in AI Dungeon. We know you all value editing, a concept that isn’t as prevalent in Heroes, and supporting editing with the AI Dungeon Memory System required some adaptations.

Memory System versus Plot Components

If you’re one of our more experienced players, you know that through careful, manual editing of Story Cards and Plot Components (like Plot Essentials or Author’s Note), you can make sure important story details are still being included in the context.

This is still important, but not as crucial as it has been in the past. Now, these components can contribute to making the Memory System even better at its job by providing it with enough relevant information to accurately create summaries and store memories.

As we mentioned above, the Auto Summarization feature of the Memory System is supported by the new Story Summary Plot Component, which can be added and edited just like other elements in this category.

Comparison Chart

Plot Component/Feature
How to Use It
AI Instructions
Give the AI a set of instructions about how to generate responses.
Story Summary
Give the AI a summary of your story to help it remember broader plot details. Works with the new Memory System.
Plot Essentials
Give the AI some key details about your story that it should always remember.
Author’s Note
Give the AI short guidance about your story’s theme and setting.
Third Person
Change “You” in Do and Say actions to your character’s name. Mostly recommended for Multiplayer games.
Story Cards
Give the AI some broader world-building details that are only included when keywords are used.
icon
Information in AI Instructions, Story Summary, Plot Essentials, and Author’s Note will always be included in the context. Story Cards are added to the context when keywords are triggered. You can see how many tokens each element takes up through the Context Viewer. Ultimately, there aren’t strict guidelines about what information needs to be in each Plot Component. We highly recommend playing around with all of them to see what works best for you!

Read even more about the Memory System in AI Dungeon →

icon
Remember: you can always get more information on any AI Dungeon subject by asking in our official Discord server.
icon
image

© Latitude 2023