Metadata-Version: 2.4
Name: semantic-redis-cache
Version: 0.1.0
Summary: Semantic caching wrapper for Redis — stop paying for duplicate LLM calls
Project-URL: Homepage, https://github.com/ausaf/semcache
Project-URL: Repository, https://github.com/ausaf/semcache
Project-URL: Issues, https://github.com/ausaf/semcache/issues
Author-email: Ausaf <kausaf141@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Ausaf
        
        Permission is hereby granted, free of charge,
        to any person obtaining a copy of this software
        to deal in the Software without restriction,
        including the rights to use, copy, modify, merge,
        publish, distribute, sublicense, and/or sell copies.
        
        THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
        OF ANY KIND.
License-File: LICENSE
Keywords: ai,cache,embeddings,llm,nlp,redis,semantic,vector
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.8
Requires-Dist: numpy>=1.21.0
Requires-Dist: redis>=4.0.0
Requires-Dist: sentence-transformers>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# semcache

Semantic caching for Redis.
Stop paying for duplicate LLM calls.

## The Problem

Traditional caching misses similar queries:
"what is monthly revenue?"  → cache miss ❌
"show me monthly revenue"   → cache miss ❌
"monthly revenue figures?"  → cache miss ❌

All three mean the same thing.
You pay for 3 LLM calls instead of 1.

## The Solution

semcache uses sentence embeddings to find
semantically similar cached responses.
Zero cost embeddings — runs locally.

## Install

pip install semcache

## Quick Start

from semcache import SemanticRedisCache

cache = SemanticRedisCache(threshold=0.85)

result = cache.get_or_set(
    query="what is monthly revenue?",
    func=your_llm_function,
    question="what is monthly revenue?"
)

print(result.value)       # LLM response
print(result.hit)         # True/False
print(result.similarity)  # 0.91
print(cache.metrics)      # hit rate, counts

## Results

→ 65-70% cache hit rate on real workloads
→ Zero cost embeddings (local model)
→ Works with any LLM
→ Drop-in Redis wrapper

## Configuration

cache = SemanticRedisCache(
    host="localhost",       # Redis host
    port=6379,              # Redis port
    threshold=0.85,         # similarity threshold
    ttl=86400,              # cache TTL in seconds
    model_name="all-MiniLM-L6-v2",  # embedding model
    namespace="semcache"    # Redis key namespace
)

## How It Works

1. Query arrives
2. Convert to embedding (local, free)
3. Search Redis for similar embeddings
4. Similarity > threshold → return cached response
5. Miss → call your LLM → store → return

## Contributing

PRs welcome. See CONTRIBUTING.md.

## License

MIT