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

81 lines
2.8 KiB
TOML

[package]
name = "gateway"
version.workspace = true
rust-version.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
tensorzero-core = { path = "../tensorzero-core" }
tensorzero-optimizers = { path = "../tensorzero-optimizers" }
evaluations = { path = "../evaluations" }
relay-aitp = { path = "../relay-aitp" }
relay-billing = { path = "../relay-billing" }
relay-catalog = { path = "../relay-catalog" }
relay-contract = { path = "../relay-contract" }
relay-cost-feed = { path = "../relay-cost-feed" }
relay-guardrails = { path = "../relay-guardrails" }
relay-semantic-cache = { path = "../relay-semantic-cache" }
relay-hedge = { path = "../relay-hedge" }
relay-storage-postgres = { path = "../relay-storage-postgres" }
relay-traces = { path = "../relay-traces" }
reqwest.workspace = true
async-trait = { workspace = true }
axum = { workspace = true }
tracing = { version = "0.1.43", features = ["log", "release_max_level_debug"] }
tokio = { workspace = true }
tokio-util = { workspace = true }
mimalloc = "0.1.50"
clap = { workspace = true }
tower-http = { workspace = true, features = ["metrics", "decompression-gzip", "decompression-br", "decompression-zstd"] }
metrics-exporter-prometheus = { workspace = true }
http = { workspace = true }
futures = { workspace = true }
tokio-stream = { workspace = true }
tensorzero-auth = { path = "../tensorzero-auth" }
autopilot-client = { path = "../autopilot-client" }
autopilot-worker = { path = "../autopilot-worker" }
autopilot-tools = { path = "../autopilot-tools" }
durable-tools = { path = "../durable-tools" }
tensorzero-mcp = { path = "../tensorzero-mcp" }
sqlx = { workspace = true }
secrecy = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
uuid = { workspace = true }
ts-rs.workspace = true
async-stream = { workspace = true }
http-body-util = { workspace = true }
base64 = "0.22.1"
hex = "0.4"
ring = "0.17"
[lints]
workspace = true
[features]
e2e_tests = ["tensorzero-core/e2e_tests", "autopilot-worker/e2e_tests", "autopilot-tools/e2e_tests", "tensorzero-mcp/e2e_tests"]
default = []
[dev-dependencies]
googletest = { workspace = true }
rmcp = { version = "1.7.0", features = [
"client",
"transport-streamable-http-client-reqwest",
] }
tempfile = { workspace = true }
tensorzero = { path = "../tensorzero-client", features = ["e2e_tests"] }
serde_json = { workspace = true }
reqwest-sse-stream = { workspace = true }
futures = { workspace = true }
secrecy = { workspace = true }
uuid = { workspace = true }
tensorzero-unsafe-helpers = { path = "../tensorzero-unsafe-helpers" }
tower = { version = "0.5.3", features = ["util"] }
chrono = { workspace = true }
flate2 = "1.1.8"
zstd = "0.13.3"
brotli = "8.0.2"
hyper = { version = "1.9.0", features = ["client", "server", "http1"] }
hyper-util = { version = "0.1.19", features = ["tokio"] }