Memory management

更新时间:
复制 MD 格式

One of the core challenges for agent applications is their forgetfulness. They cannot remember historical interactions, user preferences, or long-term context. PolarDB memory management is a managed service that provides long-term memory for AI applications. It stores key information in a PolarDB cluster and uses intelligent retrieval and dynamic context injection. This lets your AI applications remember everything to build smarter, more personalized user experiences.

Note

If you have any questions about PolarDB memory management, search for the group number in DingTalk to join our support group. You can directly at sign (@) our experts in the group and ask your questions. DingTalk group number: 34560007316.

How it works

PolarDB memory management creates an isolated Schema in your PolarDB for PostgreSQL cluster to store and manage the memory of your AI applications. When your application interacts with a user, it sends the conversation content to the memory management service. The service uses a large language model (LLM) to automatically extract, summarize, and structure information. It then stores the processed memory in PolarDB. In subsequent interactions, the application can retrieve relevant memories from the service at any time. It injects these memories as context into new prompts. This allows the LLM to provide more accurate and consistent responses.

Core concepts

  • Memory Project: An independent memory management unit that corresponds to one of your AI applications. At the database level, each project corresponds to an independent Schema to ensure data isolation.

  • Long-term Memory: Information that is persistently stored in PolarDB. It saves knowledge across different stages and records the following:

    • Factual memory: User preferences, account details, and domain-specific facts.

    • Episodic memory: Summaries of past interactions or completed tasks.

    • Semantic memory: Relationships between concepts, which allows the agent to reason about them later.

  • AI Agent: Your AI application that integrates memory management capabilities, such as an intelligent chatbot or a personal assistant.

Scope

Before you use PolarDB memory management, make sure your environment meets the following conditions. This section helps you quickly determine if the feature is suitable for you, and is not a preparation guide.

  • Cluster type: Centralized PolarDB for PostgreSQL clusters. PolarDB for PostgreSQL Distributed Edition clusters are not supported.

  • Database engine: PostgreSQL 16.

