AI PostgreSQL

AI PostgreSQL

Certified

Persist chat memory in PostgreSQL

Stores chat history in a PostgreSQL table keyed by memory_id; TTL sets an expires_at timestamp. Honors drop policies BEFORE_TASKRUN/AFTER_TASKRUN; defaults to NEVER (memory is retained). Table is created if missing. Requires reachable Postgres with permissions to create tables.

yaml
type: io.kestra.plugin.ai.memory.PostgreSQL

Use PostgreSQL-based chat memory for a conversation

yaml
id: chat_with_memory
namespace: company.ai

tasks:
  - id: first
    type: io.kestra.plugin.ai.rag.ChatCompletion
    chatProvider:
      type: io.kestra.plugin.ai.provider.GoogleGemini
      modelName: gemini-3.5-flash-lite
      apiKey: "{{ secret('GEMINI_API_KEY') }}"
    memory:
      type: io.kestra.plugin.ai.memory.PostgreSQL
      host: localhost
      port: 5432
      database: ai_memory
      user: postgres
      password: secret
      tableName: my_custom_memory_table
    systemMessage: You are a helpful assistant, answer concisely
    prompt: "{{ inputs.first }}"
Properties

Database name

Name of the PostgreSQL database holding the chat memory table. No default: this property is required.

PostgreSQL host

Hostname or IP address of the PostgreSQL server storing the chat memory. No default: this property is required.

Database password

Password of the database user. Store it as a Kestra secret rather than inline. No default: this property is required.

Database user

User connecting to the PostgreSQL database. No default: this property is required.

DefaultNEVER
Possible Values
NEVERBEFORE_TASKRUNAFTER_TASKRUN

When to drop the memory

Controls when the stored conversation is erased, rather than waiting for ttl to expire. NEVER (default) keeps it until expiry, BEFORE_TASKRUN clears it before the task runs, and AFTER_TASKRUN clears it once the task run completes.

Default{{ labels.system.correlationId }}

Memory ID

Identifier under which the conversation is stored, so that different runs or users can keep separate histories. Defaults to the system.correlationId label, which makes one memory span an entire flow execution including its subflows.

Default10

Maximum messages in memory

Number of chat messages retained in memory. When the limit is reached, the oldest messages are evicted first (FIFO); the last system message is always kept. Defaults to 10.

Default5432

PostgreSQL port

TCP port the PostgreSQL server listens on. Defaults to 5432.

Defaultchat_memory

Table name

Table used to persist the chat memory, created with CREATE TABLE IF NOT EXISTS on first use. Must match ^[a-zA-Z_][a-zA-Z0-9_]{0,62}$, or the task fails before connecting; this is enforced to prevent SQL injection, since the name is interpolated into the statements. Defaults to chat_memory.

DefaultPT1H

Memory duration

How long the memory is retained before it expires. Defaults to PT1H (one hour).