Skip to main content

Multi-layer Redis caching + Huffman disk archival for conversational AI — session memory, semantic deduplication, and compressed storage

Project description

lix-open-cache

Standalone multi-layer caching and session management for conversational AI. Works with just Redis — no server needed.

pip install lix-open-cache

Quick Start

from lix_open_cache import CacheConfig, CacheCoordinator

config = CacheConfig(redis_host="localhost", redis_port=6379)
cache = CacheCoordinator(session_id="user-abc", config=config)

# Store & retrieve conversation context
cache.add_message_to_context("user", "What's the weather in Tokyo?")
cache.add_message_to_context("assistant", "22C and sunny.")
history = cache.get_context_messages()

# Semantic cache — skip LLM on similar queries
import numpy as np
embedding = np.random.rand(384).astype(np.float32)
cached = cache.get_semantic_response("https://weather.com", embedding)

Three Cache Layers

Layer Purpose Backend TTL
Session Context Window Rolling 20-message window + disk overflow Redis DB 2 + .huff files 24h
Semantic Query Cache Deduplicate similar queries (cosine >= 0.90) Redis DB 0 5 min
URL Embedding Cache Cache embedding vectors per URL Redis DB 1 24h

Key Features

  • Two-tier hybrid storage — Redis hot window + Huffman-compressed disk archive
  • LRU eviction daemon — auto-migrates idle sessions to disk, re-hydrates on return
  • smart_context() — recent messages + semantically relevant history from disk
  • Pure Python Huffman codec — ~54% compression, zero native dependencies
  • CacheConfig dataclass — all tunables in one place, 12-factor env var support

Dependencies

Only 3: redis, numpy, loguru

Research Paper

A Three-Layer Caching Architecture for Low-Latency LLM Web Search on Commodity CPU Hardware Ayushman Bhattacharya, 2026 Read the paper

License

MIT

Project details


Download files

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

Source Distribution

lix_open_cache-2.1.6.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

lix_open_cache-2.1.6-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file lix_open_cache-2.1.6.tar.gz.

File metadata

  • Download URL: lix_open_cache-2.1.6.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lix_open_cache-2.1.6.tar.gz
Algorithm Hash digest
SHA256 3a7bc8910811dfb453e1d6ef57b49988c00b86738fa0126f6f4321af260683b5
MD5 24b5ea66d793ebbec1450d70ad1f8eb6
BLAKE2b-256 93932431fbdce5e66150b18d75439c98ce6b17409130c61260d34dc2a24914ee

See more details on using hashes here.

File details

Details for the file lix_open_cache-2.1.6-py3-none-any.whl.

File metadata

  • Download URL: lix_open_cache-2.1.6-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lix_open_cache-2.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 186412b1bc9c16749b8b1960cbe92aaa0169dd78b42f823cde639de2659500c5
MD5 1674ff4c1aeee922c351967761505bda
BLAKE2b-256 fd07b9e09cf8385bda4c194a39dc1e1c4cef8175caee5c8a73c30c06bf80a016

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