Skip to main content

A flexible memory system for Gen AI applications

Project description

GLLM Memory

Description

A flexible and extensible memory system for AI Agents with Mem0 Platform integration (both cloud and self-hosted), designed following SOLID principles and clean architecture patterns.

Prerequisites

Mandatory

  1. Python 3.11+Install here
  2. pipInstall here
  3. uvInstall here
  4. gcloud CLI (for authentication) — Install here, then log in using:
    gcloud auth login
    

Mem0 Configuration

Mem0 API Key:

Optional Self-Hosted Server:

  • If using self-hosted Mem0, provide your server URL via MEM0_HOST environment variable

Keep your API key secure and never commit it to version control.


📦 Installation

Install from Artifact Registry

This requires authentication via the gcloud CLI.

uv pip install \
  --extra-index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/" \
  gllm-memory

🔧 Local Development Setup

Prerequisites

  1. Python 3.11+Install here
  2. pipInstall here
  3. uvInstall here
  4. gcloud CLIInstall here, then log in using:
    gcloud auth login
    
  5. GitInstall here
  6. Access to the GDP Labs SDK GitHub repository

1. Clone Repository

git clone git@github.com:GDP-ADMIN/gl-sdk.git
cd gl-sdk/libs/gllm-memory

2. Setup Authentication

Set the following environment variables to authenticate with internal package indexes:

export UV_INDEX_GEN_AI_INTERNAL_USERNAME=oauth2accesstoken
export UV_INDEX_GEN_AI_INTERNAL_PASSWORD="$(gcloud auth print-access-token)"
export UV_INDEX_GEN_AI_USERNAME=oauth2accesstoken
export UV_INDEX_GEN_AI_PASSWORD="$(gcloud auth print-access-token)"

3. Quick Setup

Run:

make setup

4. Activate Virtual Environment

source .venv/bin/activate

🚀 Quick Start

For Using the Library

  1. Install the package:

    uv pip install gllm-memory
    
  2. Set your Mem0 API key:

    export MEM0_API_KEY="your_api_key_here"
    
  3. For Self-Hosted Mem0 (Optional):

    export MEM0_API_KEY="your_api_key_here"
    export MEM0_HOST="https://your-mem0-server.com"
    

For Development

  1. Complete setup (this will install all dependencies, setup pre-commit, and activate the environment):

    make setup
    source .venv/bin/activate
    
  2. Set your Mem0 API key:

    export MEM0_API_KEY="your_api_key_here"
    
  3. Run the basic usage example:

    # Run the example (includes add, search, list, delete_by_user_query, and delete operations)
    python examples/simple_usage.py
    

Architecture

The system follows a layered architecture below:

┌─────────────────────────────────────────────────────────────┐
│                    Application Layer                        │
├─────────────────────────────────────────────────────────────┤
│                    Memory Manager                           │
├─────────────────────────────────────────────────────────────┤
│                    Memory Client (Base)                     │
├─────────────────────────────────────────────────────────────┤
│                    Provider Layer (Mem0)                    │
├─────────────────────────────────────────────────────────────┤
│                    Mem0 Platform                            │
└─────────────────────────────────────────────────────────────┘

🌐 Self-Hosted Mem0 Support

In addition to the cloud Mem0 Platform, this library supports self-hosted Mem0 servers. You can connect to your own Mem0 deployment by specifying a custom host:

from gllm_memory import MemoryManager

# Cloud usage (default)
manager = MemoryManager(api_key="your-api-key")

# Self-hosted usage
manager = MemoryManager(
    api_key="your-api-key",
    host="https://your-mem0-server.com"
)

Environment Variables:

  • MEM0_API_KEY: Your Mem0 API key
  • MEM0_HOST: Your self-hosted Mem0 server URL (optional, defaults to cloud)

Core API Methods

The MemoryManager provides a simple, platform-agnostic interface for memory operations:

Available Methods

  • add(user_id, agent_id, messages, scopes, metadata, infer) - Add new memories from message objects
  • search(query, user_id, agent_id, scopes, metadata, threshold, top_k) - Search and retrieve memories by query (query is required)
  • list_memories(user_id, agent_id, scopes, metadata, keywords, page, page_size) - Get all memories with pagination and keywords filtering
  • update(memory_id, new_content, metadata, user_id, agent_id, scopes) - Update an existing memory by ID
  • delete(memory_ids, user_id, agent_id, scopes, metadata) - Delete memories by IDs or by user/agent identifiers
  • delete_by_user_query(query, user_id, agent_id, scopes, metadata, threshold, top_k) - Delete memories by query (query is required)

Method Details

from gllm_memory import MemoryManager
from gllm_inference.schema.message import Message
from gllm_memory.enums import MemoryScope

# Initialize
memory_manager = MemoryManager()

# Add memories using Message objects
messages = [
    Message.user("I love pizza and Italian food"),
    Message.assistant("I'll remember that you love pizza and Italian food"),
]
await memory_manager.add(
    user_id="user_123",
    messages=messages,
    scopes=[MemoryScope.USER],
    metadata={"conversation_id": "chat_001"},  # Optional
    infer=True  # Optional, defaults to True
)

# Retrieve memories (query is required)
memories = await memory_manager.search(
    query="What does the user like to eat?",
    user_id="user_123",
    scopes=[MemoryScope.USER],
    metadata=None,  # Optional
    threshold=0.3,  # Optional, defaults to 0.3
    top_k=10  # Optional, defaults to 10
)

