Skip to main content

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[mem0]"         # + mem0 as a memory type (docs/internals/external-memory.md)
pip install "kristal[all]"          # + MySQL, Redis, S3, Milvus, Langfuse, Chinese name/calendar support, mem0

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, and the built-in read-only Memory Workbench for browsing memories, social graphs, profiles and segments across apps and users is at http://localhost:8000/workbench. For local development only, KRISTAL_AUTH_MODE=relaxed skips signature checks.

Inputs and memory types

Inputs. Recordings with transcripts (media/recording.*), transcripts (conversation/transcript.*), instant messaging chats (conversation/chat.*) and assistant sessions (conversation/agent.session) are cleaned, segmented and understood; each kind has its own segmentation rules. Images and files inside messages travel with the segment as attachments. Other kinds are stored and traceable but not yet turned into memories. In the library, pick the kind with k.add(messages, user_id=..., subtype="chat.im").

Memory types. A memory type turns segments into memories. Kristal ships life_timeline (narratives of the user's days, months and years) and social_graph (user-centered interpersonal relationship graph and character memories), and can plug in open-source memory frameworks as memory types; storage and retrieval are theirs, while authorization, tracing, audit and erasure stay Kristal's (docs/internals/external-memory.md). The first adapter is mem0:

# kristal.toml; install with: pip install "kristal[mem0]"
[memory_types.mem0]
enabled = true                       # external frameworks are off by default
sources = ["conversation/chat.*", "conversation/agent.session"]

[memory_types.life_timeline]
sources = ["conversation/transcript.*", "media/recording.*", "conversation/chat.*"]

Which memory types receive a segment is the intersection of the deployment ([memory_types.<name>]: enabled, sources) and the writing app, which can limit it in its App Profile with memory_types.

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 worker runs 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 kristal.toml.template and .env.template for all settings and stage-level model routing ([models.*], [stages], [embedding], [rerank]).

License

MIT

Metadata

Release files for kristal 0.1.11

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

Source distribution (sdist)

Source distribution for kristal 0.1.11
File Size Uploaded Provenance Actions
kristal-0.1.11.tar.gz 811.8 kB Without provenance Details for kristal-0.1.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kristal 0.1.11
File Interpreter ABI Platform Actions
kristal-0.1.11-py3-none-any.whl Python 3 none any Details for kristal-0.1.11-py3-none-any.whl

Total release size: 1.5 MB

Release files / kristal-0.1.11.tar.gz

Download URL kristal-0.1.11.tar.gz
Size 811.8 kB
Tags Source
SHA-256 checksum
How to use checksums
62045c346d7c509a161b74054247a0a6daa67aa39a52a7cedf75c545b9969126
BLAKE2b-256 checksum
How to use checksums
aede04567863fc5d3a640264c20e7e6a15449d6ac429fbb3bac682cc0e13173d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / kristal-0.1.11-py3-none-any.whl

Download URL kristal-0.1.11-py3-none-any.whl
Size 737.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
183f7be2d766bf48a551e83837ba3238625b5a42cbe936d1d684130d58bed7b6
BLAKE2b-256 checksum
How to use checksums
3f4917d36c3e41509a43637d04dd5b2d41a1b4e9ace20c5035b82faf2c968e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Security for kristal 0.1.11

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