Skip to main content

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

Project description

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 (subjectrelationobject) 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.

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

aletheiadb-0.1.2.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

aletheiadb-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file aletheiadb-0.1.2.tar.gz.

File metadata

  • Download URL: aletheiadb-0.1.2.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aletheiadb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 493aef3a11748d701c927df2c100deb340d4f7b4cda9c9f2aad06817805168c1
MD5 67abe592c254596fa370dbe095525d18
BLAKE2b-256 e7f75fba93973f82ead2daac1d6dbe95c43a477eb440a81789056d1669ec03a6

See more details on using hashes here.

File details

Details for the file aletheiadb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aletheiadb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aletheiadb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e57221ebbdb50b9b314fcec66e43ad12a302e47631a995391b695cdcc2bf7e17
MD5 58804ef779a1ee42d22615f14aa8a1ee
BLAKE2b-256 113d08a3146475d8986a381e419152feff00cddd0b8ba60617fab25b98220b95

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