Skip to main content

High-performance LLM prompt optimization library

Project description

kkachi-python

Python bindings for the kkachi LLM optimization library.

Installation

pip install kkachi

Usage

from kkachi import Signature, Example

sig = Signature("question -> answer")
ex = Example({"question": "What is 2+2?", "answer": "4"})

Memory / RAG with Persistent Storage

The Memory class provides a vector store for RAG (Retrieval-Augmented Generation) with full CRUD operations and optional persistent storage using DuckDB.

Basic Usage (In-Memory)

from kkachi import Memory

# Create in-memory store
mem = Memory()

# CREATE: Add documents
doc_id = mem.add("Document content here")
mem.add_with_id("custom-id", "Another document")
mem.add_tagged("category", "Tagged document")

# READ: Retrieve documents
content = mem.get(doc_id)
results = mem.search("query text", k=3)

# UPDATE: Modify existing documents
mem.update(doc_id, "Updated content")

# DELETE: Remove documents
mem.remove(doc_id)

Persistent Storage

Enable DuckDB-backed persistent storage to preserve data across program restarts:

from kkachi import Memory

# Create or open a persistent database
mem = Memory().persist("./my_rag_db.db")

# Add documents (persists to disk)
mem.add("Important knowledge that survives restarts")
mem.add("More documents here")

# Data persists across program runs
results = mem.search("knowledge", k=3)

# Close and reopen
del mem
mem = Memory().persist("./my_rag_db.db")  # Data is still there!

The database file will be created if it doesn't exist. Subsequent calls to .persist() with the same path will reopen the existing database.

Requirements:

  • The storage feature is enabled by default in pip package
  • DuckDB native library (usually handled automatically)

Complete Example

See examples/memory_persist.py for a complete demonstration of CRUD operations with persistent storage.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kkachi-0.1.0-cp312-cp312-win_amd64.whl (12.5 MB view details)

Uploaded CPython 3.12Windows x86-64

kkachi-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

kkachi-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl (12.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

kkachi-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kkachi-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file kkachi-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kkachi-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 12.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kkachi-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b13c58c3afbb0bcbe1e94d28f56d9e4106b82cc625cf9c8c9dde5fb5d5def859
MD5 346bb4628622ef93d0d9a37a73c4deda
BLAKE2b-256 e39b0e7beca7ff8aa4d76e80cf1a52975e99c260b0f40c41671ab4ede666087d

See more details on using hashes here.

File details

Details for the file kkachi-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kkachi-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4f05b1d89dff5672f631312b016d380e60654ffd873642dfe9149f67a6cb3848
MD5 2ad3295e64973fdff925685c18e374bb
BLAKE2b-256 a25ce5bba53297cbecf5852084f429e9aefce947a3ba0533de3557b9430b87dd

See more details on using hashes here.

File details

Details for the file kkachi-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for kkachi-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 195c177d3c879335cf82dbe2ea68dc3fee452d46d468f5988f3c629e97c7dcb7
MD5 8eea16c9305fa83c840023d240edd83a
BLAKE2b-256 0f0878fd539b03cd499c470c23aa7dcdf2709a411f88480c2cddb8f02e7d7830

See more details on using hashes here.

File details

Details for the file kkachi-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kkachi-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f31ebab2881246a33d43b8d58a87a4c342032cb858fed1942e0f279c0fc3d20b
MD5 de3ea0e98e7c74c90c4b01db9126a768
BLAKE2b-256 b9d9de87cbfc131184a586879a21e1f4ca390ec82ade7fe7d8cf48c7388add1f

See more details on using hashes here.

File details

Details for the file kkachi-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kkachi-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e8fb9052186f6d36e871520d764b7b4df8c1ca0d9ded2f0140f09960e89dea00
MD5 ff6f6c2b54e76ff68f27cfe955a246f9
BLAKE2b-256 8b220c5a4894463c78249ef6318890cb2f708273e3baa4cae5cf131a4a736474

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page