Billing

  • Component fees: PolarDB memory management charges fees for resource components. The fees are calculated based on the component specifications (CPU and memory) you select and the subscription duration.

    Component pricing

    The Chinese mainland

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    11

    0.02

    polar.app.g2.small

    1-core 2 GB

    18

    0.04

    polar.app.g2.medium

    2-core 4 GB

    250

    0.52

    polar.app.g4.medium

    2-core 8 GB

    270

    0.56

    polar.app.g8.medium

    2-core 16 GB

    330

    0.6875

    polar.app.g2.large

    4-core 8 GB

    475

    0.99

    polar.app.g4.large

    4-core 16 GB

    630

    1.31

    polar.app.g8.large
    4-core 32 GB

    660

    1.375

    polar.app.g2.xlarge

    8-core 16 GB

    1,000

    2.08

    polar.app.g4.xlarge

    8-core 32 GB

    1,240

    2.58

    polar.app.g8.xlarge
    8-core 64 GB

    1,320

    2.75

    polar.app.g2.2xlarge

    16-core 32 GB

    2,000

    4.17

    polar.app.g4.2xlarge

    16-core 64 GB

    2,400

    5.00

    polar.app.g8.2xlarge
    16-core 128 GB

    2,640

    5.5

    polar.app.g2.4xlarge
    32-core 64 GB

    4,000

    8.32

    polar.app.g4.4xlarge
    32-core 128 GB

    4,320

    8.96

    polar.app.g8.4xlarge
    32-core 256 GB

    5,280

    11

    China (Hong Kong)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1 core 1 GB

    17.6

    0.032

    polar.app.g2.small

    1 core 2 GB

    28.8

    0.064

    polar.app.g2.medium

    2 core 4 GB

    400

    0.832

    polar.app.g4.medium

    2 core 8 GB

    432

    0.896

    polar.app.g8.medium
    2 core 16 GB

    528

    1.100

    polar.app.g2.large

    4 core 8 GB

    760

    1.584

    polar.app.g4.large

    4 core 16 GB

    1,008

    2.096

    polar.app.g8.large
    4 core 32 GB

    1,056

    2.200

    polar.app.g2.xlarge

    8 core 16 GB

    1,600

    3.330

    polar.app.g4.xlarge

    8 core 32 GB

    1,984

    4.130

    polar.app.g8.xlarge
    8 core 64 GB

    2,112

    4.400

    polar.app.g2.2xlarge

    16 core 32 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    16 core 64 GB

    3,840

    8.000

    polar.app.g8.2xlarge
    16 core 128 GB

    4,224

    8.800

    Japan (Tokyo)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1 core 1 GB

    17.6

    0.032

    polar.app.g2.small

    1 core 2 GB

    28.8

    0.064

    polar.app.g2.medium

    2 core 4 GB

    400

    0.832

    polar.app.g4.medium

    2 core 8 GB

    432

    0.896

    polar.app.g8.medium
    2 core 16 GB

    528

    1.100

    polar.app.g2.large

    4 core 8 GB

    760

    1.584

    polar.app.g4.large

    4 core 16 GB

    1,008

    2.096

    polar.app.g8.large
    4 core 32 GB

    1,056

    2.200

    polar.app.g2.xlarge

    8 core 16 GB

    1,600

    3.330

    polar.app.g4.xlarge

    8 core 32 GB

    1,984

    4.130

    polar.app.g8.xlarge
    8 core 64 GB

    2,112

    4.400

    polar.app.g2.2xlarge

    16 core 32 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    16 core 64 GB

    3,840

    8.000

    polar.app.g8.2xlarge
    16 core 128 GB

    4,224

    8.800

    South Korea

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1 core 1 GB

    17.6

    0.032

    polar.app.g2.small

    1 core 2 GB

    28.8

    0.064

    polar.app.g2.medium

    2 core 4 GB

    400

    0.832

    polar.app.g4.medium

    2 core 8 GB

    432

    0.896

    polar.app.g8.medium
    2 core 16 GB

    528

    1.100

    polar.app.g2.large

    4 core 8 GB

    760

    1.584

    polar.app.g4.large

    4 core 16 GB

    1,008

    2.096

    polar.app.g8.large
    4 core 32 GB

    1,056

    2.200

    polar.app.g2.xlarge

    8 core 16 GB

    1,600

    3.330

    polar.app.g4.xlarge

    8 core 32 GB

    1,984

    4.130

    polar.app.g8.xlarge
    8 core 64 GB

    2,112

    4.400

    polar.app.g2.2xlarge

    16 core 32 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    16 core 64 GB

    3,840

    8.000

    polar.app.g8.2xlarge
    16 core 128 GB

    4,224

    8.800

    Singapore

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1 Core 1 GB

    17.6

    0.032

    polar.app.g2.small

    1 core 2 GB

    28.8

    0.064

    polar.app.g2.medium

    2 cores, 4 GB

    400

    0.832

    polar.app.g4.medium

    2 cores, 8 GB

    432

    0.896

    polar.app.g8.medium
    2 cores, 16 GB

    528

    1.100

    polar.app.g2.large

    4 cores, 8 GB

    760

    1.584

    polar.app.g4.large

    4 cores, 16 GB

    1,008

    2.096

    polar.app.g8.large
    4 cores, 32 GB

    1,056

    2.200

    polar.app.g2.xlarge

    8 Cores 16 GB

    1,600

    3.330

    polar.app.g4.xlarge

    8 cores, 32 GB

    1,984

    4.130

    polar.app.g8.xlarge
    8 cores, 64 GB

    2,112

    4.400

    polar.app.g2.2xlarge

    16 cores, 32 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    16 cores, 64 GB

    3,840

    8.000

    polar.app.g8.2xlarge
    16 cores 128 GB

    4,224

    8,800

    polar.app.g2.4xlarge
    32 cores 64 GB

    6,400

    13.310

    polar.app.g4.4xlarge
    32 cores, 128 GB

    6,912

    14.340

    polar.app.g8.4xlarge
    32 cores 256 GB

    8,448

    17.600

    Malaysia (Kuala Lumpur)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1 core 1 GB

    17.6

    0.032

    polar.app.g2.small

    1 core 2 GB

    28.8

    0.064

    polar.app.g2.medium

    2 core 4 GB

    400

    0.832

    polar.app.g4.medium

    2 core 8 GB

    432

    0.896

    polar.app.g8.medium
    2 core 16 GB

    528

    1.100

    polar.app.g2.large

    4 core 8 GB

    760

    1.584

    polar.app.g4.large

    4 core 16 GB

    1,008

    2.096

    polar.app.g8.large
    4 core 32 GB

    1,056

    2.200

    polar.app.g2.xlarge

    8 core 16 GB

    1,600

    3.330

    polar.app.g4.xlarge

    8 core 32 GB

    1,984

    4.130

    polar.app.g8.xlarge
    8 core 64 GB

    2,112

    4.400

    polar.app.g2.2xlarge

    16 core 32 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    16 core 64 GB

    3,840

    8.000

    polar.app.g8.2xlarge
    16 core 128 GB

    4,224

    8.800

    Indonesia (Jakarta)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    15.4

    0.028

    polar.app.g2.small

    1-core 2 GB

    25.2

    0.056

    polar.app.g2.medium

    2-core 4 GB

    350

    0.728

    polar.app.g4.medium

    2-core 8 GB

    378

    0.784

    polar.app.g8.medium
    2-core 16 GB

    462

    0.9625

    polar.app.g2.large

    4-core 8 GB

    665

    1.386

    polar.app.g4.large

    4-core 16 GB

    882

    1.834

    polar.app.g8.large
    4-core 32 GB

    924

    1.925

    polar.app.g2.xlarge

    8-core 16 GB

    1,400

    2.910

    polar.app.g4.xlarge

    8-core 32 GB

    1,736

    3.610

    polar.app.g8.xlarge
    8-core 64 GB

    1,848

    3.850

    polar.app.g2.2xlarge

    16-core 32 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    16-core 64 GB

    3,360

    7.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,696

    7.700

    polar.app.g2.4xlarge
    32-core 64 GB

    5,600

    11.650

    polar.app.g4.4xlarge
    32-core 128 GB

    6,048

    12.540

    polar.app.g8.4xlarge
    32-core 256 GB

    7,392

    15.400

    Philippines

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    15.4

    0.028

    polar.app.g2.small

    1-core 2 GB

    25.2

    0.056

    polar.app.g2.medium

    2-core 4 GB

    350

    0.728

    polar.app.g4.medium

    2-core 8 GB

    378

    0.784

    polar.app.g8.medium
    2-core 16 GB

    462

    0.9625

    polar.app.g2.large

    4-core 8 GB

    665

    1.386

    polar.app.g4.large

    4-core 16 GB

    882

    1.834

    polar.app.g8.large
    4-core 32 GB

    924

    1.925

    polar.app.g2.xlarge

    8-core 16 GB

    1,400

    2.910

    polar.app.g4.xlarge

    8-core 32 GB

    1,736

    3.610

    polar.app.g8.xlarge
    8-core 64 GB

    1,848

    3.850

    polar.app.g2.2xlarge

    16-core 32 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    16-core 64 GB

    3,360

    7.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,696

    7.700

    Thailand (Bangkok)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    15.4

    0.028

    polar.app.g2.small

    1-core 2 GB

    25.2

    0.056

    polar.app.g2.medium

    2-core 4 GB

    350

    0.728

    polar.app.g4.medium

    2-core 8 GB

    378

    0.784

    polar.app.g8.medium
    2-core 16 GB

    462

    0.9625

    polar.app.g2.large

    4-core 8 GB

    665

    1.386

    polar.app.g4.large

    4-core 16 GB

    882

    1.834

    polar.app.g8.large
    4-core 32 GB

    924

    1.925

    polar.app.g2.xlarge

    8-core 16 GB

    1,400

    2.910

    polar.app.g4.xlarge

    8-core 32 GB

    1,736

    3.610

    polar.app.g8.xlarge
    8-core 64 GB

    1,848

    3.850

    polar.app.g2.2xlarge

    16-core 32 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    16-core 64 GB

    3,360

    7.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,696

    7.700

    Germany (Frankfurt)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    15.4

    0.028

    polar.app.g2.small

    1-core 2 GB

    25.2

    0.056

    polar.app.g2.medium

    2-core 4 GB

    350

    0.728

    polar.app.g4.medium

    2-core 8 GB

    378

    0.784

    polar.app.g8.medium
    2-core 16 GB

    462

    0.9625

    polar.app.g2.large

    4-core 8 GB

    665

    1.386

    polar.app.g4.large

    4-core 16 GB

    882

    1.834

    polar.app.g8.large
    4-core 32 GB

    924

    1.925

    polar.app.g2.xlarge

    8-core 16 GB

    1,400

    2.910

    polar.app.g4.xlarge

    8-core 32 GB

    1,736

    3.610

    polar.app.g8.xlarge
    8-core 64 GB

    1,848

    3.850

    polar.app.g2.2xlarge

    16-core 32 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    16-core 64 GB

    3,360

    7.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,696

    7.700

    UK (London)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    15.4

    0.028

    polar.app.g2.small

    1-core 2 GB

    25.2

    0.056

    polar.app.g2.medium

    2-core 4 GB

    350

    0.728

    polar.app.g4.medium

    2-core 8 GB

    378

    0.784

    polar.app.g8.medium
    2-core 16 GB

    462

    0.9625

    polar.app.g2.large

    4-core 8 GB

    665

    1.386

    polar.app.g4.large

    4-core 16 GB

    882

    1.834

    polar.app.g8.large
    4-core 32 GB

    924

    1.925

    polar.app.g2.xlarge

    8-core 16 GB

    1,400

    2.910

    polar.app.g4.xlarge

    8-core 32 GB

    1,736

    3.610

    polar.app.g8.xlarge
    8-core 64 GB

    1,848

    3.850

    polar.app.g2.2xlarge

    16-core 32 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    16-core 64 GB

    3,360

    7.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,696

    7.700

    US (Silicon Valley)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    13.2

    0.024

    polar.app.g2.small

    1-core 2 GB

    21.6

    0.048

    polar.app.g2.medium

    2-core 4 GB

    300

    0.624

    polar.app.g4.medium

    2-core 8 GB

    324

    0.672

    polar.app.g8.medium
    2-core 16 GB

    396

    0.825

    polar.app.g2.large

    4-core 8 GB

    570

    1.188

    polar.app.g4.large

    4-core 16 GB

    756

    1.572

    polar.app.g8.large
    4-core 32 GB

    792

    1.650

    polar.app.g2.xlarge

    8-core 16 GB

    1,200

    2.500

    polar.app.g4.xlarge

    8-core 32 GB

    1,488

    3.100

    polar.app.g8.xlarge
    8-core 64 GB

    1,584

    3.300

    polar.app.g2.2xlarge

    16 cores, 32 GB

    2,400

    5.000

    polar.app.g4.2xlarge

    16 cores, 64 GB

    2,880

    6.000

    polar.app.g8.2xlarge
    16 cores, 128 GB

    3,168

    6.600

    polar.app.g2.4xlarge
    32 cores, 64 GB

    4,800

    9.980

    polar.app.g4.4xlarge
    32 cores 128 GB

    5,184

    10.750

    polar.app.g8.4xlarge
    32 vCPUs, 256 GB

    6,336

    13.200

    US (Virginia)

    Node specification code

    CPU and memory

    Subscription (CNY/month)

    Pay-as-you-go (CNY/hour)

    polar.app.g1.tiny

    1-core 1 GB

    13.2

    0.024

    polar.app.g2.small

    1-core 2 GB

    21.6

    0.048

    polar.app.g2.medium

    2-core 4 GB

    300

    0.624

    polar.app.g4.medium

    2-core 8 GB

    324

    0.672

    polar.app.g8.medium
    2-core 16 GB

    396

    0.825

    polar.app.g2.large

    4-core 8 GB

    570

    1.188

    polar.app.g4.large

    4-core 16 GB

    756

    1.572

    polar.app.g8.large
    4-core 32 GB

    792

    1.650

    polar.app.g2.xlarge

    8-core 16 GB

    1,200

    2.500

    polar.app.g4.xlarge

    8-core 32 GB

    1,488

    3.100

    polar.app.g8.xlarge
    8-core 64 GB

    1,584

    3.300

    polar.app.g2.2xlarge

    16-core 32 GB

    2,400

    5.000

    polar.app.g4.2xlarge

    16-core 64 GB

    2,880

    6.000

    polar.app.g8.2xlarge
    16-core 128 GB

    3,168

    6.600

  • Storage fees: Data and files generated by PolarDB memory management are stored in the storage space of the PolarDB for PostgreSQL cluster.

  • Model fees: The models used in PolarDB memory management, such as qwen3-max, text-embedding-v4, or qwen3-rerank, are all models from Alibaba Cloud Model Studio. For detailed billing rules, see Model invocation billing.

  • Traffic and bandwidth: No fees are charged.

