Skip to main content

hakua-memory

TL;DR: hakua-memory is a self-contained Python memory library for autonomous agents. It combines SQLite-backed Ebbinghaus memory, a structured semantic graph, optional embedding-based retrieval, RAG (Retrieval-Augmented Generation) with citation tracking and ACL filtering, sleep-cycle consolidation, and Obsidian-compatible diary and dream exports behind a small, composable API.

Overview

Long-running agents need more than a vector index. They need memories that can decay, be reinforced, be inspected as structured claims, and be exported into a human-readable knowledge base.

hakua-memory provides those building blocks without requiring the Hermes Agent codebase. The package uses a src/ layout and keeps the main integrations optional where practical.

Features

  • Ebbinghaus memory store
    • SQLite persistence
    • Retention and forgetting-curve calculations
    • Recall scoring and reinforcement
    • Salience, valence, tags, and memory-state handling
    • Sleep-cycle rehearsal, archival, pruning, and dream candidates
  • Semantic Graph
    • SQLite graph storage
    • Typed nodes, edges, evidence, fragments, and evaluations
    • Full-text search where available
    • Sanitisation and deterministic data handling
  • Embedding retrieval
    • Pluggable embedding backend contract
    • Deterministic fake backend for tests and demonstrations
    • Optional llama-cpp-python backend
    • Versioned embedding namespaces and dimension validation
    • Hybrid lexical/dense retrieval with deterministic reciprocal-rank fusion
  • RAG (Retrieval-Augmented Generation)
    • Document ingestion (PDF, DOCX, PPTX, Markdown, plain text)
    • Page/slide/section-aware chunking with provenance
    • Document version management
    • ACL (Access Control List) filtering per document
    • Citation context rendering (Markdown + XML)
    • Meeting item extraction (decisions, tasks, action items, unresolved items)
    • Contradiction detection between documents
    • CJK-aware search with FTS + LIKE fallback
  • Obsidian export
    • Diary and dream markdown exports
    • Human-readable files suitable for an Obsidian vault
  • Single composite API
    • One entry point for remembering, recalling, graph updates, RAG operations, retrieval, sleep, export, and status reporting

Installation

Python 3.11, 3.12, and 3.13 are supported.

python -m pip install hakua-memory

For local development:

python -m pip install -e ".[dev]"

Optional extras:

# Obsidian/Git integration helpers
python -m pip install "hakua-memory[obsidian]"

# llama.cpp embedding support
python -m pip install "hakua-memory[embedding]"

# RAG document ingestion (PDF/DOCX/PPTX)
python -m pip install "hakua-memory[rag]"

Quick start

from pathlib import Path

from hakua_memory import CompositeMemory

memory = CompositeMemory(Path(".memory"))

memory.remember(
    "The user prefers concise, verifiable reports.",
    tags=["user-preference", "communication"],
)

matches = memory.recall("verifiable reports")
print(matches)

memory.add_node(
    {
        "node_id": "claim-1",
        "node_type": "Claim",
        "label": "Verifiable reporting",
        "summary": "Reports should distinguish observed results from assumptions.",
        "status": "asserted",
        "authority": "user",
        "confidence": 0.95,
        "salience": 0.8,
        "evidence": [],
    }
)

print(memory.stats())
memory.sleep()
memory.export_wiki(Path("knowledge-base"))

RAG Quick start

from pathlib import Path
from hakua_memory import CompositeMemory

memory = CompositeMemory(Path(".memory"))

# Ingest a PDF document
result = memory.ingest_document(
    Path("meeting_notes.pdf"),
    title="Q3 Planning Meeting",
    author="Alice",
    department="Product",
)
print(result)  # {'document_id': '...', 'title': '...', 'chunks': 12, ...}

# Search with citation tracking
results = memory.search_documents("release schedule", top_k=5)
for r in results:
    print(f"[{r['rank']}] {r['document_title']} (p.{r.get('page_number')})")
    print(f"    {r['content'][:100]}...")

