Client
The Memorer class is the main entry point for the SDK.
Constructor
from memorer import Memorer
client = Memorer(
api_key="mem_sk_...", # Required
base_url="https://api.memorer.ai", # Optional, defaults to MEMORER_BASE_URL or production
timeout=30.0, # Optional, request timeout in seconds
max_retries=2, # Optional, retries for transient failures
)Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
api_key | str | Yes | — | Your Memorer API key |
base_url | str | No | https://api.memorer.ai | API base URL. Also reads MEMORER_BASE_URL env var |
timeout | float | No | 30.0 | Request timeout in seconds |
max_retries | int | No | 2 | Maximum retries for transient failures |
Context Manager
The client supports the context manager protocol for automatic cleanup:
with Memorer(api_key="mem_sk_...") as client:
user = client.for_user("user-123")
user.remember("User prefers dark mode")
# client is automatically closedMethods
for_user(owner_id)
Creates a user-scoped client for memory operations. This is the recommended way to handle multi-tenancy.
user = client.for_user("user-123")| Parameter | Type | Description |
|---|---|---|
owner_id | str | Unique identifier for the end-user |
Returns: UserClient
consolidate(dry_run, threshold_percentile)
Run adaptive forgetting to consolidate memories.
# Preview what would be deleted
report = client.consolidate(dry_run=True)
print(f"Would delete {report.entities_soft_deleted} memories")
# Actually run consolidation
report = client.consolidate(dry_run=False, threshold_percentile=30.0)
print(f"Reduced memory by {report.memory_reduction_pct}%")| Parameter | Type | Default | Description |
|---|---|---|---|
dry_run | bool | True | Preview changes without making them |
threshold_percentile | float | 30.0 | Percentile below which to soft-delete |
Returns: ConsolidationReport
health()
Check the API health status.
status = client.health()
print(status.status) # "ok"
print(status.version) # API version
print(status.environment) # "production"Returns: HealthStatus with fields status, version, environment
close()
Close the client and release resources. Called automatically when using the context manager.
client.close()Resource Attributes
The client exposes resource objects for project-wide operations:
| Attribute | Type | Description |
|---|---|---|
client.knowledge | KnowledgeResource | Knowledge graph operations |
client.entities | EntitiesResource | Entity CRUD operations |
client.memories | MemoriesResource | Memory management |
client.graph | GraphResource | Graph operations (communities, duplicates, merge) |
Last updated on