Core memory engine for Z3rno: PostgreSQL schema, SQLAlchemy models, Alembic migrations, and the store/recall/forget/audit library functions.
Project description
z3rno-core
Core memory engine for Z3rno -- PostgreSQL schema, SQLAlchemy models, Alembic migrations, and the store/recall/forget/audit library.
Features
- 7 relational tables -- tenants, API keys, agents, memories, memory relationships, lifecycle policies, audit log
- 15 Alembic migrations -- fully versioned schema evolution
- Row-Level Security (RLS) -- multi-tenant isolation at the database level
- SCD Type 2 versioning -- temporal history for every memory mutation
- pgvector HNSW indexing -- fast approximate nearest-neighbor vector search
- Apache AGE graph layer -- entity and relationship traversal via Cypher queries
- Hash-chained audit log -- tamper-evident record of every store, recall, forget, and update
Quickstart
Run migrations
# Set your database URL
export DATABASE_URL="postgresql://z3rno:password@localhost:5432/z3rno"
# Install
pip install -e .
# Apply all migrations
alembic upgrade head
Use the engine
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
from z3rno_core.engine import store, recall, forget, audit
engine = create_async_engine("postgresql+asyncpg://z3rno:password@localhost/z3rno")
Session = async_sessionmaker(engine)
async with Session() as db:
# Store a memory
memory = await store(db, org_id=org_id, agent_id="agent-1", content="User prefers dark mode")
# Recall by semantic similarity
results = await recall(db, org_id=org_id, agent_id="agent-1", query="user preferences", top_k=5)
# Soft-delete a memory
await forget(db, org_id=org_id, memory_id=memory.id)
# Query the audit trail
entries = await audit(db, org_id=org_id, agent_id="agent-1")
Architecture
The schema follows a strict dependency order:
tenants -> api_keys -> agents -> memories -> memory_relationships
|
+-> lifecycle_policies
+-> audit_log
All engine functions operate within a single async SQLAlchemy session and respect RLS via SET LOCAL on the org context.
Documentation
- SCHEMA.md -- full table and column reference
- MULTI_TENANCY.md -- RLS design and tenant isolation
- Architecture Decision Records -- design rationale
Development
uv sync --dev
uv run ruff check .
uv run mypy .
uv run pytest
See CONTRIBUTING.md for the full workflow.
License
Apache 2.0 -- see LICENSE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file z3rno_core-0.1.0.tar.gz.
File metadata
- Download URL: z3rno_core-0.1.0.tar.gz
- Upload date:
- Size: 96.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd872116e5fb8c972e94ff3c7bf664328050de6a1e318158b0be1b6283a6b6e1
|
|
| MD5 |
6ad94c9f435acace95f6b937800274e9
|
|
| BLAKE2b-256 |
8f7f341257445276ecacc6e7d1c22a0bb48b423b17635f4ecba386c9169f8792
|
File details
Details for the file z3rno_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: z3rno_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f738d98ff6029acaa22e985754f5b131afbcd75633e5c0d2c4d5f3d496a285c8
|
|
| MD5 |
03e416e4280350c5a9dd8e78ff6d570a
|
|
| BLAKE2b-256 |
f468fa6678467546c19ee95ed97d0a7b3b9736f182402687ca4a0e1895c85f98
|