Skip to main content

Long-term memory for AI Agents with Azure DefaultAzureCredential authentication and MySQL history database support. Async-only API.

Project description

Mem0 - Azure Enhanced Fork

This repository is an enhanced fork of mem0ai/mem0 that provides enterprise-grade improvements for Azure environments and production deployments.

Key Enhancements

1. Async-Only API

  • AsyncMemory: This fork provides only the async AsyncMemory class for better performance and scalability
  • Simplified Codebase: Removed synchronous Memory class to reduce code complexity and maintenance burden
  • Modern Python: Built for async/await patterns with full asyncio support

2. Azure Entra ID Authentication

  • Azure AI Search: Support for Azure Entra ID (Azure AD) authentication using DefaultAzureCredential
  • Azure OpenAI: Seamless Entra ID integration for both LLM and embedding services
  • Simplified Authentication: No need to manage API keys when using managed identities or service principals

3. MySQL Database Support

  • Production-Ready: Replace SQLite3 with enterprise-grade MySQL for scalable memory history storage
  • Connection Pooling: Built-in connection pooling and SSL support for secure connections
  • Thread-Safe: Thread-safe operations with proper connection management

Installation

Install the enhanced package with Azure and MySQL dependencies:

pip install mem0ai-azure-mysql

Or with uv:

uv add mem0ai-azure-mysql

Quick Start

import asyncio
from mem0 import AsyncMemory

config = {
    "vector_store": {
        "provider": "azure_ai_search",
        "config": {
            "collection_name": "mem0",
            "service_name": "your-search-service",
            "embedding_model_dims": 1536,
            "azure_ad_token": "<your-token>"  # Or use DefaultAzureCredential
        },
    },
    "llm": {
        "provider": "azure_openai",
        "config": {
            "model": "gpt-4",
            "azure_kwargs": {
                "api_version": "2024-12-01-preview",
                "azure_deployment": "gpt-4",
                "azure_endpoint": "https://your-endpoint.openai.azure.com/",
                "azure_ad_token": "<your-token>",
            },
        },
    },
    "embedder": {
        "provider": "azure_openai",
        "config": {
            "model": "text-embedding-3-small",
            "embedding_dims": 1536,
            "azure_kwargs": {
                "api_version": "2024-12-01-preview",
                "azure_deployment": "text-embedding-3-small",
                "azure_endpoint": "https://your-endpoint.openai.azure.com/",
                "azure_ad_token": "<your-token>",
            },
        },
    },
    "db": {
        "provider": "mysql",
        "config": {
            "host": "your-mysql-server.mysql.database.azure.com",
            "port": 3306,
            "user": "mem0",
            "password": "<your-password>",
            "database": "mem0",
            "ssl_enabled": True,
        },
    },
}

async def main():
    memory = await AsyncMemory.from_config(config)

    # Add memories
    result = await memory.add(
        "I love playing tennis on weekends",
        user_id="user123"
    )
    print(result)

    # Search memories
    results = await memory.search("What sports do I like?", user_id="user123")
    print(results)

asyncio.run(main())

Development

Setup with uv (Recommended)

# Install dependencies with dev extras
uv sync --extra dev

# Run example
uv run python example.py

# Run tests
uv run pytest tests/

Setup with hatch

# Create environment
make install

# Run tests
make test

Available Commands

make format    # Format code with ruff
make lint      # Lint code with ruff
make test      # Run tests
make build     # Build package
make clean     # Clean build artifacts

API Reference

AsyncMemory

The main class for interacting with the memory system.

from mem0 import AsyncMemory

# Create from config
memory = await AsyncMemory.from_config(config)

# Add memories
await memory.add(messages, user_id="user123")

# Search memories
await memory.search(query, user_id="user123")

# Get all memories
await memory.get_all(user_id="user123")

# Delete memories
await memory.delete_all(user_id="user123")

# Get memory by ID
await memory.get(memory_id)

# Update memory
await memory.update(memory_id, new_data)

# Get history
await memory.history(memory_id)

# Reset all
await memory.reset()

License

This project is licensed under the Apache License 2.0 - see the original mem0 repository for details.

Project details


Download files

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

Source Distribution

mem0ai_azure_mysql-0.2.2.tar.gz (48.8 kB view details)

Uploaded Source

Built Distribution

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

mem0ai_azure_mysql-0.2.2-py3-none-any.whl (61.3 kB view details)

Uploaded Python 3

File details

Details for the file mem0ai_azure_mysql-0.2.2.tar.gz.

File metadata

  • Download URL: mem0ai_azure_mysql-0.2.2.tar.gz
  • Upload date:
  • Size: 48.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mem0ai_azure_mysql-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e169894f729e0879a072c8925981646ef8cd9d803627cefb65b8a1084a45ed26
MD5 e176d22bd0253016f4eaf469321d1626
BLAKE2b-256 f07051d12921bf0e7e84d2441c29ac62597041d23d358903564d30fe54abe1f2

See more details on using hashes here.

File details

Details for the file mem0ai_azure_mysql-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: mem0ai_azure_mysql-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 61.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mem0ai_azure_mysql-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c68bd5f00e287379bb81957967c5f4051bf36682d41223f179633e701f28c1fc
MD5 42b276525583b2bc5ed9cd3b6ee71f7e
BLAKE2b-256 e3d78da90627539b09f34436a9459364ad0beb3e4be64ec1db6fc4ff1a5e76f2

See more details on using hashes here.

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