Skip to main content

Local-first personal knowledge graph for AI agents — ontology, causal chains, contradiction detection

Project description

🌳 lorien

Local-first personal knowledge graph for AI agents.
What to believe, why, and what conflicts — structured memory that Mem0 can't do.

pip install lorien-memory           # core (KuzuDB + CLI)
pip install "lorien-memory[vectors]"  # + semantic search

Why lorien?

"Other tools tell you what the user said. lorien tells you what to believe, why, and what conflicts."

lorien stores structured knowledge — not just flat strings. Every fact has a source, every rule has a priority, and contradictions are detected automatically. Local, free, no server required.


lorien graph visualization

Quickstart

from lorien import LorienMemory

mem = LorienMemory(enable_vectors=True)

# Add a conversation
mem.add([
    {"role": "user",      "content": "I have a severe shellfish allergy. Oysters send me to the ER."},
    {"role": "assistant", "content": "Noted — I'll never recommend shellfish."},
], user_id="alice")

# 3 months later — new conversation
mem.add([
    {"role": "user",      "content": "Where should I eat tonight?"},
    {"role": "assistant", "content": "The new oyster bar on Main St is great!"},
], user_id="alice")

# Semantic search — finds allergy even without exact keywords
results = mem.search("seafood restrictions", user_id="alice")
# → [{"memory": "User has severe shellfish allergy...", "score": 0.82}]

# Auto-detected contradiction
contradictions = mem.get_contradictions()
# → [{"fact_a": "shellfish allergy...", "fact_b": "oyster bar recommendation..."}]

# Hard rules with priority
rules = mem.get_entity_rules("alice")
# → [{"text": "Never recommend shellfish to alice", "priority": 100}]

Schema

lorien uses KuzuDB — an embedded graph database (like SQLite, but for graphs).

Entity ─── HAS_RULE ───► Rule
  │
ABOUT
  │
  ▼
Fact ─── CAUSED ──► Fact
  │
CONTRADICTS
  │
  ▼
Fact

3 node types:

  • Entity — people, organizations, topics (canonical_key = "type:name")
  • Fact — statements about entities (subject → predicate → object)
  • Rule — constraints with priority 0–100 (100 = absolute prohibition)

5 edge types: ABOUT, HAS_RULE, RELATED_TO, CAUSED, CONTRADICTS


CLI

# Initialize
lorien init

# Check status
lorien status

# Ingest a file (MEMORY.md, notes, etc.)
lorien ingest MEMORY.md
lorien ingest MEMORY.md --model haiku   # LLM extraction via OpenClaw

# Query the graph
lorien query "MATCH (e:Entity) RETURN e.name LIMIT 10"

# Show entity details
lorien show "alice"

# List contradictions
lorien contradictions

# Conversation memory for a user
lorien memory alice

# Web visualization (vis.js, no extra deps)
lorien serve

Contradiction Detection

After every fact is ingested, lorien automatically checks for semantic contradictions:

  1. Vector similarity — find facts with similar meaning (threshold 0.55)
  2. Heuristic check — negation pair patterns (허용↔금지, always↔never, must↔must not, ...)
  3. LLM confirmation (optional) — yes/no question to any OpenAI-compatible model
  4. CONTRADICTS edge — auto-created in the graph for later querying
detector = ContradictionDetector(
    store=store,
    vector_index=vi,
    llm_model="gpt-4o-mini",
    api_key="sk-...",
    similarity_threshold=0.55,
)
n = detector.check_and_record(new_fact_id, new_fact_text)

OpenClaw Integration

lorien auto-detects the OpenClaw gateway when available:

lorien ingest MEMORY.md --model haiku   # routes through OpenClaw → Anthropic
lorien ingest notes.md  --model flash   # routes through OpenClaw → Gemini

No API key needed when OpenClaw gateway is running locally.


Installation

# Core only (graph + CLI, no LLM, no vectors)
pip install lorien-memory

# With semantic search
pip install "lorien-memory[vectors]"

# With OpenAI-compatible LLM extraction
pip install "lorien-memory[llm]"

# Everything
pip install "lorien-memory[all]"

Requirements: Python 3.12+, no server, no Docker.
DB stored at ~/.lorien/db. Vectors at ~/.lorien/vectors.db.


Roadmap

  • v0.1 — Core graph schema (Entity, Fact, Rule + 5 edge types)
  • v0.1 — LLM ingest via OpenClaw gateway
  • v0.1 — Mem0-compatible LorienMemory API
  • v0.2 — Vector semantic search (sentence-transformers, multilingual)
  • v0.2 — Automatic contradiction detection
  • v0.2 — PyPI release (pip install lorien-memory)
  • v1.0 — Web graph visualization
  • v1.0 — LangChain adapter


MIT License · GitHub

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

lorien_memory-0.3.0.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

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

lorien_memory-0.3.0-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file lorien_memory-0.3.0.tar.gz.

File metadata

  • Download URL: lorien_memory-0.3.0.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for lorien_memory-0.3.0.tar.gz
Algorithm Hash digest
SHA256 398afd985f72ea534b476f72c9816481556737b77b5a7204f7a350e9c5eb4297
MD5 6af5173f212c2aef4cf2464ee75907bf
BLAKE2b-256 4f28cce718cec6fa113f23315402c1893b07d531432be883d615f7fcef0d02ed

See more details on using hashes here.

File details

Details for the file lorien_memory-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lorien_memory-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for lorien_memory-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba5e78ab6fef3ba477a9c60440f97a15b9237b5f1438efa2fe7a9e62f9421417
MD5 825f4a37228a972dc458ad6fbfc4da40
BLAKE2b-256 0e65a8e170f1bfa29ef50473fe9f53a031f36cf5d0a14599c8d10a989a7e004a

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