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
- Python 3.11+ — Install here
- pip — Install here
- uv — Install here
- gcloud CLI (for authentication) — Install here, then log in using:
gcloud auth login
Mem0 Configuration
Mem0 API Key:
- Get your API key from https://app.mem0.ai/dashboard/api-keys
- For self-hosted deployments, use your server's API key
Optional Self-Hosted Server:
- If using self-hosted Mem0, provide your server URL via
MEM0_HOSTenvironment 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
- Python 3.11+ — Install here
- pip — Install here
- uv — Install here
- gcloud CLI — Install here, then log in using:
gcloud auth login
- Git — Install here
- 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
-
Install the package:
uv pip install gllm-memory
-
Set your Mem0 API key:
export MEM0_API_KEY="your_api_key_here"
-
For Self-Hosted Mem0 (Optional):
export MEM0_API_KEY="your_api_key_here" export MEM0_HOST="https://your-mem0-server.com"
For Development
-
Complete setup (this will install all dependencies, setup pre-commit, and activate the environment):
make setup source .venv/bin/activate
-
Set your Mem0 API key:
export MEM0_API_KEY="your_api_key_here"
-
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 keyMEM0_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 objectssearch(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 filteringupdate(memory_id, new_content, metadata, user_id, agent_id, scopes)- Update an existing memory by IDdelete(memory_ids, user_id, agent_id, scopes, metadata)- Delete memories by IDs or by user/agent identifiersdelete_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
-
Fork and clone the repository
-
Set up development environment:
# Complete setup: installs uv, configures auth, installs packages, sets up pre-commit make setup
-
Activate virtual environment:
source .venv/bin/activate
-
Run tests to ensure everything works:
make test
-
Make your changes and ensure tests pass:
# Make your changes # Ensure tests pass make test
-
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gllm_memory_binary-0.1.12-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 570.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc79d8c965ce8d29052de7f005de1af0766eebaf73ef8761f88df9edfadb96b7
|
|
| MD5 |
f3fc50f667d33186efba2d78a713e957
|
|
| BLAKE2b-256 |
60d86286f34ea8b03f2f7264b4bb312dd51e603fb1a252b5aa78092ae545da7c
|
Provenance
The following attestation bundles were made for gllm_memory_binary-0.1.12-cp312-cp312-win_amd64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_memory_binary-0.1.12-cp312-cp312-win_amd64.whl -
Subject digest:
bc79d8c965ce8d29052de7f005de1af0766eebaf73ef8761f88df9edfadb96b7 - Sigstore transparency entry: 1183602188
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Branch / Tag:
refs/tags/gllm_memory-v0.1.12 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_memory_binary-0.1.12-cp312-cp312-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 816.1 kB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d587b055ec99907443b404ffde63a0639c662284af54660c20957f44198c6cf9
|
|
| MD5 |
ce3bee3f7d29594585df2ca2ef132905
|
|
| BLAKE2b-256 |
929a0197c187fbff3dc05dd9b6f31ab94d89b01d89a591c6111e135ba2d862c6
|
File details
Details for the file gllm_memory_binary-0.1.12-cp312-cp312-macosx_13_0_arm64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp312-cp312-macosx_13_0_arm64.whl
- Upload date:
- Size: 562.6 kB
- Tags: CPython 3.12, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c99489bc7ca17b61d9722ad8a8cd374ed5b508938aea98e2a99313e9331ec34
|
|
| MD5 |
fdfda9386fabee526b44c7f1c7a36d0f
|
|
| BLAKE2b-256 |
720d8f19bce848b06ca23d9b323095d7160ab27e2bffa9fae3609f0c754a4c6d
|
Provenance
The following attestation bundles were made for gllm_memory_binary-0.1.12-cp312-cp312-macosx_13_0_arm64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_memory_binary-0.1.12-cp312-cp312-macosx_13_0_arm64.whl -
Subject digest:
8c99489bc7ca17b61d9722ad8a8cd374ed5b508938aea98e2a99313e9331ec34 - Sigstore transparency entry: 1183602298
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Branch / Tag:
refs/tags/gllm_memory-v0.1.12 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_memory_binary-0.1.12-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 576.6 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5865e984624088c62c940f3196855a81656425a30d44c6d39db63d9dfdb16dd
|
|
| MD5 |
2d58bf7bc5f81c72760ef6a92e3edc5d
|
|
| BLAKE2b-256 |
0a6abeb2c59fd7fcc3b8487bea5c64e0f3766b1bbc145c6bc8684c55f71c2a67
|
Provenance
The following attestation bundles were made for gllm_memory_binary-0.1.12-cp311-cp311-win_amd64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_memory_binary-0.1.12-cp311-cp311-win_amd64.whl -
Subject digest:
e5865e984624088c62c940f3196855a81656425a30d44c6d39db63d9dfdb16dd - Sigstore transparency entry: 1183601748
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Branch / Tag:
refs/tags/gllm_memory-v0.1.12 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_memory_binary-0.1.12-cp311-cp311-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 745.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb0b291fa2838808ea2280bcbc2f0dbcb396417f7384d79665c6e29f0436c49
|
|
| MD5 |
906b67f4c860e117a2ae5b2fa39e4bbe
|
|
| BLAKE2b-256 |
f00247a56a8c8df015ac0ff2946530585b85343e4c8461eea252e6adcbfde987
|
File details
Details for the file gllm_memory_binary-0.1.12-cp311-cp311-macosx_13_0_arm64.whl.
File metadata
- Download URL: gllm_memory_binary-0.1.12-cp311-cp311-macosx_13_0_arm64.whl
- Upload date:
- Size: 555.4 kB
- Tags: CPython 3.11, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca43804a7902271062bafce08b836f1f4b1d8db121b127053807fec707e73529
|
|
| MD5 |
0b65404c2646ccf0c7698c068e1a5997
|
|
| BLAKE2b-256 |
c8c9c0cdafd5fed2d260a61ed59123a0d50fd90f72738dd944616cd238a25258
|
Provenance
The following attestation bundles were made for gllm_memory_binary-0.1.12-cp311-cp311-macosx_13_0_arm64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_memory_binary-0.1.12-cp311-cp311-macosx_13_0_arm64.whl -
Subject digest:
ca43804a7902271062bafce08b836f1f4b1d8db121b127053807fec707e73529 - Sigstore transparency entry: 1183601337
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Branch / Tag:
refs/tags/gllm_memory-v0.1.12 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@920577827d06dc2dcfe9a4d1b4b1ff95ef89d757 -
Trigger Event:
push
-
Statement type: