Python SDK for smritea AI memory system
Project description
smritea SDK — Python
Python SDK for the smritea AI memory system.
Installation
pip install smritea-sdk
Requires Python 3.9+.
Get your API key
- Sign up at smritea.ai — free account, no credit card required
- Create an app in the dashboard and copy your API key (
sk-...) and App ID (app_...) - Export them as environment variables:
export SMRITEA_API_KEY="sk-..."
export SMRITEA_APP_ID="app_..."
Quickstart
import os
from smritea import SmriteaClient
client = SmriteaClient(
api_key=os.environ["SMRITEA_API_KEY"],
app_id=os.environ["SMRITEA_APP_ID"],
)
# Store something about a user
client.add("Alice is a vegetarian and loves hiking", user_id="alice")
# Retrieve it later in a different session
results = client.search("What are Alice's food preferences?", user_id="alice")
for r in results:
print(f"{r.score:.2f} {r.content}")
Constructor
from smritea import SmriteaClient
client = SmriteaClient(
api_key="sk-...", # required
app_id="app_...", # required
base_url="https://api.smritea.ai", # optional, default shown
max_retries=2, # optional, default 2; 0 disables retry
)
Methods
add — Store a memory
memory = client.add(
"User prefers concise replies",
user_id="alice", # shorthand for actor_id + actor_type="user"
metadata={"source": "chat"}, # optional
conversation_id="conv_123", # optional
)
print(memory.id) # mem_...
user_id is a shorthand — sets actor_id and forces actor_type="user". For agent or system memories use actor_id + actor_type directly.
| Parameter | Default | Description |
|---|---|---|
content |
required | Memory text |
user_id |
None |
Shorthand: actor_id + actor_type="user" |
actor_id |
None |
Explicit actor ID |
actor_type |
"user" |
"user" | "agent" | "system" |
actor_name |
None |
Display name |
metadata |
None |
Arbitrary key-value dict |
conversation_id |
None |
Conversation context |
search — Semantic search
results = client.search(
"dietary restrictions",
user_id="alice",
limit=5,
method="deep_search", # "quick_search" | "deep_search" | "context_aware_search"
threshold=0.7, # min relevance score 0.0–1.0
)
for r in results:
print(r.score, r.content)
Results are ordered by relevance (descending). Each result exposes score (0.0–1.0) and all Memory fields directly.
| Search method | When to use |
|---|---|
quick_search |
Low-latency, keyword + vector hybrid |
deep_search |
Higher recall, traverses the memory graph |
context_aware_search |
Reranks results using conversation context |
| Parameter | Default | Description |
|---|---|---|
query |
required | Search text |
user_id |
None |
Filter to this user's memories |
actor_id |
None |
Filter by actor ID |
actor_type |
None |
Filter by actor type |
limit |
app default | Max results to return |
method |
app default | Search strategy |
threshold |
None |
Min relevance score 0.0–1.0 |
graph_depth |
None |
Graph traversal depth override |
conversation_id |
None |
Conversation context |
get — Retrieve a memory by ID
memory = client.get("mem_abc123")
print(memory.content, memory.created_at)
# Raises SmriteaNotFoundError if the ID does not exist
delete — Delete a memory by ID
client.delete("mem_abc123")
# Raises SmriteaNotFoundError if the ID does not exist
get_all — List all memories
Not yet implemented. Raises
NotImplementedError. Usesearch()with a broad query as a workaround:
results = client.search("", user_id="alice", limit=100)
Error handling
from smritea import (
SmriteaClient,
SmriteaAuthError,
SmriteaNotFoundError,
SmriteaRateLimitError,
SmriteaQuotaError,
SmriteaValidationError,
SmriteaError,
)
try:
results = client.search("preferences", user_id="alice")
except SmriteaAuthError:
print("Check your API key")
except SmriteaRateLimitError as e:
print(f"Rate limited — retry after {e.retry_after}s")
except SmriteaQuotaError:
print("Plan quota exceeded")
except SmriteaError as e:
print(f"Unexpected error: {e}")
| Exception | HTTP | When |
|---|---|---|
SmriteaAuthError |
401 | Invalid or missing API key |
SmriteaValidationError |
400 | Invalid request parameters |
SmriteaNotFoundError |
404 | Memory ID does not exist |
SmriteaQuotaError |
402 | Organisation quota exceeded |
SmriteaRateLimitError |
429 | Rate limit hit — check .retry_after |
SmriteaError |
other | Unexpected server error |
Memory type reference
| Field | Type | Description |
|---|---|---|
id |
str | Memory ID (mem_...) |
app_id |
str | App this memory belongs to |
content |
str | Memory text |
actor_id |
str | Actor who owns this memory |
actor_type |
str | "user" | "agent" | "system" |
actor_name |
str | None | Display name |
metadata |
dict | None | Arbitrary key-value pairs |
conversation_id |
str | None | Conversation context |
conversation_message_id |
str | None | Message within the conversation |
active_from |
str | ISO 8601 — when memory becomes valid |
active_to |
str | None | ISO 8601 — when memory expires |
created_at |
str | ISO 8601 creation timestamp |
updated_at |
str | ISO 8601 last update timestamp |
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
Built Distribution
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 smritea_sdk-0.1.4.tar.gz.
File metadata
- Download URL: smritea_sdk-0.1.4.tar.gz
- Upload date:
- Size: 74.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15270353b83489276aa90c9cc0a3a3b1e6490fcb0e77a4e51413d42662a2c63b
|
|
| MD5 |
1990f14da12523097d3b94e7e5b9305b
|
|
| BLAKE2b-256 |
f5e7a117eac018fef68017ed8fad0a6f2477a56efe1e6669074889d1a701be28
|
File details
Details for the file smritea_sdk-0.1.4-py3-none-any.whl.
File metadata
- Download URL: smritea_sdk-0.1.4-py3-none-any.whl
- Upload date:
- Size: 54.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ba9c4873907786de32b1c43662964e4e045185e34b86a4a0f7e52f3f7bcc433
|
|
| MD5 |
11b30bd68b5647c9729b305823e55fb4
|
|
| BLAKE2b-256 |
c074df9ea5f254701e6f2864c410d2642f9b61ca87e6d38de16be0dccf299406
|