Kristal
Kristal — a multi-faceted memory framework for AI: define any memory facet on a shared multi-source data substrate, consume them through one unified context layer, and audit every write and read across apps.
Status: pre-alpha. APIs will change. Prompts are currently tuned for Chinese, so generated memories are written in Chinese; an English prompt pack is planned.
Why Kristal
Memory is not one thing. A person's timeline, relationships, preferences and habits each need their own shape, lifecycle and retrieval rules. Kristal treats memory as a crystal: every memory type is a facet, and all facets grow from the same substrate.
- Multi-source substrate — raw inputs (chats, transcripts, media, app events) land as immutable items and are normalized into an observation layer that every facet reads from.
- Pluggable facets — add a new memory type by implementing one model and registering it; ingestion, orchestration and consumption stay untouched.
- Unified consumption — all facets converge into a single context layer that apps and agents query, with consistent permissions.
- People & profiles — a shared person directory (social graph) and user profile, fed by the facets that know about them.
- Auditable by design — every memory traces back to its evidence, and every read is ticketed and logged.
- Cross-app by default — one user, many apps, one memory, governed by explicit authorization.
Architecture
Items (raw input) ─► Observations / Segments ─► Facets (memory types) ─► Context (consumption)
multi-source shared substrate pluggable unified, auditable
└─► Persons & Profiles
Install
pip install kristal # library, standalone (SQLite + local files), no other services needed
pip install "kristal[server]" # + HTTP service (kristal serve)
pip install "kristal[all]" # + MySQL, Redis, S3, Milvus, Langfuse, Chinese name/calendar support
Python 3.11 or 3.12.
Quickstart: as a library
Set OPENAI_API_KEY (or point OPENAI_BASE_URL at any OpenAI-compatible endpoint), then:
from kristal import Kristal
with Kristal() as k: # data lives in ~/.kristal (SQLite + local files)
k.add([
{"role": "user", "content": "We fixed the release plan for Friday afternoon today.",
"at": "2026-11-20T09:00:00+08:00"},
{"role": "assistant", "content": "Are the two open bugs fixed by then?"},
{"role": "user", "content": "Yes, by Thursday. I'll write the release notes."},
], user_id="alice")
k.flush() # wait until the day's narrative is readable
print(k.memories("alice")["memories"][0]["content"]) # the day's narrative
ctx = k.context("alice", "What did Alice decide about the release?")
print(k.trace("alice", ctx["sections"][0]["memories"][0]["memory_id"])["items"]) # memory → evidence
flush() returns once what you wrote can be read (the day narratives); event stories, month and year rollups and
profiles keep running in the background, and flush(full=True) waits for them too. Methods return plain data and raise KristalError with the same error codes as the HTTP API. Use
k.app("glasses") to write and read as another app: several apps feed the same user, and each app's data stays
under its own visibility and authorization rules.
To use other providers, write a kristal.toml (see examples/config/ for OpenAI, DeepSeek,
Gemini, Qwen and Ollama) and pass it: Kristal("kristal.toml").
Quickstart: as a service
pip install "kristal[server]"
export OPENAI_API_KEY=...
export KRISTAL_ADMIN_TOKEN=$(openssl rand -hex 16) # enables the admin API
kristal serve --port 8000
Register an app (the response contains its AK/SK; the SK is shown only once):
curl -s -X POST localhost:8000/admin/v1/apps -H "X-Admin-Token: $KRISTAL_ADMIN_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"app_id": "notes", "name": "Notes", "owner": "me", "account_domain": "home", "trust": "first_party"}'
Every request is signed with the app's AK/SK. KristalClient does this for you and has the same methods as the
library:
from kristal import KristalClient
c = KristalClient("http://localhost:8000", ak="...", sk="...")
c.add([{"role": "user", "content": "..."}], user_id="alice")
print(c.context("alice", "What did Alice decide?"))
Interactive API docs are at http://localhost:8000/docs. For local development only, KRISTAL_AUTH_MODE=relaxed
skips signature checks.
Deployment
Kristal uses whatever infrastructure you configure and falls back to defaults for the rest:
| Component | Configured | Default |
|---|---|---|
| database | MySQL | SQLite file in KRISTAL_DATA_DIR |
| file storage | S3-compatible store | local directory |
| vectors | Milvus | a table in the database |
| locks, dedup, tokens | Redis | in-process / database |
| task queue | Redis Streams | in-process queue + sweeper |
- Standalone (no Redis): one process. A lease in the database makes a second process refuse to start. After a restart, unfinished work is recovered from the database.
- Cluster (Redis configured): any number of replicas; requires MySQL and S3.
kristal workerruns background processing without serving HTTP.
Configuration
Settings resolve in this order: constructor arguments → KRISTAL_* environment variables (and .env) →
kristal.toml (current directory or KRISTAL_CONFIG) → defaults. See .env.template for all
settings. Model routing ([models.*], [stages], [embedding], [rerank]) lives in kristal.toml.
License
Metadata
Release files for kristal 0.0.2
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 |
|---|---|---|---|---|
| kristal-0.0.2.tar.gz | 670.8 kB | Without provenance | Details for kristal-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kristal-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for kristal-0.0.2-py3-none-any.whl |
Total release size: 1.3 MB
Release files / kristal-0.0.2.tar.gz
| Download URL | kristal-0.0.2.tar.gz |
|---|---|
| Size | 670.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
927712789314a2d415350304cc81c4f1bb218ab254296db25eccc8eef6e55890
|
|
BLAKE2b-256 checksum How to use checksums |
370b1be5b35c10ad76e153f96ed555eda3fb73c04e191298d0f973a26aafca07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / kristal-0.0.2-py3-none-any.whl
| Download URL | kristal-0.0.2-py3-none-any.whl |
|---|---|
| Size | 617.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e43fdde40a9646d584b72074cb55250942698635aad3f33182486e1d152ae98d
|
|
BLAKE2b-256 checksum How to use checksums |
6b764df97aea3ca3eeda5199bf2885080bd9401802702d235462455b38168d87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for kristal 0.0.2
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.