Prepare the cluster environment

Before you create a memory project, you must prepare a PolarDB for PostgreSQL cluster that meets the requirements and create a dedicated database for it.

  1. Prepare a cluster: Use an existing cluster or purchase a new PostgreSQL 16 cluster based on your business needs.

  2. Create a privileged account: Prepare a privileged account to create the Memory Management module. If you already have a privileged account, you can skip this step.

  3. Create a database: Create a logical database to store data related to memory projects.

  4. Configure the IP address whitelist: Configure the cluster whitelist to ensure that your application can securely connect to the database.

Quick start

Step 1: Create a memory management project

  1. Go to the PolarDB console. Click Clusters in the navigation pane on the left. Find a destination cluster that meets the requirements specified in Scope, and then open its details page. In the navigation pane on the left, select AI Capabilities > AI Applications and click Create AI Application.

  2. On the purchase page, select the appropriate configuration based on your needs:

    Configuration item

    Description

    Billing Method

    • Subscription: An upfront payment method. When you create an application, you select resources with defined specifications and pay for them in advance. The longer the subscription duration, the larger the discount. This method is suitable for scenarios with stable, long-term business requirements.

    • Pay-as-you-go: A pay-as-you-go billing method. When you create an application, you select resources with defined specifications but do not need to pay in advance. You are billed based on the actual usage duration. This method is suitable for scenarios with flexible business requirements.

    Engine

    Fixed as PolarDB.

    Region

    Select the geographic location where the application is deployed.

    Note
    • You cannot change the region after the application is purchased.

    • The application must be in the same region as the PolarDB for PostgreSQL cluster. Therefore, select the same region as the PolarDB for PostgreSQL cluster.

    • Create the application in the same region as the ECS instance you want to connect to. Otherwise, they cannot communicate over the internal network (private network) and must use the public network, which prevents optimal performance.

    Architecture

    Select AI Application.

    Ecosystem

    Automatically filled with the database ecosystem of the source PolarDB cluster. You do not need to enter it manually.

    Source PolarDB Cluster

    Select the PolarDB cluster for which you want to create the application.

    Version

    Automatically filled with the database version of the source PolarDB cluster. You do not need to enter it manually.

    AI Application

    Select Memory Management.

    Memory Engine

    Select mem0.

    Component Set

    An AI application can contain multiple resource components. We recommend selecting at least two components to support high availability for memory management.

    AI Application Name

    Enter a custom application name.

    Note

    The name cannot start with http:// or https:// and must be 2 to 256 characters long.

    Network Type

    Fixed as Virtual Private Cloud (VPC).

    VPC Network

    Automatically filled with the VPC of the source PolarDB cluster. You do not need to enter it manually.

    Zone and vSwitch

    Configure the vSwitch for your VPC network. We recommend selecting the same vSwitch as the primary zone of your PolarDB for PostgreSQL cluster to achieve optimal network performance.

    If your existing vSwitches do not meet your requirements, you can create a new one by clicking Create vSwitch.

    Project Name

    An independent memory management unit that corresponds to one of your AI applications. At the database level, each project corresponds to an independent Schema to ensure data isolation.

    Database Name

    Enter the database name for the project.

    LLM Model

    A large language model. You cannot change this after selection. Supported models include the following:

    • qwen3-max

    • qwen-plus

    Embedding Model

    A text-to-vector model. You cannot change this after selection. Supported versions include the following:

    • text-embedding-v4

    • text-embedding-v3

    ReRank Model

    A model used in the memory ReRanker process. You cannot change this after selection. Supported versions include the following:

    • qwen3-rerank

    • gte-rerank-v2

    Database Account

    Enter the privileged account for the PolarDB for PostgreSQL cluster.

    Account Password

    Enter the password for the privileged account.

    Security Group

    Configure the security group for the application.

    Quantity

    Select the number of applications to purchase.

    Note
    • You can purchase only one AI application of the same type per PolarDB for PostgreSQL cluster.

    • This setting is available only when the Billing Method is set to Subscription.

    Subscription Duration

    Select the subscription duration for the application.

    Note

    This setting is available only when the Billing Method is set to Subscription.

    Auto-renewal

    Configure whether to enable auto-renewal. To avoid service interruptions due to missed renewals, we recommend enabling auto-renewal.

    Note

    This setting is available only when the Billing Method is set to Subscription.

  3. After successful purchase, return to the AI Applications page of the cluster to view the newly created application.

    Note

    The system takes 3 to 5 minutes to create the application. Please wait patiently.

