Skip to main content

Deterministic entity / world-model engine for AI agents — resolve messy references to canonical IDs, traverse relations, author the alias table. Storage-agnostic, local-first, zero generative-LLM on the hot path.

Project description

cairn-engine

The deterministic entity / world-model engine for AI agents. (The brand is Cairn; the distribution is cairn-engine and the import package is cairn_engine.)

Resolve messy human references to stable canonical IDs, traverse their relations bi-temporally, and author the frozen alias table that makes it all reproducible — storage-agnostic, local-first, zero generative-LLM and zero network on the default path, zero runtime dependencies (pure stdlib).

cairn-engine is the foundational entity subsystem. The agent-retrieval layer (gate, signals, fusion, assembler) lives in the separate cairn-retrieval package, which depends on this one.

Status: feature-complete, pre-release (0.1.0) — full resolution cascade, bounded bi-temporal traversal, ontology authoring + 3-tier dedup, SQLite and openCypher adapters, and a cross-system entity index. 120 tests, ruff + mypy strict, byte-stable. The retrieval-quality benchmark (OP-31) is the next phase; until then, treat determinism/portability as proven and quality as unclaimed. See the roadmap.

Install

pip install cairn-engine

Quickstart

from cairn_engine import (
    Entity, InMemoryAliasTable, InMemoryGraph, Ref, Relation, resolve, traverse,
)

entities = [
    Entity("account::schwab_main", "Schwab", "config", aliases=("my Schwab account",),
           refs=(Ref(doc_id="doc::accounts"),)),
    Entity("doc::payment_retry_policy", "Payment Retry Policy", "document",
           refs=(Ref(doc_id="doc::retry"),),
           relations=(Relation("references", "account::schwab_main"),)),
]

table = InMemoryAliasTable.from_entities(entities)     # build -> freeze -> read-only
graph = InMemoryGraph.from_entities(table.canonical_entities())

resolved, unresolved = resolve("does the payment retry policy touch my Schwab account?",
                               table=table)
# both entities found by gazetteer scan; unresolved == []  (a miss is never a made-up ID)

result = traverse(resolved[0].canonical_id, graph=graph, depth=2)
# connected DocumentRefs, hop-scored 1/(1+hop), byte-stable

The resolution cascade: exact → normalized (NFKC) → fuzzy (token-sort ≥ 0.85, entropy-gated) → semantic (opt-in: your embedder) → LLM arbiter (opt-in: your callable; picks among presented candidates in the 0.70–0.85 band — never mints an ID). Misses come back in unresolved — never a synthesized ID (closed world).

Build-time authoring (offline, human-gated): author_from_textdedup_candidates (exact → MinHash/LSH → review band, never auto-merged) → your approval → freeze(). Optional extractors (GLiNER / LLM) enter as callables you supply — the engine never imports third-party packages or calls APIs.

Also here: bi-temporal state (as_at, supersede), a cross-system entity index (CrossSystemIndex), a SQLite alias-table backend, and an openCypher compiler (compile_traversal / traverse_cypher) that runs the same bounded traversal on Neo4j / FalkorDB — the engine imports no DB driver; you pass the connection.

Design foundations

Grounded in five CS theories (canonicalization over equivalence classes, labeled property graphs, the bi-temporal model, bounded transitive closure, and the closed-world assumption) — see docs/patterns/ and docs/research/foundations/. Every module is developed intent-first (IVD): constraints in intents/ map 1:1 to tests with hand-computed golden fixtures.

License

MIT — Copyright (c) 2026 Leo Celis

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

cairn_engine-0.1.0.tar.gz (76.4 kB view details)

Uploaded Source

Built Distribution

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

cairn_engine-0.1.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file cairn_engine-0.1.0.tar.gz.

File metadata

  • Download URL: cairn_engine-0.1.0.tar.gz
  • Upload date:
  • Size: 76.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cairn_engine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7db3981084b5c657e5b2282ea39f18a90affbb3d58665c79023d0aeb1fa8e249
MD5 23cd220c8f7c260f786dac9fcadb9e33
BLAKE2b-256 df43210cdb16b73f6005ed8e86701ec35518550c6fa814c8ade325816a8bf7d7

See more details on using hashes here.

File details

Details for the file cairn_engine-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cairn_engine-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cairn_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c150bdd6e14e549b59f75d85d09501b5b34e204fefd5711995977f8c941b3a
MD5 1f3412699c665ad45a530540d4857a89
BLAKE2b-256 2f2d2edd69015d7991cba100f9b9d9765f8aeecf05b06063f540fd6af6d6a64c

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