Never pay twice for an LLM call.
Never serve a stale answer.

Blind semantic similarity is dangerous in production. MemoLM sits between your application and upstream LLMs (Groq, OpenAI, Gemini), subjecting every candidate match to an explainable Safety Gate before returning it in ~18ms.

terminal
$npm install @memolm/sdk
~18ms
Safe Hit Latency
vs 1,200ms cold LLM
100%
Version Isolation
Zero stale docs served
>85%
Token Reductions
On repeated semantics
Fail-Open
Zero Outage Guarantee
Automatic upstream direct
Interactive Safety Gate Console

Trace the Gate in Real-Time

Experience how MemoLM distinguishes safe semantic paraphrases from dangerous stale documentation leaks.

Safe cache hits
0
Session hit rate
0%
Latency saved
0.00s
Cost avoided
$0.000
ver:
MemoLM Gateway initialized. Select a scenario preset below or submit any prompt to trace the Safety Gate decision in real-time.
Gate Diagnostics
Run a scenario preset above to inspect the Safety Gate trace.
Production Failure Modes

Why Naive Semantic Caching Breaks

Raw vector retrieval assumes similarity equals safety. Here is why enterprise teams replace raw vector caches with the MemoLM Firewall.

Naive Vector Caches (Unsafe)
MemoLM Response Firewall
Stale Documentation & Deprecated Policies

Blind vector caches continue serving outdated v12 return/pricing policies for weeks after business documentation updates.

MemoLM Resolution

Bump knowledge_version tag (v12 ➔ v13). The Safety Gate immediately blocks stale candidates with zero database purges.

Cross-Tenant Data & Prompt Bleed

Vector similarity has no concept of tenant boundaries. High-similarity queries cross organizations, leaking internal company data.

MemoLM Resolution

Every vector search applies cryptographic tenant isolation at the query execution level. Never crosses tenant partitions.

Hallucinated Output Permanence

Once an LLM hallucinates an erroneous response, a naive cache stores it forever, repeatedly poisoning customer conversations.

MemoLM Resolution

Dynamic semantic TTL assigns zero-caching to high-risk domains and enforces strict similarity margins on sensitive categories.

Unexplainable Black Box Failures

When a customer complains about an incorrect answer, engineers have zero visibility into why the cache triggered or similarity scores.

MemoLM Resolution

Every response returns explicit telemetry: cosine similarity, required threshold, latency saved, and itemized safety gate verdicts.

Core Pipeline

How MemoLM Works

A deterministic, low-overhead pipeline ensuring no response is served without verified safety credentials.

OpenAI-Compatible

01. Request Interception

Inbound requests target https://memolm.onrender.com/v1/chat/completions. The gateway strips MemoLM headers and passes prompts down-pipeline.

Exact + Qdrant Vectors

02. Dual-Tier Retrieval

Sub-5ms exact hash lookup runs concurrently with Qdrant vector retrieval, enforcing strict tenant isolation filters.

Constraint Firewall

03. The Safety Gate

Verifies candidate match against Knowledge Version, TTL expiration, tenant boundary, and domain risk margin.

Sub-20ms or Writeback

04. Return or LLM Fallback

Verified hits return in ~18ms with 0 tokens billed. Stale or miss queries route to Groq/OpenAI with automatic writeback.

Pipeline Execution Spec: 03. The Safety Gate
Stage 3 of 4
// The Safety Gate Constraints
candidate = qdrant.search(embedding, filter=tenant_filter)
if candidate.payload.version != requested.version:
    return REJECT("knowledge_version_mismatch")
if now() > candidate.payload.created_at + candidate.payload.ttl:
    return REJECT("ttl_expired")
if candidate.score < risk_margin(requested.risk):
    return REJECT("similarity_below_margin")
return SAFE_CACHE_HIT
Production Architecture

Built for High-Throughput Workloads

Everything your engineering team needs to safely cache generative AI responses without operational surprises.

The Multi-Point Safety Gate

Every candidate is evaluated against Knowledge Version, TTL validity, tenant ownership, and risk policies before serving.

x-memolm-version: "v12"

Dual-Tier Latency Optimization

Sub-5ms exact deterministic match for repeated prompts; sub-20ms semantic vector search in Qdrant for natural paraphrases.

p99_latency: 18ms

Multi-Tenant Namespace Isolation

Partition vector collections by customer, organization, or user. Data never crosses tenant boundaries under any similarity score.

tenant_id: "acme-corp"

Zero-Downtime Cache Invalidation

