Skip to main content

Python SDK for smritea AI memory system

Project description

smritea SDK — Python

Python SDK for the smritea AI memory system.

Get a free API key →


Installation

pip install smritea-sdk

Requires Python 3.9+.


Get your API key

  1. Sign up at smritea.ai — free account, no credit card required
  2. Create an app in the dashboard and copy your API key (sk-...) and App ID (app_...)
  3. 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. Use search() 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

smritea_sdk-0.1.3.tar.gz (74.3 kB view details)

Uploaded Source

Built Distribution

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

smritea_sdk-0.1.3-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file smritea_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: smritea_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 74.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for smritea_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dd614e84ffe54ae3f0faa5074ed7d77671b428410a6ba287c25cb046e691ad0c
MD5 cf58f27f3d394ce4916d7d4944c7cb32
BLAKE2b-256 b56d1aff30fcc58e323901130d7494f6bfd5aaad483fab4d752092d928985d8d

See more details on using hashes here.

File details

Details for the file smritea_sdk-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for smritea_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb841086ef705405c3633c009e353f3573011707dc482bfb5528077963d582dd
MD5 9c5636dab8c9b5d8479dca12b65b4e35
BLAKE2b-256 b29579cd6c91f75c553a937dcafc177a9d2c65af6ae4ee3aae840038461e3e76

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