Skip to main content

Official Python SDK for MemoryModel API

Project description

memory-model

Official Python SDK for MemoryModel.

Installation

pip install memory-model

Local Development

cd sdk-python
pip install -e .

Quick Start

from memory_model import MemoryClient

client = MemoryClient(
    api_key="sk_live_...",
    default_end_user_id="user_123"
)

# Add a memory
client.add("Project deadline is Friday.")

# Search memories
results = client.search("When is the deadline?")
for memory in results:
    print(f"[{memory.similarity:.2f}] {memory.content}")

API Reference

Constructor

MemoryClient(
    api_key: str,                      # Required
    base_url: str = "https://api.memorymodel.dev",
    default_end_user_id: str = None,
    timeout: int = 30,                 # Seconds
    max_retries: int = 3,              # Retries for 5xx/429
    api_version: str = "v1"            # API version prefix
)

Methods

add(content, *, user_context=None, end_user_id=None)

response = client.add("Meeting moved to 3pm.", user_context="Calendar update")
print(response.job_id)

add_image(image_data, *, user_context=None, end_user_id=None)

import base64
with open("screenshot.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode()

response = client.add_image(img_b64, user_context="Error screenshot")

search(query, *, limit=5, strategy="centroid_aware", end_user_id=None)

results = client.search("What time is the meeting?", limit=3)

list(*, limit=50, memory_type=None, end_user_id=None)

memories = client.list(limit=10)

delete(memory_id, *, end_user_id=None)

client.delete("mem_abc123")

Error Handling

from memory_model import MemoryClient, MemoryClientError

try:
    client.search("test")
except MemoryClientError as e:
    print(e.message)       # Human-readable error
    print(e.status)        # HTTP status (401, 429, 500...)
    print(e.code)          # Error code from API
    print(e.is_retryable)  # True for 5xx/429

Automatic Retry: The SDK retries on 5xx/429 with exponential backoff (1s → 2s → 4s).


Agent Integration

LangChain / CrewAI Example

from memory_model import MemoryClient
from langchain_openai import ChatOpenAI
from langchain.schema import SystemMessage, HumanMessage

memory = MemoryClient(api_key="sk_live_...", default_end_user_id="user_123")
llm = ChatOpenAI(model="gpt-4o")

def agent_respond(user_message: str) -> str:
    # 1. Store user message
    memory.add(user_message, user_context="User question")
    
    # 2. Retrieve context
    context = memory.search(user_message, limit=3)
    context_str = "\n".join([f"- {m.content}" for m in context])
    
    # 3. Generate response
    messages = [
        SystemMessage(content=f"Context:\n{context_str}"),
        HumanMessage(content=user_message)
    ]
    response = llm.invoke(messages)
    
    return response.content

Publishing to PyPI

cd sdk-python

# Build
pip install build
python -m build

# Upload
pip install twine
twine upload dist/*

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

memory_model-0.0.1.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

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

memory_model-0.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file memory_model-0.0.1.tar.gz.

File metadata

  • Download URL: memory_model-0.0.1.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for memory_model-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6001b5cb4ff6cff7e60df0b5ece29593e11a370e54f922beced7f0ee364a81a4
MD5 e525d56a836f45cbb55e776fd381cd54
BLAKE2b-256 ac4cfd0b7866847ceb6d5c5290603f9c0f88f60bac404532689105c10a68d662

See more details on using hashes here.

File details

Details for the file memory_model-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: memory_model-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for memory_model-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1c72860b41f220b8be34d7235d4391b6457baca0719901cc7f7386b29926906
MD5 edaf7a4300a677636360c47ea174ef5b
BLAKE2b-256 b9e6dfcfebc5dc433355c85ab71379aa3d69ef444c369a021462a61c1fa94c98

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