# Render citation context for RAG answers
context = memory.render_citations(results, format="markdown")
print(context)

# Extract meeting items (decisions, tasks, action items)
items = memory.extract_meeting_items(results[0]["document_id"])
for item in items:
    print(f"[{item['item_type']}] {item['content']}")

# Grant ACL access and search with filtering
memory.grant_access(results[0]["document_id"], "alice", "read")
alice_results = memory.search_documents("schedule", principal="alice")

# Detect contradictions between documents
contradictions = memory.detect_contradictions(min_confidence=0.6)
for c in contradictions:
    print(f"[{c['type']}] {c['description']}")

Embedding retrieval

Embedding support is backend-agnostic. The package includes a deterministic fake backend for tests and a contract for production backends.

from hakua_memory.semantic_graph.embedding.base import EmbeddingModelIdentity
from hakua_memory.semantic_graph.embedding.fake import DeterministicFakeEmbeddingBackend

backend = DeterministicFakeEmbeddingBackend(
    identity=EmbeddingModelIdentity(
        provider="demo",
        model="deterministic",
        revision="1",
        dimensions=8,
        serializer_version=1,
    ),
    vectors={"Verifiable reporting": [1, 2, 3, 4, 5, 6, 7, 8]},
)

results = memory.search("Verifiable reporting", backend=backend)

The retrieval layer validates vector dimensions, records the embedding namespace, and combines lexical and dense rankings without silently mixing incompatible representations.

Architecture

CompositeMemory
├── EbbinghausMemoryStore ── SQLite memory database
├── SemanticGraphStore ──── SQLite graph database
├── Hybrid retrieval ────── lexical + optional embedding backend
└── Obsidian export ──────── diary and dream Markdown files

The package is intentionally independent from Hermes Agent. It can be embedded into another agent runtime, used as a local library, or extended through its backend interfaces.

Development

Run the package checks from the repository root:

python -m compileall -q src
python -m build

The integration path can be exercised with a temporary directory and the deterministic embedding backend, covering:

  1. memory insertion and recall;
  2. semantic-node insertion;
  3. hybrid search;
  4. sleep-cycle processing; and
  5. Obsidian diary export.

Design notes

  • SQLite is the persistence boundary; generated databases should normally remain outside the repository.
  • Embedding backends are optional and replaceable.
  • Lexical retrieval remains available when no embedding backend is configured.
  • Numerical verification and formal proof are deliberately separate concerns.
  • Exported Markdown is intended to be inspectable and version-controllable by the user.

License

Apache License 2.0. See LICENSE.

Metadata

Release files for hakua-memory 0.2.0

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

Source distribution (sdist)

Source distribution for hakua-memory 0.2.0
File Size Uploaded Provenance Actions
hakua_memory-0.2.0.tar.gz 126.3 kB Without provenance Details for hakua_memory-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hakua-memory 0.2.0
File Interpreter ABI Platform Actions
hakua_memory-0.2.0-py3-none-any.whl Python 3 none any Details for hakua_memory-0.2.0-py3-none-any.whl

Total release size: 267.1 kB

Release files / hakua_memory-0.2.0.tar.gz

Download URL hakua_memory-0.2.0.tar.gz
Size 126.3 kB
Tags Source
SHA-256 checksum
How to use checksums
47b1c3c36f83b3ee7615521528bcf33075261311dfcdfbf958210a2704a1cfde
BLAKE2b-256 checksum
How to use checksums
a38fd1254bb54a7fd932858335a9a473b12779f1fdb1e6367e95582063326534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hakua_memory-0.2.0-py3-none-any.whl

Download URL hakua_memory-0.2.0-py3-none-any.whl
Size 140.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53076f25eb6bd0fbcf31016db0e44ba17064c4b9c76ac4dda34e4c33c160abb1
BLAKE2b-256 checksum
How to use checksums
225c65f77eb0dda2136d77949b43fe31ecd51bf22207f7811df4df6c0472c25d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for hakua-memory 0.2.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.

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