sumudunissanka/ai.memory.redis

0.1.0
Ballerina Redis Short-Term Memory Store

Overview

This Ballerina module provides a Redis-backed short-term memory store for AI chat messages. It implements the ai:ShortTermMemoryStore interface, enabling AI agents and model providers to persist conversation history using Redis as the storage backend.

Features

  • Redis-backed storage: Persistent storage of chat messages using Redis data structures
  • Configurable message limits: Set the maximum number of interactive messages per session key (default: 20)
  • In-memory caching: Optional cache layer for improved read performance (default capacity: 20)
  • Flexible initialization: Use either a connection configuration or a pre-created Redis client

Prerequisites

Getting Started

Configuration-based Setup

Copy
import ballerinax/ai.memory.redis;

redis:ShortTermMemoryStore store = check new (
    connection = {
        host: "localhost",
        port: 6379
    }
);

Client-based Setup

Copy
import ballerinax/ai.memory.redis;
import ballerinax/redis as redisClient;

redisClient:Client cl = check new (
    connection = {
        host: "localhost",
        port: 6379
    }
);

redis:ShortTermMemoryStore store = check new (cl);

Customization

Message Capacity

Copy
redis:ShortTermMemoryStore store = check new (
    connection = {host: "localhost", port: 6379},
    maxMessagesPerKey = 50
);

Cache Configuration

Copy
import ballerina/cache;

redis:ShortTermMemoryStore store = check new (
    connection = {host: "localhost", port: 6379},
    cacheConfig = {capacity: 30, evictionFactor: 0.2}
);

Key Prefix

Copy
redis:ShortTermMemoryStore store = check new (
    connection = {host: "localhost", port: 6379},
    keyPrefix = "my_app_memory"
);

Building from Source

Prerequisites

Build

Copy
bal build

Run Tests

Start a Redis server (e.g., using Docker):

Copy
docker run -d -p 6379:6379 --name redis-test redis:7-alpine

Then run:

Copy
bal test

Community

License

This module is available under the Apache 2.0 License.

Import

import sumudunissanka/ai.memory.redis;Copy

Other versions

0.1.1

0.1.0

Metadata

Released date: 3 days ago

Version: 0.1.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.13.2

GraalVM compatible: Yes


Pull count

Total: 1

Current verison: 1


Weekly downloads


Source repository


Keywords

ai

agent

memory

redis

AI & Machine Learning


Contributors