Python SDK for Neocortex API by TinyHumans - ingest and delete memory with human context
Project description
TinyHuman Neocortex SDK
A persistent memory layer for AI applications. Neocortex lets your AI agents store, retrieve, and use context across conversations -- so they remember what matters.
Built on the TinyHumans API.
Install
pip install tinyhumansai
Requires Python 3.9+. The only runtime dependency is httpx.
Running locally
From the package directory (packages/sdk-python), install the project and optional dependency groups with uv:
uv sync --group dev --group examples
--group dev— test and lint tools (pytest, pytest-asyncio, mypy, ruff).--group examples—python-dotenvfor running the example script.
Then run the example:
# Copy .env.example to .env and set TINYHUMANS_TOKEN, TINYHUMANS_MODEL_ID, OPENAI_API_KEY (for recall_with_llm).
uv run python example.py
To install only the package and examples (no dev tools): uv sync --group examples.
Quick start
import tinyhumansai as api
client = api.TinyHumanMemoryClient("YOUR_APIKEY_HERE")
# Store a single memory
client.ingest_memory({
"key": "user-preference-theme",
"content": "User prefers dark mode",
"namespace": "preferences",
"metadata": {"source": "onboarding"},
})
# Ask a LLM something from the memory
response = client.recall_with_llm(
prompt="What is the user's preference for theme?",
api_key="OPENAI_API_KEY"
)
print(response.text) # The user prefers dark mode
Core concepts
Memory items are the basic unit of storage. Each item has:
| Field | Required | Description |
|---|---|---|
key |
yes | Unique identifier within a namespace (used for upsert/dedup) |
content |
yes | The memory text |
namespace |
yes | Scope for organizing items |
metadata |
no | Arbitrary dict for tagging/filtering |
created_at |
no | Unix timestamp in seconds |
updated_at |
no | Unix timestamp in seconds |
Namespaces let you organize memories by category (e.g. "preferences", "conversation-history", "user-facts").
Context is a pre-formatted string built from your stored memories, ready to inject into any LLM prompt as system context.
API reference
TinyHumanMemoryClient
client = api.TinyHumanMemoryClient(
token="your-api-key", # Required. TinyHumans API key.
model_id="neocortex-mk1", # Required. Model identifier.
base_url="https://...", # Optional. Override API base URL.
)
The client supports the context-manager protocol for automatic cleanup:
with api.TinyHumanMemoryClient(token="...", model_id="...") as client:
ctx = client.recall_memory(namespace="preferences", prompt="User preferences", num_chunks=10)
ingest_memory
Upsert a single memory item. The item is deduped by (namespace, key) -- if a match exists, it is updated; otherwise a new item is created.
result = client.ingest_memory(
item={
"key": "fav-color",
"content": "User's favorite color is blue",
"namespace": "preferences",
}
)
print(result.ingested, result.updated, result.errors)
With the MemoryItem dataclass:
from tinyhumansai import MemoryItem
result = client.ingest_memory(
item=MemoryItem(key="fav-color", content="Blue", namespace="preferences")
)
ingest_memories
Upsert multiple memory items in one call. Items are deduped by (namespace, key).
result = client.ingest_memories(
items=[
{"key": "fav-color", "content": "Blue", "namespace": "preferences"},
{"key": "fav-food", "content": "Pizza", "namespace": "preferences"},
]
)
print(result.ingested, result.updated, result.errors)
recall_memory
Fetch relevant memory chunks using a prompt and return them as an LLM-friendly context string. The API uses the prompt to retrieve the most relevant chunks from the namespace.
# Fetch up to 10 chunks relevant to the prompt
ctx = client.recall_memory(
namespace="preferences",
prompt="What is the user's favorite color?",
num_chunks=10,
)
print(ctx.context) # Formatted string
print(ctx.items) # List of ReadMemoryItem objects
print(ctx.count) # Number of items
# Optional: fetch more or fewer chunks
ctx = client.recall_memory(namespace="preferences", prompt="User preferences", num_chunks=5)
# Optional: filter by specific key(s) instead of prompt-based retrieval
ctx = client.recall_memory(namespace="preferences", prompt="", key="fav-color", num_chunks=10)
delete_memory
Remove memory items by key or delete all in a namespace. namespace is required.
# Delete a specific key
client.delete_memory(namespace="preferences", key="fav-color")
# Delete multiple keys
client.delete_memory(namespace="preferences", keys=["fav-color", "fav-food"])
# Delete all memories in a namespace
client.delete_memory(namespace="preferences", delete_all=True)
recall_with_llm (optional)
Query an LLM provider with your stored context injected -- no extra SDK dependencies needed. Supports OpenAI, Anthropic, and Google Gemini out of the box, plus any OpenAI-compatible endpoint.
ctx = client.recall_memory(namespace="preferences", prompt="User preferences", num_chunks=10)
# OpenAI
response = client.recall_with_llm(
prompt="What is the user's favorite color?",
provider="openai",
model="gpt-4o-mini",
api_key="your-openai-key",
context=ctx.context,
)
print(response.text)
Project details
Release history Release notifications | RSS feed
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 tinyhumansai-0.5.2.tar.gz.
File metadata
- Download URL: tinyhumansai-0.5.2.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ef669710289c715dbc4c66f7be17e6cd0640e04e248da5f9468f1cb2defe8fb
|
|
| MD5 |
2d5258ac12e9a7e7cbfade3302070c33
|
|
| BLAKE2b-256 |
12c7843688d06cea3c0fb5e4fa7c1ffe8ae5575f99f6c167a218c7007464d227
|
File details
Details for the file tinyhumansai-0.5.2-py3-none-any.whl.
File metadata
- Download URL: tinyhumansai-0.5.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6be699cf0568813024591461095c142ec971ae1272102f00a10a360d15b7846
|
|
| MD5 |
aeb3ee2d1fd474e5cb648f6f91ef3f82
|
|
| BLAKE2b-256 |
bb5aadf7a64d7b273028dfb2753b43a85d4d2fe95b7ced65dbb9a48d23cfcdfd
|