Increment your version tag (v12 ➔ v13). Outdated records are safely blocked in milliseconds without expensive database purges.

invalidation_overhead: 0ms

100% Fail-Open Reliability

If the MemoLM gateway ever becomes unreachable, SDKs automatically fail open directly to your upstream LLM. Zero outage risk.

fallback_to_upstream: True

Explainable Decision Audit Stream

Programmatically inspect why every candidate passed or was rejected with similarity scores, latency speedups, and audit logs.

response.memolm_stats
Multi-Language SDK & API Reference

Integrate in 60 Seconds

Type-safe Python and TypeScript SDKs, 1-line OpenAI drop-in wrappers, and direct HTTP proxies with explainable Safety Gate stats.

Select Upstream Model Target:
Updates code snippets below dynamically
1# 1. Drop-in OpenAI Wrapper (1-Line Zero Code Rewrite)
2from openai import OpenAI
3from memolm import wrap_openai
4
5# Initialize standard OpenAI client and wrap it
6openai_client = OpenAI(api_key="your-api-key")
7
8client = wrap_openai(
9 openai_client,
10 gateway_url="https://memolm.onrender.com",
11 knowledge_version="v12", # Prevents serving outdated answers
12 tenant_id="acme-corp", # Strict tenant vector isolation
13 risk="low", # Risk level policy ('low' | 'medium' | 'high')
14 fallback_to_upstream=True # Fails open to OpenAI if MemoLM gateway is offline
15)
16
17# Standard call sites remain 100% untouched
18response = client.chat.completions.create(
19 model="openai/gpt-oss-20b",
20 messages=[
21 {"role": "system", "content": "You are a customer support specialist."},
22 {"role": "user", "content": "What is the return and refund policy?"}
23 ],
24 temperature=0.7,
25 max_tokens=500
26)
27
28# Access response content
29print(response.choices[0].message.content)
30
31# Access MemoLM explainability statistics
32if hasattr(response, "memolm_stats") and response.memolm_stats:
33 print(f"Safety Verdict: {response.memolm_stats.verdict}")
34 print(f"Similarity: {response.memolm_stats.similarity:.3f}")
35 print(f"Latency Saved: {response.memolm_stats.latency_saved}s")
36 print(f"Cost Incurred: $" + "{response.memolm_stats.cost_incurred}")
37
38# Print cumulative session ROI metrics
39print(client.get_session_metrics())
40# => Total: 12 | Hits: 10 (83.3%) | Latency Saved: 11.2s | Cost Saved: $0.052
Keywords Functions Strings Parameters Classes
Selected: openai/gpt-oss-20b

SDK Parameter & Policy Reference

Supports sync, async & streaming across all providers
modelstring

Target model ID across Groq, OpenAI, Gemini, or Anthropic.

Default: "openai/gpt-oss-20b"
knowledge_versionstring

Prevents stale data. Bumping version instantly invalidates outdated cache entries.

Default: "v1"
tenant_idstring

Enforces strict tenant namespace isolation in vector storage.

Default: "default-tenant"
risk"low" | "medium" | "high"

Controls Safety Gate strictness. High risk enforces tighter similarity cutoff.

Default: "low"
similarity_thresholdfloat (0.0 - 1.0)

Minimum cosine similarity score required for a semantic cache hit.

Default: 0.85
force_refreshboolean

Bypasses cache lookup, calls upstream LLM fresh, and updates cache.

Default: false
cache_onlyboolean

Guaranteed $0 cost. If not in cache, raises CacheMissError without billing LLM.

Default: false
fallback_to_upstreamboolean

Zero-downtime fail-open: routes directly to LLM if gateway is unreachable.

Default: true
Economic Impact

Calculate Your Cloud LLM Savings

Estimate direct inference bill reductions and user latency saved across your production stack.

Monthly Inbound Queries:500,000
50k2.5M5M
Target Cache Hit Ratio:45%
10% (Sparse)45% (Typical Support)80% (High Repetition)
Average Tokens per Query:1200 tokens
3002,0004,000
Estimated Monthly Savings
$4,050 / mo
Projected Annual ROI: $48,600 / yr
End-User Wait Time Saved
74 hours / mo
Replaces ~1.2s cold model wait times with ~18ms deterministic vector responses.
Architecture FAQ

Frequently Asked Questions

MemoLM is architected with a strict Fail-Open guarantee. Both the Python and TypeScript SDKs (and wrap_openai) intercept connection drops and transparently route requests directly to your primary LLM provider (Groq, OpenAI, or Gemini) without throwing exceptions to your end-users.