Step 2: Get the endpoint and access credentials

  • Retrieve the endpoint: On the AI Applications page, click your Application ID to go to the application details page. In the Basic Information tab, find the Topology section and view the private endpoint.

    Note
    • You must apply for a public endpoint separately. Click the Apply button to apply.

    • A public endpoint provides only an IP address and port, not a domain name. If you need a domain name, bind one yourself.

  • Retrieve configuration information: On the Mem0 Memory Store list page, click your Application ID/Name to go to the details page. In the Configure tab, view the related configuration information.image

Step 3: Configure the whitelist

On the AI Applications page, click your Application ID to go to the application details page. In the Whitelist tab, click Add Whitelist, Select Security Groups, or Configure an existing whitelist group.

Note
  • The application whitelist and cluster whitelist are independent. You must configure them separately.

  • If your ECS instance needs to access the application, go to the ECS Instance Details page to retrieve the ECS instance's IP address and add it to the IP whitelist.

    • If your ECS instance and application are in the same VPC, you can enter the private IP address of the ECS or its VPC CIDR block.

    • If your ECS instance and application are in different VPCs, you can add the ECS public IP address or its security group to the whitelist.

  • If your local server, computer, or other cloud servers need to access the application, add their public IP addresses to the IP whitelist.

image

Step 4: (Optional) Configure parameters and custom extraction policies

