Skip to main content

AletheiaDB Python SDK

The official Python client for AletheiaDB, the cognitive memory engine for AI agents with fact supersession, knowledge graphs, and temporal truth retrieval.

This SDK wraps both the local-first Rust memory engine sidecar and the hosted/remote HTTP API under the exact same interface, ensuring a seamless development loop from local testing to cloud deployment.


Core Features

  • Fact Supersession & Conflict Resolution: Automatically manages evolving facts. When a new memory conflicts with an old one (e.g. "I moved to Seattle" superseding "I live in Austin"), the engine invalidates the old memory, resolving conflict and preventing hallucinations.
  • Hybrid Vector & Lexical Retrieval: Unifies HNSW semantic vector embeddings, BM25 full-text keyword matching, and neural rerankers for high-precision recall.
  • Temporal Querying & Decay: Apply time-aware relevance decay (freshness biasing) or query specific time windows to answer what was true at a specific moment.
  • Knowledge Graph Memories: Store memories alongside entity relations (subject ➔ relation ➔ object) and run walking traversals to fetch context networks.
  • Zero-Dependency Local Engine: The SDK can download, resolve, run, and manage a local Rust memory engine sidecar binary. Run memory completely privately on your local machine.

Installation

pip install aletheiadb

Client Connection

Initialize one client per process and reuse it across requests to optimize connection pooling.

1. Local-First Development Flow

In local-first mode, the SDK handles the lifecycle of the Rust sidecar engine binary.

from aletheia import AletheiaClient

# Automatically resolves, downloads, and runs the Rust engine binary on startup
client = AletheiaClient.from_local(
    auto_start=True,
    port=3000,
    data_dir="~/.aletheia/data",
)

2. Cloud Flow

Connect to the hosted AletheiaDB cloud platform or a self-hosted remote instance.

from aletheia import AletheiaClient

client = AletheiaClient.from_cloud(
    base_url="https://engine.aletheiadb.com",
    api_key="your_aletheiadb_api_key",
)

Usage Guide & Code Examples

1. Ingestion & Semantic Query

Store a natural language observation and search it semantically.

# Ingest memory
client.ingest(
    entity_id="user-123",
    text="I prefer pour-over coffee to espresso.",
)

# Retrieve context with semantic query
hits = client.query(
    query="What kind of coffee do I like?",
    entity_id="user-123",
    top_k=5,
    rerank=True,
)

for hit in hits:
    print(f"[{hit.similarity:.3f}] {hit.textual_content} (ID: {hit.memory_id})")

2. Knowledge Graph & Relation Mapping

Store facts associated with semantic relations and traverse the memory graph.

# Ingest memory with explicit graph relations
client.ingest(
    entity_id="user-123",
    text="Alice works at AletheiaDB.",
    relations=[("Alice", "works_at", "AletheiaDB")]
)

# Query immediate relations of a subject node
graph_res = client.graph_query(
    subject="Alice",
    edge_type="works_at",
)
print("Relations:", graph_res)

# Traverse the memory graph with a deep walk
walk_res = client.graph_walk(
    node="Alice",
    direction="out",
    depth=2,
    limit=20,
)
print("Walk Path:", walk_res)

# Export subgraph for custom visualizations
subgraph = client.export_graph(
    seed="Alice",
    max_nodes=50,
)

3. Temporal Queries

Enforce strict Unix millisecond boundaries to retrieve memories from a specific time window.

# Find what was discussed during a specific time interval
window_hits = client.temporal_query(
    entity_id="user-123",
    textual_query="Where did I work?",
    window_start_ms=1700000000000,  # Nov 2023
    window_end_ms=1760000000000,    # Oct 2025
)
print("Windowed memories:", window_hits)

4. Batch Ingestion

For high-throughput data loads, ingest items in batch chunks.

from aletheia import IngestItem

items = [
    IngestItem(
        entity_id="user-123",
        text="I am learning Rust.",
        kind="Skill",
    ),
    IngestItem(
        entity_id="user-123",
        text="I want to build web apps.",
        kind="Goal",
    ),
]

client.ingest_many(items, batch_size=64)

5. Memory Inspection & Self-Repair Deletion

Inspect raw memory state and safely delete nodes while triggering automatic predecessor recovery.

memory_id = "user-123::sdk::example_id"

# Inspect memory details and surrounding context turn-window
details = client.inspect_memory(
    memory_id=memory_id,
    include_turn_window=True,
    turn_window_radius=3,
)
print("Memory detail:", details)

# Delete memory (safely updates slots and heals invalidated facts)
client.delete_memory(
    memory_id=memory_id,
    reason="User requested removal",
)

6. Analytics Querying

Perform deterministic aggregate analytics on metric tags.

analytics = client.analytics_query(
    entity_id="user-123",
    label="coffee_intake",
    start_timestamp_ms=1700000000000,
)
print("Analytics trend:", analytics)

Engine Binary Resolution

When calling AletheiaClient.from_local(), the engine resolves the path to the local Rust sidecar binary in the following priority order:

  1. Explicitly provided binary_path argument.
  2. ALETHEIA_ENGINE_BINARY or TEMPORAL_MEMORY_ENGINE_BINARY environment variables.
  3. Repo-local builds: target/release/temporal_memory or target/debug/temporal_memory.
  4. Cached binaries in ALETHEIA_ENGINE_CACHE_DIR.
  5. Automatic download from ALETHEIA_ENGINE_MANIFEST_URL.

Environment Configuration

The SDK configures the Rust engine binary using the following variables:

  • TEMPORAL_MEMORY_HOST: Network interface host (default: 127.0.0.1).
  • TEMPORAL_MEMORY_PORT: Network interface port (default: 3000).
  • TEMPORAL_MEMORY_DATA_DIR: Directory where data files are persisted.
  • TEMPORAL_MEMORY_API_KEY: API credential key for the local instance.
  • ALETHEIA_API_KEY: API credential key for the remote/cloud client.

Metadata

Release files for aletheiadb 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aletheiadb 0.1.2
File Size Uploaded Provenance Actions
aletheiadb-0.1.2.tar.gz 12.7 kB Without provenance Details for aletheiadb-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aletheiadb 0.1.2
File Interpreter ABI Platform Actions
aletheiadb-0.1.2-py3-none-any.whl Python 3 none any Details for aletheiadb-0.1.2-py3-none-any.whl

Total release size: 22.9 kB

Release files / aletheiadb-0.1.2.tar.gz

Download URL aletheiadb-0.1.2.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
493aef3a11748d701c927df2c100deb340d4f7b4cda9c9f2aad06817805168c1
BLAKE2b-256 checksum
How to use checksums
e7f75fba93973f82ead2daac1d6dbe95c43a477eb440a81789056d1669ec03a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / aletheiadb-0.1.2-py3-none-any.whl

Download URL aletheiadb-0.1.2-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57221ebbdb50b9b314fcec66e43ad12a302e47631a995391b695cdcc2bf7e17
BLAKE2b-256 checksum
How to use checksums
113d08a3146475d8986a381e419152feff00cddd0b8ba60617fab25b98220b95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for aletheiadb 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page