Skip to main content

Semantic memory for LLM agent calls with an equivalence-first cache architecture.

Project description

SmartMemo

SmartMemo is a portfolio-grade implementation of semantic caching for LLM agent calls. The project thesis is simple: cosine similarity is a useful candidate selector, but it is not semantic equivalence. The production version should use a learned equivalence classifier to decide cache hits.

This first implementation deliberately ships the baseline first:

  • async SmartMemo.get_or_call(...)
  • SQLite persistence
  • embedding provider protocol
  • FAISS-backed vector search when smartmemo[ml] is installed
  • dependency-light in-memory search for tests and smoke demos
  • measured cosine-baseline benchmark fixtures for customer-support prompts
  • classifier training and evaluation scaffolding for the next phase

The classifier fields are present in the public result shape, but classifier_score is None in the cache path. That keeps the API ready for the learned judge without pretending a production classifier has been trained or integrated.

Install

pip install smartmemo
pip install "smartmemo[ml]"

For local development:

uv sync --all-extras
uv run pytest
uv run ruff check
uv run pyright

Minimal Example

from smartmemo import SmartMemo

cache = SmartMemo(domain="customer-support")

async def call_llm(prompt: str) -> str:
    return "fresh LLM response"

result = await cache.get_or_call(
    prompt="Summarize this customer's latest billing ticket",
    llm_function=call_llm,
)

print(result.response)
print(result.was_cache_hit)

Baseline Benchmark

The customer-support benchmark is intentionally designed to show the baseline failure mode: prompts about the same object can require opposite actions.

uv run python benchmarks/cosine_baseline_customer_support.py

The numbers from that benchmark are the only performance claims this implementation makes.

Classifier Pipeline

Phase 2 adds a trainable pair classifier over prompt embeddings:

uv run smartmemo train-classifier \
  --data data/fixtures/customer_support_pairs.jsonl \
  --out models/classifier-smoke.pt \
  --embedding-provider hash \
  --embedding-dim 64 \
  --epochs 2

Use the hash provider only for smoke checks. Real experiments should install smartmemo[ml] and use the SentenceTransformers embedding provider.

Release

Version 0.0.1 is configured for PyPI as smartmemo. The repository publishes through GitHub Actions trusted publishing from .github/workflows/publish-pypi.yml with the pypi environment.

git tag v0.0.1
git push origin v0.0.1

That tag builds the source distribution and wheel, then uploads them to PyPI.

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

smartmemo-0.0.1.tar.gz (122.0 kB view details)

Uploaded Source

Built Distribution

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

smartmemo-0.0.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file smartmemo-0.0.1.tar.gz.

File metadata

  • Download URL: smartmemo-0.0.1.tar.gz
  • Upload date:
  • Size: 122.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smartmemo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 390449f714a8a6ae80d38eae30f1fea92c62a39097dffc0eb0b82ec3fe76c331
MD5 934ba3a3041184d7d6e45ac8ad9b6bc2
BLAKE2b-256 ff5b3da4f41ff48b80a5b77cdcd12b203c80b0b121e19b9e11b0574ab0561a50

See more details on using hashes here.

Provenance

The following attestation bundles were made for smartmemo-0.0.1.tar.gz:

Publisher: publish-pypi.yml on awesome-pro/smartmemo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smartmemo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: smartmemo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smartmemo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00b7e5d581ce536af195d414372137326636ada9491d99630058fec4566dce3d
MD5 4029a4e154ecdc931b157c417bf2fa3d
BLAKE2b-256 7a1d6a9f52cd9a85c4bd224862bb7e464091eafc12f90c9905f405728d5bfbb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for smartmemo-0.0.1-py3-none-any.whl:

Publisher: publish-pypi.yml on awesome-pro/smartmemo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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