Parameter description

You can adjust the following parameters on the Configure tab of memory management to optimize service performance and results.

Important

Changing some parameters triggers a service restart. Perform these changes during off-peak hours.

  • secret.access.apikey: Your access credential.

  • memserver.POLAR_GRAPH_EMBEDDING_THRESHOLD: The threshold used when extracting memories to determine whether to create a new graph node. When adding relationships to an existing graph, the service compares vector similarity between extracted memories and existing nodes. If the similarity is greater than the threshold, the service uses the existing node. If the similarity is less than the threshold, the service creates a new node. The default threshold is 0.7.

  • memserver.POLAR_GRAPH_MAXCONN: The maximum number of concurrent connections for the memory service.

Custom extraction policies (Prompts)

Memory management uses built-in Prompt templates (extraction policies) to guide the LLM on how to extract and summarize memories from conversations. You can customize these Prompts to fit specific business scenarios.

Policy types

  • Only session summarization and semantic memory policies are supported.

  • For each policy type (such as session summarization), only one policy can be active at a time.

Operation Instructions

  1. Manage these policies on the Extraction Policies tab of memory management.image

  2. Edit an existing policy to fine-tune it, or click Add Policy. Then click the Modify Policy button to activate the new policy.image

Step 5: API examples

Add memories

curl -X POST http://my-endpoint:8080/v1/memories \
  -H "Content-Type: application/json" \
  -H "Authorization: Token <your-api-key>" \
  -d '{
        "messages": [
            {
              "role": "user",
              "content": "I like spicy food, especially Sichuan cuisine."
            },
            {
              "role": "assistant",
              "content": "Got it, I've noted your taste preferences."
            }
        ],
        "user_id": "user_002",
        "agent_id": "food-assistant",
        "run_id": "user_002_run_id",
        "metadata": {
            "additionalProp1": {}
        }
    }'

