# Long Term Memory

Long-Term Memory (LTM) enables the persistent storage of conversational history with NPCs, allowing players to seamlessly continue interactions from where they previously left off, even across multiple sessions. This feature significantly enhances the realism of NPCs, aligning with our goal of creating more immersive and lifelike characters within your game.

{% hint style="info" %}
Prerequisite: Have a project with Convai SDK version 3.1.0 or higher. If you don't have it, check this documentation&#x20;

[setting-up-unity-plugin](https://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin/setting-up-unity-plugin "mention")
{% endhint %}

### Steps to get LTM working

1. Select your Convai Character&#x20;

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FrHtaOfEpXu3ysWD8sTB0%2FAddComponent.png?alt=media&#x26;token=47cea28b-e84b-431a-aa6b-e83a8474b6f3" alt=""><figcaption></figcaption></figure>
2. Add the Long-Term Memory Component onto your character

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FxdkYI2iRn9bx1YI4RxeX%2FAdding%20LTM.png?alt=media&#x26;token=bfefc477-c25a-4536-b828-7e465aafc38d" alt=""><figcaption></figcaption></figure>
3. Make sure that Long Term Memory is enabled for that character&#x20;

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FqD1nUtoQmcicJj6gPyNw%2FLTM%20Enabled.png?alt=media&#x26;token=ec6de233-f4c1-42e6-ae0a-c4810aeff12b" alt=""><figcaption></figcaption></figure>

Long Term Memory should now be working for your character.

### Components of the LTM System

#### Convai Long Term Memory Component

This component will enable or disable LTM right from the unity editor

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6xYd1ICNAiYweKBLLHWT%2FLTM%20Disabled.png?alt=media&#x26;token=0bc592ff-e524-46ab-8731-79b4e4898f10" alt=""><figcaption></figcaption></figure>

Toggling Long Term Memory

1\) Click the button provided in the component

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfVZPUWzK2186MwADjjtM%2FLTM%20Disabled%20Button%20Highlighted.png?alt=media&#x26;token=03d6bb41-819e-409c-96b0-469e920f060b" alt=""><figcaption></figcaption></figure>

2\) It will take some time to update, and after that the new status of the LTM should be visible in the inspector.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FniiudjNLSDVWXpwVsxlF%2FLTM%20Updating%20Status.png?alt=media&#x26;token=1c7a8096-7f8d-4f4a-9d7d-3d190cabd29e" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Since enabling or disabling Long-Term Memory (LTM) for a character is a global action that impacts all players interacting with that character, we strongly recommend against toggling the LTM status at runtime. This functionality should be managed exclusively by developers or designers through the editor to ensure consistent gameplay experiences.
{% endhint %}

### Troubleshooting

{% hint style="danger" %}
Grpc.Core.RpcException: Status(StatusCode=InvalidArgument, Detail="Cannot find speaker with id: 99fbef96-5ecb-11ef-93ce-42010a7be011.")
{% endhint %}

If you encounter this error, ensure that the **SpeakerID** was created using the same API key currently in use. If you're uncertain about the API key used, you can reset the **SpeakerID** and **PlayerName** by accessing the `ConvaiPlayerDataSO` file located in `Assets > Convai > Resources`, allowing you to start the process anew.

### Management of Speaker ID(s)

It is essential for developers to efficiently manage the Speaker ID(s) generated using their API key, as the number of IDs that can be created is limited and dependent on the subscription tier. Proper management ensures optimal usage of resources and prevents potential disruptions in the application's functionality.

#### Speaker ID limit per API key are as follows

| Tier                         | Limit                   |
| ---------------------------- | ----------------------- |
| Personal                     | 1                       |
| Gamer / Indie / Professional | 5                       |
| Partner / Enterprise         | 100 (Can be Customized) |

You can view all the Speaker ID(s) associated with a specific API key by accessing the **Convai Window** within your Unity project. This feature provides a comprehensive list of IDs, allowing for easier management and monitoring.

{% hint style="danger" %}
Ensure that the API key is correctly entered; otherwise, the feature will not function as expected. Accurate API key input is critical for accessing and managing Speaker ID(s) through the Convai Window in Unity.
{% endhint %}

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fnc2iy1JbHWSckNM6CXTc%2FUntitled.png?alt=media&#x26;token=9a8328be-1830-4d4b-b0ed-5a282c686a9a" alt=""><figcaption></figcaption></figure>

Head over to Long Term Memory Section

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FZaIoupylUGK2BDIavUen%2FUntitled.png?alt=media&#x26;token=754058c0-0cfd-45bd-a9ce-2aaf9d60a8ec" alt=""><figcaption></figcaption></figure>

If the message "No Speaker ID(s) Found" appears, there is no need to proceed with this guide. However, if a Speaker ID list is displayed, it's advisable to delete any ID(s) that are no longer in use or needed to optimize your available resources.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FN4kfR5PD4wN9vUaQCUK1%2FUntitled.png?alt=media&#x26;token=a450c610-11dc-45da-aa82-a4047cd975db" alt=""><figcaption></figcaption></figure>