# List all memories with pagination and keywords filtering
all_memories = await memory_manager.list_memories(
    user_id="user_123",
    scopes=[MemoryScope.USER],
    metadata=None,  # Optional
    keywords="food",  # Optional
    page=1,  # Optional, defaults to 1
    page_size=100  # Optional, defaults to 100
)

# Update an existing memory by ID
updated_memory = await memory_manager.update(
    memory_id="memory_uuid_123",
    new_content="Updated memory content",  # Optional
    metadata={"category": "updated_preferences"},  # Optional
    user_id="user_123",
    agent_id="agent_456",
    scopes=[MemoryScope.USER, MemoryScope.ASSISTANT]  # Optional
)

# Delete memories by query (query is required)
deleted = await memory_manager.delete_by_user_query(
    query="food preferences",
    user_id="user_123",
    scopes=[MemoryScope.USER, MemoryScope.ASSISTANT],
    metadata=None,  # Optional
    threshold=0.3,  # Optional, defaults to 0.3
    top_k=10  # Optional, defaults to 10
)

# Delete memories by identifiers
delete_result = await memory_manager.delete(
    memory_ids=None,  # Optional
    user_id="user_123",
    scopes=[MemoryScope.USER, MemoryScope.ASSISTANT],
    metadata=None  # Optional
)

🔧 Code Quality

# Format code with ruff
ruff format gllm_memory/ tests/

# Check code quality
ruff check gllm_memory/ tests/

# Fix auto-fixable issues
ruff check gllm_memory/ tests/ --fix

Local Development Utilities

The following Makefile commands are available for quick operations:

Install uv

make install-uv

Install Pre-Commit

make install-pre-commit

Install Dependencies

make install

Update Dependencies

make update

Run Tests

make test

Contributing

Please refer to the Python Style Guide for information about code style, documentation standards, and SCA requirements.

Contributing Steps

  1. Fork and clone the repository

  2. Set up development environment:

    # Complete setup: installs uv, configures auth, installs packages, sets up pre-commit
    make setup
    
  3. Activate virtual environment:

    source .venv/bin/activate
    
  4. Run tests to ensure everything works:

    make test
    
  5. Make your changes and ensure tests pass:

    # Make your changes
    # Ensure tests pass
    make test
    
  6. Submit a pull request:

    # Submit a pull request
    git push origin your-branch
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gllm_memory_binary-0.1.9-cp312-cp312-win_amd64.whl (566.3 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_memory_binary-0.1.9-cp312-cp312-manylinux_2_31_x86_64.whl (811.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_memory_binary-0.1.9-cp312-cp312-macosx_13_0_arm64.whl (555.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_memory_binary-0.1.9-cp311-cp311-win_amd64.whl (571.2 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_memory_binary-0.1.9-cp311-cp311-manylinux_2_31_x86_64.whl (742.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_memory_binary-0.1.9-cp311-cp311-macosx_13_0_arm64.whl (550.7 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gllm_memory_binary-0.1.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a4b12a70c564109938d4d68d6eb91ffa69d7dd12283619c6e3d1d1fa4149298a
MD5 b8bc5a4dc47014ba40df0a5a8004057c
BLAKE2b-256 0086ee871ee72c5e5e419d0c78005253b1a4d86fb8304fc688c8d3d895d5ca0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_memory_binary-0.1.9-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_memory_binary-0.1.9-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2afe5c11d26d4947aceee9d4dc25c700e302a7b9ec6edb8f749012faa999d02a
MD5 c13305dd9b205771a188d674438dde5f
BLAKE2b-256 692f9699f9a93c3230f1ec8ee95c9ba338d3d4ffe560fe0b4f2a238fef2d7ad6

See more details on using hashes here.

File details

Details for the file gllm_memory_binary-0.1.9-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ad545666add37256e2e63bd192fa64feedaa9c56f6348914bbff49dac980fc20
MD5 02a5b053b64c74c212e92d2c2e8c5a62
BLAKE2b-256 13f37271052dd8320043f014030f1cb5ca2eee409c0affae3c267e489691aac2

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_memory_binary-0.1.9-cp312-cp312-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_memory_binary-0.1.9-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f44e36ced6cea4d002ffe6b3d61d2576616565e8ce3102f72531ba4319c5459c
MD5 a14635eb8d05c1247b756033e3e14b66
BLAKE2b-256 4efde35c343684d670afbafa0273b94b3ff30e964bf915abd8b0a61ab9a20bd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_memory_binary-0.1.9-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_memory_binary-0.1.9-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0ebd93c12541505e7884c2f0d420608aaa66d98f7cf518dbe1b06b43da419e7c
MD5 8fa2724e024f3a4b065992a0a26e86ff
BLAKE2b-256 5a8ab3ea13841e7b470d00f577d34893f6e4a45dc42785f8f036a86e9d8768d2

See more details on using hashes here.

File details

Details for the file gllm_memory_binary-0.1.9-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_memory_binary-0.1.9-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 6e6f167946b49ca87de4055113aa69c7e51949fe99c2904cd5388d102f633e9d
MD5 6153abd5d4508cf1b7259bb312b745e1
BLAKE2b-256 f2cf3b6951610db4d134c12bb0f8c479bf9c22ce63b60bd3b6e96038d23a0134

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_memory_binary-0.1.9-cp311-cp311-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page