Expected response:

{
    "results": [
        {
            "id": "32155c0a-xxxx-xxxx-xxxx-804e119bb965",
            "event": "ADD",
            "data": {
                "memory": "likes spicy food"
            }
        },
        {
            "id": "9188deee-xxxx-xxxx-xxxx-3073ef826b42",
            "event": "ADD",
            "data": {
                "memory": "especially likes Sichuan cuisine"
            }
        }
    ]
}

Search memories

curl -X POST http://my-endpoint:8080/v2/memories/search \
  -H "Content-Type: application/json" \
  -H "Authorization: Token <your-api-key>" \
  -d '{
        "query": "What kind of food do I like?",
        "agent_id": "food-assistant",
        "filters": {
            "user_id": "user_002",
            "run_id": "user_002_run_id",
            "additionalProp1": {}
        }
    }'

Expected response:

{
    "results": [
        {
            "id": "9188deee-xxxx-xxxx-xxxx-3073ef826b42",
            "memory": "especially likes Sichuan cuisine",
            "hash": "a826fbf3c3844024633e84d04875ee45",
            "metadata": {
                "additionalProp1": {

                }
            },
            "score": 0.681654033365126,
            "created_at": "2026-03-05T23:59:36.038217-08:00",
            "updated_at": null,
            "user_id": "user_002",
            "agent_id": "food-assistant",
            "run_id": "user_002_run_id"
        },
        {
            "id": "32155c0a-xxxx-xxxx-xxxx-804e119bb965",
            "memory": "likes spicy food",
            "hash": "b2882aaf96654a9e16f45f363022010a",
            "metadata": {
                "additionalProp1": {

                }
            },
            "score": 0.582298149788604,
            "created_at": "2026-03-05T23:59:36.023417-08:00",
            "updated_at": null,
            "user_id": "user_002",
            "agent_id": "food-assistant",
            "run_id": "user_002_run_id"
        }
    ]
}

