Knowledge memory library for long-horizon AI agents — hybrid retrieval over documents, embeddings, and graph relationships
Project description
Khora
"Khora is the receptacle, the space, the matrix in which all things come to be." — Plato, Timaeus
Khora is a knowledge memory library for long-horizon AI agents, with pluggable retrieval engines and storage backends to fit different workloads. It stores knowledge as documents, embeddings, and graph relationships, and retrieves it through hybrid search (vector + graph + keyword), reranking, and temporal context.
Khora is a library, not an application. Tooling lives in sibling packages (coming soon...):
- khora-cli (to be released soon) — CLI tooling for extraction and search.
- khora-explorer (to be released soon) — tooling for ontology construction and exploration.
Install
pip install khora # core (PostgreSQL + pgvector)
pip install khora[sqlite-lance] # [experimental] embedded SQLite + LanceDB
pip install khora[surrealdb] # [experimental] unified SurrealDB (single store)
pip install khora[all-backends] # everything: Neo4j, SurrealDB, SQLite+LanceDB, Weaviate, AGE
See docs/configuration.md for the full extras list.
Production stack
The production stack is PostgreSQL + pgvector + Neo4j:
- VectorCypher (default engine) — runs on PostgreSQL + pgvector + Neo4j.
- Chronicle — runs on PostgreSQL + pgvector (no graph DB required).
- Skeleton — available; PostgreSQL + pgvector (no graph DB required).
Set KHORA_DATABASE_URL and KHORA_NEO4J_URL, run uv run alembic upgrade head, then instantiate Khora() with no arguments:
import asyncio
from khora import Khora
async def main() -> None:
async with Khora() as kb: # reads KHORA_DATABASE_URL / KHORA_NEO4J_URL
ns = await kb.create_namespace("demo")
await kb.remember(
"Marie Curie won the Nobel Prize in Physics in 1903.",
namespace=ns.namespace_id,
)
result = await kb.recall("What did Curie win?", namespace=ns.namespace_id)
print(result.context_text)
asyncio.run(main())
Batch processing
submit_batch() stages documents as PENDING and returns a BatchHandle immediately. A background processor picks them up and calls on_result per document as each completes.
The processor is opt-in. Call kb.start_pending_processor() after connect() on services that write documents. Read-only services do not need it. The processor can be stopped with await kb.stop_pending_processor() and restarted at any time.
async with Khora() as kb:
kb.start_pending_processor() # opt-in; write-path services only
handle = await kb.submit_batch(
[{"content": "doc 1"}, {"content": "doc 2"}],
on_result=lambda completed, total, result: print(result),
namespace=ns_id,
)
await handle.wait()
Embedded options (experimental)
Khora ships two zero-infrastructure paths. Both are marked experimental — fine for demos, evaluation, tests, and small single-user CLIs; not yet stamped as a deployment story.
- SQLite + LanceDB (
pip install khora[sqlite-lance], setKHORA_STORAGE_BACKEND=sqlite_lance) — recommended embedded stack. Covers VectorCypher, Skeleton, and Chronicle via dialect-aware Alembic migrations and LanceDB-backed vector search. Documented scale ceiling: ~1M chunks, ~100k entities, ~500k edges, traversal depth ≤3. Known gaps: no point-in-time queries, partial atomicity incoordinator.transaction(), FTS on chunks only. See configuration.md. - SurrealDB (
pip install khora[surrealdb]) — unified relational + vector + graph in one store. Python SDK is on the alpha track (>=2.0.0a1), and KNN (<|K|>) is unreliable in embedded mode (uses brute-force cosine + HNSW fallback). Suitable for experimentation; not recommended for production.
Quickstart caveat. A literal
Khora("memory://")call passes"memory://"as the PostgreSQL URL, not as a backend selector — there is nomemory://URL scheme parsed by khora itself today. To use the embedded path, setKHORA_STORAGE_BACKEND=sqlite_lance(orsurrealdb) and the correspondingdb_path/ connection settings. Routing a truememory://URI to the SQLite+LanceDB stack is tracked for v0.10.
Observability
khora emits OpenTelemetry spans and metrics through the OTel API.
The export path is your choice: vanilla OTel SDK (pip install khora[otel]), Logfire
(pip install khora[logfire]), or nothing (zero-cost no-op). Khora
never installs a TracerProvider at import time and never sets
service.name — those belong to the host application.
pip install khora[otel]
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
export OTEL_SERVICE_NAME="my-app"
from khora.telemetry import configure_telemetry
configure_telemetry() # honors OTEL_* env vars
See docs/observability.md for the full env-var
contract, the precedence rules, vendor recipes (Honeycomb, Datadog,
Tempo, etc.), sampling guidance, and the troubleshooting checklist.
The complete telemetry surface lives in
docs/telemetry-contract.json with the
drift gate enforced by tests/unit/telemetry/test_contract.py.
Two separate observability channels live in khora.telemetry:
- Spans + metrics via the OTel API (this section).
- Structured
LLMEvent/StorageEvent/PipelineEventrows to a dedicated PostgreSQL database whenKHORA_TELEMETRY_DATABASE_URLis set. Without it, aNoOpCollectoris used (zero cost). Wired byinit_telemetry(), independent ofconfigure_telemetry().
Credential fields on KhoraConfig (DSNs, passwords) are
pydantic.SecretStr — repr() and config dumps render as
'**********'. Callers that need the cleartext must call
.get_secret_value() explicitly.
Async logging caveat. Library consumers that import khora without
configuring loguru sinks inherit the default sync stderr sink, which
blocks the event loop on every log call inside async def. Either
call khora.logging_config.setup_logging() (which configures sinks
with enqueue=True and registers an atexit drain) or configure
your own loguru sinks with enqueue=True explicitly.
Documentation
Start at docs/README.md. Key entry points:
- API reference — public
Khorasurface. - Configuration —
KHORA_*env vars andKhoraConfig. - Observability — OTel spans/metrics,
[otel]/[logfire]paths,configure_telemetry(). - Architecture — how the pieces fit.
- Engines — VectorCypher, Skeleton, Chronicle.
- Migrations — Alembic workflow for library users.
- Downstream consumers — sibling packages and integration guide.
Development
make dev # start PostgreSQL + Neo4j (Docker)
make test # pytest with coverage
make format # ruff format + isort
make lint # ruff + ty typecheck
See CHANGELOG.md for release history.
License
Copyright 2026 AllTheData Inc.
Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.
Project details
Release history Release notifications | RSS feed
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 khora-0.11.2.tar.gz.
File metadata
- Download URL: khora-0.11.2.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4563ec4aa1ea4bf9d9cee19108eccf6084d20aca392bbc98a0f68129b0b17004
|
|
| MD5 |
0b07a33b400517a3290be6b970eb8d64
|
|
| BLAKE2b-256 |
3068253fdc72fd3cdf525bc82f66ffdfbc5c58939457b2352e9cd859d1ba386a
|
Provenance
The following attestation bundles were made for khora-0.11.2.tar.gz:
Publisher:
release.yml on DeytaHQ/khora
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
khora-0.11.2.tar.gz -
Subject digest:
4563ec4aa1ea4bf9d9cee19108eccf6084d20aca392bbc98a0f68129b0b17004 - Sigstore transparency entry: 1535824715
- Sigstore integration time:
-
Permalink:
DeytaHQ/khora@e86a4ff50012e53f941259415e00227824afb5e4 -
Branch / Tag:
refs/tags/v0.11.2 - Owner: https://github.com/DeytaHQ
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e86a4ff50012e53f941259415e00227824afb5e4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file khora-0.11.2-py3-none-any.whl.
File metadata
- Download URL: khora-0.11.2-py3-none-any.whl
- Upload date:
- Size: 775.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d6bf2d921687f601162da28be6662875675425778777dabc27da7c395c3a391
|
|
| MD5 |
3f01b9468e46c8d8dc4f60875ed2b242
|
|
| BLAKE2b-256 |
5810d8978e569ec5414e3c06d24a56a02760f0e50a163d09ef6ad2ce9e86f34d
|
Provenance
The following attestation bundles were made for khora-0.11.2-py3-none-any.whl:
Publisher:
release.yml on DeytaHQ/khora
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
khora-0.11.2-py3-none-any.whl -
Subject digest:
8d6bf2d921687f601162da28be6662875675425778777dabc27da7c395c3a391 - Sigstore transparency entry: 1535824892
- Sigstore integration time:
-
Permalink:
DeytaHQ/khora@e86a4ff50012e53f941259415e00227824afb5e4 -
Branch / Tag:
refs/tags/v0.11.2 - Owner: https://github.com/DeytaHQ
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e86a4ff50012e53f941259415e00227824afb5e4 -
Trigger Event:
push
-
Statement type: