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_text →
dedup_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
Metadata
Release files for cairn-engine 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cairn_engine-0.1.0.tar.gz | 76.4 kB | Without provenance | Details for cairn_engine-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cairn_engine-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for cairn_engine-0.1.0-py3-none-any.whl |
Total release size: 116.9 kB
Release files / cairn_engine-0.1.0.tar.gz
| Download URL | cairn_engine-0.1.0.tar.gz |
|---|---|
| Size | 76.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7db3981084b5c657e5b2282ea39f18a90affbb3d58665c79023d0aeb1fa8e249
|
|
BLAKE2b-256 checksum How to use checksums |
df43210cdb16b73f6005ed8e86701ec35518550c6fa814c8ade325816a8bf7d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / cairn_engine-0.1.0-py3-none-any.whl
| Download URL | cairn_engine-0.1.0-py3-none-any.whl |
|---|---|
| Size | 40.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6c150bdd6e14e549b59f75d85d09501b5b34e204fefd5711995977f8c941b3a
|
|
BLAKE2b-256 checksum How to use checksums |
2f2d2edd69015d7991cba100f9b9d9765f8aeecf05b06063f540fd6af6d6a64c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for cairn-engine 0.1.0
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.