Get memories

  curl -X POST http://my-endpoint:8080/v2/memories \
  -H "Content-Type: application/json" \
  -H "Authorization: Token <your-api-key>" \
  -d '{
        "filters": {
            "user_id": "user_002",
            "run_id": "user_002_run_id",
            "agent_id": "food-assistant"
        }
    }'

Expected response:

{
    "results": [
        {
            "id": "39b06e97-xxxx-xxx-xxxx-4223818bc04e",
            "memory": "likes spicy food",
            "hash": "b2882aaf96654a9e16f45f363022010a",
            "metadata": {
                "additionalProp1": {

                }
            },
            "created_at": "2026-03-06T00:12:45.109789-08:00",
            "updated_at": null,
            "user_id": "user_002",
            "agent_id": "food-assistant",
            "run_id": "user_002_run_id"
        },
        {
            "id": "482def46-xxxx-xxxx-xxxx-ff4886a1047c",
            "memory": "especially likes Sichuan cuisine",
            "hash": "a826fbf3c3844024633e84d04875ee45",
            "metadata": {
                "additionalProp1": {

                }
            },
            "created_at": "2026-03-06T00:12:45.121585-08:00",
            "updated_at": null,
            "user_id": "user_002",
            "agent_id": "food-assistant",
            "run_id": "user_002_run_id"
        }
    ]
}

Appendix: API reference

PolarDB memory management is a managed service based on the open-source framework mem0 (v1.0.1). You can visit http://<your-endpoint>:8080/docs to view the up-to-date API documentation.image

Request header

Authenticate API requests by including Authorization: Token <your-api-key> in the Request Header.

Request examples

This section provides examples for key APIs.

Create memories

Stores new memories. The service automatically analyzes the content of messages to generate conversation summaries and semantic memories.

  • Request URL: POST /v1/memories

  • Request Body:

    messages array (Required)

    A list of conversation messages in the OpenAI Format.

    Properties

    role String (Required)

    The role of the message sender, such as user or assistant.

    content String (Required)

    The content of the message.

    curl
    curl -X POST http://my-endpoint:8080/v1/memories \
      -H "Content-Type: application/json" \
      -H "Authorization: Token <your-api-key>" \
      -d '{
            "messages": [
                {
                  "role": "user",
                  "content": "I like spicy food, especially Sichuan cuisine."
                },
                {
                  "role": "assistant",
                  "content": "Got it, I have noted your taste preference."
                }
            ],
            "user_id": "user_002",
            "agent_id": "food-assistant",
            "run_id": "user_002_run_id",
            "metadata": {
                "additionalProp1": {}
            }
        }'
    Python
    import requests
    import json
    
    payload = {
        "messages": [
            {"role": "user", "content": "I like spicy food, especially Sichuan cuisine."},
            {"role": "assistant", "content": "Got it, I have noted your taste preference."}
        ],
        "user_id": "user-002",
        "agent_id": "food-assistant",
        "run_id": "user_002_run_id"
    }
    
    response = requests.post(
        "http://<your-endpoint>:8080/v1/memories",
        headers={"Authorization": "Token <your-api-key>", "Content-Type": "application/json"},
        data=json.dumps(payload)
    )
    
    print(response.json())
    

    user_id String (Required)

    A unique identifier for the user.

    agent_id String (Optional)

    A unique identifier for the Agent, used to isolate memories for different applications for the same user.

    run_id String (Optional)

    A unique identifier for a single run or Session.

    metadata Object (Optional)

    Additional metadata to store with the memory.

