Skip to main content

The memory database for AI agents — graph memory, hybrid search, audit trail.

Project description

engrava

The memory database for AI agents.

Graph memory, hybrid search, and a tamper-evident audit trail — one pip install, no server, no LLM.

CI PyPI Python License: MIT

engrava is a standalone embedded database for AI agent memory. Built on SQLite, it provides thought CRUD, edge-based knowledge graphs, embedding-based similarity search, full-text search (FTS5/BM25), and a declarative extension system — all in a single package with zero external service dependencies.

Use Cases

  • AI agent persistent memory
  • Personal knowledge base
  • Conversation storage with semantic search
  • Research notes with associative linking
  • Any application that needs a thought-graph with embeddings

Quick Start

Installation

pip install engrava

Optional extras:

pip install engrava[vec]               # sqlite-vec vector search backend
pip install engrava[embeddings-local]  # sentence-transformers embeddings
pip install engrava[embeddings-openai] # OpenAI-compatible embeddings

Basic Usage

import asyncio
from engrava import SqliteEngravaCore

async def main() -> None:
    store = SqliteEngravaCore(":memory:")
    await store.ensure_schema()

    # Create a thought
    thought_id = await store.create_thought(
        thought_type="OBSERVATION",
        essence="Python is great for AI",
        content="Python's async ecosystem makes it ideal for AI agents.",
        priority="P2",
        source="human",
    )

    # Retrieve it
    thought = await store.get_thought(thought_id)
    print(f"Stored: {thought.essence}")

    # Create an edge between thoughts
    second_id = await store.create_thought(
        thought_type="INSIGHT",
        essence="SQLite is underrated",
        content="SQLite provides ACID transactions with zero setup.",
        priority="P2",
        source="human",
    )
    await store.create_edge(thought_id, second_id, "ASSOCIATION")

    # Query with MindQL
    from engrava import MindQLExecutor
    executor = MindQLExecutor(store)
    result = await executor.execute("FIND type=OBSERVATION LIMIT 5")
    for row in result.rows:
        print(row)

    await store.close()

asyncio.run(main())

Configuration-Driven Setup

from engrava import load_config, SqliteEngravaCore

config = load_config("engrava.yaml")
store = SqliteEngravaCore(config.db_path)
await store.ensure_schema()

See docs/configuration.md for the full YAML schema.

Upgrading

Automatic schema migration runs on first connection. See the upgrade guide for compatibility notes, backup guidance, and troubleshooting steps.

Features

Thought CRUD

Create, read, update, and archive thoughts with full lifecycle management. All models are frozen Pydantic objects — mutations happen via evolve().

Edge-Based Knowledge Graph

Link thoughts with typed, weighted edges. Supports association, causation, contradiction, and custom edge types.

Embedding Search

Store embeddings alongside thoughts and perform brute-force cosine similarity search. Pluggable embedding providers:

Provider Extra Backend
SentenceTransformerProvider embeddings-local Local model via sentence-transformers
OpenAICompatibleProvider embeddings-openai Any OpenAI-compatible API
OllamaProvider embeddings-ollama Local Ollama server
HuggingFaceProvider embeddings-hf HuggingFace Inference API
CallbackProvider (built-in) Custom callable

Full-Text Search (FTS5)

SQLite FTS5 virtual table with BM25 ranking. Hybrid search combines vector similarity, text relevance, and recency scoring.

MindQL Query Language

Declarative query language for the thought-graph:

FIND type=OBSERVATION priority=P1 LIMIT 10
COUNT status=ACTIVE
SELECT thought_id, essence WHERE type=INSIGHT

Extensible with custom commands via the hook system.

Extension System

Plug into the thought lifecycle via EngravaHooksProtocol:

from engrava import EngravaHooksProtocol, ThoughtRecord, ScoringContext

class MyHooks(EngravaHooksProtocol):
    async def on_store(self, thought: ThoughtRecord) -> ThoughtRecord:
        # Transform thoughts before persistence
        return thought

    async def score_function(
        self, thought: ThoughtRecord, context: ScoringContext
    ) -> float:
        # Custom relevance scoring
        return thought.confidence or 0.5

Dreaming / Memory Consolidation

Built-in DreamingExtension for periodic memory consolidation — scores thoughts via configurable signals, promotes high-value entries, and (v0.4.0) creates REFLECTION thoughts by clustering semantically related thoughts and computing centroid embeddings (no LLM required).

→ See docs/benchmarks.md for reproducible evidence (synthetic benchmark suite runnable in ~5 minutes).

Multi-Service Isolation

Run multiple independent databases under one EngravaManager:

from engrava import EngravaManager

async with EngravaManager(data_dir=Path("./data")) as mgr:
    agent_a = await mgr.get_store("agent-a")
    agent_b = await mgr.get_store("agent-b")
    # Completely isolated databases

CLI

engrava --db mydata.db info          # Database stats
engrava --db mydata.db query "FIND type=OBSERVATION LIMIT 5"
engrava --db mydata.db snapshot -o backup.jsonl
engrava --db mydata.db restore -i backup.jsonl
engrava --db mydata.db gc            # Garbage-collect archived thoughts
engrava --db mydata.db migrate       # Ensure schema is up-to-date
engrava --db mydata.db export -o portable.json

engrava info now renders the same metrics snapshot contract exposed by await store.metrics().

Architecture

  • SQLite with WAL mode for concurrent reads
  • Frozen Pydantic models — immutable domain objects
  • Async-first — all I/O via aiosqlite
  • Hook-based extension — zero monkey-patching
  • Template method pattern — subclass SqliteEngravaCore for extended schemas
  • Zero external services — everything runs locally in-process

Documentation

Development

pip install -e ".[dev]"
ruff check src/ tests/            # Lint
ruff format --check src/ tests/   # Format check
mypy --strict src/                # Type check
pytest --cov                      # Test with coverage

License

MIT — see LICENSE for details.

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

engrava-0.3.1.tar.gz (270.2 kB view details)

Uploaded Source

Built Distribution

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

engrava-0.3.1-py3-none-any.whl (259.0 kB view details)

Uploaded Python 3

File details

Details for the file engrava-0.3.1.tar.gz.

File metadata

  • Download URL: engrava-0.3.1.tar.gz
  • Upload date:
  • Size: 270.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for engrava-0.3.1.tar.gz
Algorithm Hash digest
SHA256 200805fbc73243bb799b45910be8b524bf3485bba789499e0b2f65ed733f00a7
MD5 0262eea84fc4169a78e2630eaaa39177
BLAKE2b-256 2614fe2fc118f5a906d8a3ee851f82b9271b757ea6b44027b2c0431c7d59111f

See more details on using hashes here.

Provenance

The following attestation bundles were made for engrava-0.3.1.tar.gz:

Publisher: release.yml on sovantica/engrava

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file engrava-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: engrava-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 259.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for engrava-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b77f79b448b11c940de41605cb38ac3eeaeac80a1baec09b73d51dcc5ee2b4
MD5 f85360c563ec0742e13c26e40fd17d7c
BLAKE2b-256 27c1678389702e013d8fcec984caaf96c769b062d562fa245d8f132399214357

See more details on using hashes here.

Provenance

The following attestation bundles were made for engrava-0.3.1-py3-none-any.whl:

Publisher: release.yml on sovantica/engrava

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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