Skip to main content

llm-kelt

Knowledge · Embedding · Learning · Training

Python Type Hints Linting: Ruff CI License

Persistent memory and fine-tuning data for LLM applications, backed by Postgres.

Store the things an LLM needs to know or learn from — facts, feedback, preferences, predictions, directives — under an isolation key. Retrieve them for prompt injection or RAG. Export them to DPO/SFT/classifier datasets. Train LoRA/DPO/Prompt adapters from the exported data.

Requirements

  • Python 3.11+
  • PostgreSQL 16+ with the vector extension (pgvector)
  • For training: CUDA GPU (or MPS on Apple Silicon)

Supported Python versions

CI tests every push on:

  • Linux (Ubuntu): Python 3.11, 3.12, 3.13, 3.14

requires-python = ">=3.11" is declared in package metadata; newer Python versions are validated in CI before being added to the matrix.

Install

pip install llm-kelt              # runtime
pip install llm-kelt[training]    # + torch / transformers / peft / trl

Database prerequisite

llm-kelt is a database-backed substrate: the quickstart and all examples/*.py scripts need a running Postgres 16+ server with pgvector before they will do anything useful. Standing one up takes ~30 seconds:

docker run -d --rm --name kelt-quickstart-db \
  -p 127.0.0.1:25432:5432 \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=learn_test \
  pgvector/pgvector:pg16

Repo cloners can equivalently make pg.server.up (uses the shipped etc/pg.yaml). See docs/quickstart.md § 1 for the full three-path menu (repo Makefile, standalone docker, existing Postgres).

Minimal example

import os

from appinfra.dot_dict import DotDict
from appinfra.log import LogConfig, LoggerFactory
from llm_kelt import ClientContext, ClientFactory
from llm_kelt.inference import ContextBuilder

lg = LoggerFactory.create_root(LogConfig.from_params(level="warning"))
database_url = os.environ.get(
    "DATABASE_URL", "postgresql://postgres:postgres@127.0.0.1:25432/learn_test"
)
config = DotDict({"dbs": {"main": {"url": database_url, "create_db": True}}})

kelt = ClientFactory(lg).create_from_config(
    context=ClientContext(context_key="my-agent"),
    config=config,
)

kelt.atomic.assertions.add("Timezone: UTC", category="settings")
kelt.atomic.assertions.add("Prefers concise, code-first answers", category="style")

system_prompt = ContextBuilder(kelt.atomic.assertions).build_system_prompt(
    base_prompt="You are a helpful assistant.",
)
# → "You are a helpful assistant.\n\n## About the user:\n- Timezone: UTC\n- ..."

That's the whole shape: put things in under a context_key, pull them back out grouped for prompt injection. Everything else (RAG, feedback, preferences, training) builds on the same model.

Where to go next

  • Quickstart — 5 minutes from install to first RAG query.
  • Concepts — context keys, schemas, atomic vs KG. Read once before the tutorials.
  • Atomic memory — the seven fact clients (assertions, feedback, preferences, predictions, directives, interactions, solutions) and how they relate.
  • Context & RAG — embedding facts, semantic search, ContextQuery.
  • Conversation — multi-turn sessions, token accounting, compaction, storage.
  • Training — manifest workflow, LoRA/DPO/SFT/Prompt, exports, adapter registry.
  • Knowledge graph — entities, aliases, hierarchical scopes.
  • Multi-schema — SchemaMode, with_schema(), isolation.
  • CLI reference — llm-kelt atomic|proxy|train|session.
  • Glossary — project-specific terms.

Configuration

ClientFactory.create_from_config accepts any dict-like config (a DotDict, a plain dict, or the object returned by appinfra's Config after loading a yaml file). For a yaml-backed setup, the shape is:

dbs:
  main:
    url: postgresql://user:pass@localhost:5432/llm_kelt
    extensions: [vector]

llm:
  default: local
  backends:
    local:
      base_url: http://localhost:8000/v1
      model: default

embedding:
  type: openai
  base_url: http://localhost:8001/v1
  model: text-embedding-3-small

kelt:
  adapters:
    lora:
      base_path: ~/models/adapters

llm, embedding, and kelt.adapters are only required for the subsystems that use them (ContextQuery, RAG, and training respectively).

Examples

Runnable scripts in examples/:

Suggested reading order:

  1. facts_and_context.py — assertions + ContextBuilder.
  2. rag_retrieval.py — embeddings, search_similar, ContextQuery with RAG.
  3. training_export.py — feedback + preferences → DPO/SFT/classifier JSONL.
  4. lora_training.py — end-to-end LoRA training.
  5. conversation.py — Conversation, compaction, FileSessionStorage.

License

Apache 2.0

Maintained by LLM Works LLC and contributors.

Metadata

Release files for llm-kelt 0.5.1

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

Source distribution (sdist)

Source distribution for llm-kelt 0.5.1
File Size Uploaded Provenance Actions
llm_kelt-0.5.1.tar.gz 392.8 kB With provenance Details for llm_kelt-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-kelt 0.5.1
File Interpreter ABI Platform Actions
llm_kelt-0.5.1-py3-none-any.whl Python 3 none any Details for llm_kelt-0.5.1-py3-none-any.whl

Total release size: 687.3 kB

Release files / llm_kelt-0.5.1.tar.gz

Download URL llm_kelt-0.5.1.tar.gz
Size 392.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eec64f75e04e49187ecf79f8cda09a2a1d767f0242d6b5768b729aedc312c188
BLAKE2b-256 checksum
How to use checksums
d3fb239fe205062ce91d8e57f7df624c78975b182d2986af94d6d8b2b68e2e51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / llm_kelt-0.5.1-py3-none-any.whl

Download URL llm_kelt-0.5.1-py3-none-any.whl
Size 294.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8a4f1c2052965ad04addd9ecde4fedb4e2d8cd93420371b68bb92409197461e
BLAKE2b-256 checksum
How to use checksums
ccd5835090f51fba07b8cd3ed1c4a5e369de4543b56e0408e0717707f4648c1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for llm-kelt 0.5.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for llm_kelt-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

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