Search memories

Searches for the most relevant memories based on a query string.

  • Request URL: POST /v2/memories/search

  • Request Body:

    query String (Required)

    The text to search for, such as a new user question.

    curl
    curl -X POST http://my-endpoint:8080/v2/memories/search \
      -H "Content-Type: application/json" \
      -H "Authorization: Token <your-api-key>" \
      -d '{
            "query": "What kind of food do I like?",
            "agent_id": "food-assistant",
            "filters": {
                "user_id": "user_002",
                "run_id": "user_002_run_id",
                "additionalProp1": {}
            }
        }'
    
    Python
    import requests
    import json
    
    payload = {
        "query": "What kind of food do I like?",
        "agent_id": "food-assistant",
        "filters": {
              "user_id": "user_002",                                                                                                                                                                            
              "run_id": "user_002_run_id"                       
          }
    }
    
    response = requests.post(
        "http://<your-endpoint>:8080/v2/memories/search",
        headers={"Authorization": "Token <your-api-key>", "Content-Type": "application/json"},
        data=json.dumps(payload)
    )
    
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
    

    agent_id String (Optional)

    Restricts the search to the specified Agent.

    filters Object (Required)

    Filters based on metadata.

    Properties

    user_id String (Required)

    A unique identifier for the user.

    run_id String (Optional)

    Restricts the search to a specific Session.

Get memories

Retrieves all raw memories within a specified scope.

  • Request URL: POST /v2/memories

  • Request Body:

    filters Object (Required)

    Filters based on metadata.

    Properties

    user_id String (Required)

    A unique identifier for the user.

    agent_id String (Optional)

    Restricts retrieval to memories from a specific Agent.

    run_id String (Optional)

    Restricts retrieval to a specific Session.

    curl
      curl -X POST http://my-endpoint:8080/v2/memories \
      -H "Content-Type: application/json" \
      -H "Authorization: Token <your-api-key>" \
      -d '{
            "filters": {
                "user_id": "user_002",
                "run_id": "user_002_run_id",
                "agent_id": "food-assistant"
            }
        }'
    Python
    import requests
    import json
    
    payload = {
        "filters": {
              "user_id": "user_002",                                                                                                                                                   
              "run_id": "user_002_run_id",
              "agent_id": "food-assistant",                     
          }
    }
    
    response = requests.post(
        "http://<your-endpoint>:8080/v2/memories",
        headers={"Authorization": "Token <your-api-key>", "Content-Type": "application/json"},
        data=json.dumps(payload)
    )
    
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
    

Delete memories

Deletes all memories within a specified scope.

  • Request URL: DELETE /v1/memories

  • Query String:

    user_id String (Required)

    A unique identifier for the user.

    curl
    curl -X DELETE 'http://<your-endpoint>:8080/v1/memories?user_id=user_002&agent_id=food-assistant' \
      -H 'accept: application/json' \
      -H 'Authorization: Token <your-api-key>'
    Python
    import requests
    import json
    
    # Define the scope for deletion
    current_user_id = "user_002"
    current_agent_id = "food-assistant"
    
    # Prepare the API request URL
    api_url = f"http://<your-endpoint>:8080/v1/memories?user_id={current_user_id}&agent_id={current_agent_id}"
    
    response = requests.delete(
        api_url,
        headers={"Authorization": "Token <your-api-key>"},
    )
    
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
    

    agent_id String (Optional)

    Deletes memories only for the specified Agent.

    run_id String (Optional)

    Deletes memories only for the specified Session.