caelum0x a0ca357f40 feat(relay): semantic response cache with pgvector, TTL and tenant isolation
New relay-semantic-cache crate: chat requests split into a scope (hash of
model, sampling, tools, format) and an embedded prompt; a stored answer is
reused when tenant and scope match, cosine similarity clears the
threshold and it has not expired. Embeddings come from a local hashed
n-gram embedder or any OpenAI-compatible embeddings route (Relay's own
included); stores are in-memory or pgvector. The gateway mounts it inside
guardrails and outside spend caps and billing when RELAY_SEMANTIC_CACHE is
memory or pgvector, keyed by organization/workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:34:49 +03:00

26 lines
723 B
TOML

[package]
name = "relay-semantic-cache"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
description = "Relay semantic response cache: embeddings (local or over Relay's own embeddings route), a pluggable vector store (memory or pgvector), TTL and per-tenant isolation."
[lib]
path = "src/lib.rs"
[dependencies]
async-trait = { workspace = true }
axum = { workspace = true }
http-body-util = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10"
sqlx = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
[dev-dependencies]
tokio = { workspace = true }
tower = { version = "0.5.3", features = ["util"] }