We are currently building something exciting and will be launching soon. Registration is temporarily closed. Launching soon — registration temporarily closed.

Integrations / Redis
Streaming & Data Infrastructure Architecture guide

Redis × Sentiqra

Cache repeated deterministic classifications when your workload contains identical requests. For reproducible behavior, cache keys should include the input and all versioned parameters that can affect the classification.

Integration: Version-aware result cache Vendor: Redis Ltd. License: RSALv2 / SSPL GitHub → Official Docs →

Why This Integration Matters

Operational question this answers:

"Can we cache identical requests to reduce cost?"

High-volume buyers processing millions of messages per day ask: "can we cache identical requests to reduce cost?" Because Sentiqra's outputs are deterministic - the same input under the same pinned configuration and output profile always produces the same analysis - a cached result is provably the same analysis, not merely a stored answer. The cache hit carries the same fingerprint and configuration ID as a fresh call.

Redis is the industry standard for in-memory caching. By caching Sentiqra detection results by input hash, high-volume buyers can cut API costs meaningfully when the same content is submitted repeatedly. The achievable hit rate depends entirely on your duplication pattern - reply chains, forwarded messages, and duplicate abuse reports are the main sources - so measure your own traffic rather than budgeting against a published figure.

Reference Architecture

┌──────────────────────────────────────────────────────────────┐
│                Your Infrastructure                           │
│                                                               │
│  ┌──────────┐    ┌──────────────┐                             │
│  │  Request  │───▶│ Hash input   │                             │
│  │  (text +  │    │ SHA-256(text │                             │
│  │  language)│    │ + language)  │                             │
│  └──────────┘    └──────┬───────┘                            │
│                         │                                     │
│                  ┌──────▼───────┐                            │
│                  │ Redis Lookup │                            │
│                  │ GET hash:key │                            │
│                  └──────┬───────┘                            │
│                         │                                     │
│              ┌──────────┴──────────┐                         │
│              │                     │                         │
│         Cache HIT             Cache MISS                     │
│              │                     │                         │
│     ┌────────▼────────┐   ┌────────▼────────┐               │
│     │ Return cached   │   │ Call Sentiqra   │               │
│     │ result (<1ms)   │   │ API (~500ms)    │               │
│     └─────────────────┘   │                 │               │
│                           │ Cache result:   │               │
│                           │ SET hash:key    │               │
│                           │ TTL: 24h        │               │
│                           └─────────────────┘               │
│                                                               │
│  Cache hit rate: workload-dependent (measure yours)          │
│  API figure is the published p95 latency target.             │
└──────────────────────────────────────────────────────────────┘

Data flow: Your application hashes the input text + language → checks Redis for a cached result → on cache hit, returns the cached detection in <1ms → on cache miss, calls Sentiqra API and caches the result with a 24h TTL. Because Sentiqra is deterministic, cached results are always valid - no stale or inconsistent results.

Working Code

Actual, tested, copy-pasteable code. Not pseudocode. Not aspirational.

Python - Redis Cache + Sentiqra

import hashlib
import json
import os
import redis
import requests

cache = redis.Redis(host="localhost", port=6379, db=0)
CACHE_TTL = 86400  # 24 hours

# Pin the detection configuration version in app config - the cache key
# includes it, so a taxonomy upgrade invalidates old entries automatically.
CONFIG_ID = os.environ["SENTIQRA_CONFIG_ID"]  # e.g. "sqcfg_ZZW77NM9"

def analyze_with_cache(text: str, language: str = "en") -> dict:
    # 1. Hash input + pinned config for the cache key
    key = f"sentiqra:{CONFIG_ID}:{hashlib.sha256(f'{text}:{language}'.encode()).hexdigest()}"

    # 2. Check cache
    cached = cache.get(key)
    if cached:
        return json.loads(cached)

    # 3. Cache miss - call Sentiqra
    response = requests.post(
        "https://sentiqra.tech/v1/analyze",
        headers={
            "Authorization": f"Bearer {os.environ['SENTIQRA_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={"text": text, "language": language, "analyzers": ["trust-safety"]},
        timeout=10,
    )
    data = response.json()

    # 4. Cache the result (deterministic under the pinned config - always valid)
    cache.setex(key, CACHE_TTL, json.dumps(data))

    return data

# Usage - first call hits Sentiqra, second call hits cache
r1 = analyze_with_cache("you are a worthless idiot")  # ~500ms (API p95 target)
r2 = analyze_with_cache("you are a worthless idiot")  # <1ms (cache hit)

JavaScript / Node.js - Redis Cache + Sentiqra

import { createClient } from "redis";
import crypto from "crypto";

const cache = createClient({ url: "redis://localhost:6379" });
await cache.connect();

const CACHE_TTL = 86400; // 24 hours
// Pin the detection configuration version - included in the cache key so a
// taxonomy upgrade invalidates old entries automatically.
const CONFIG_ID = process.env.SENTIQRA_CONFIG_ID; // e.g. "sqcfg_ZZW77NM9"

async function analyzeWithCache(text, language = "en") {
  const key = `sentiqra:${CONFIG_ID}:${crypto
    .createHash("sha256")
    .update(`${text}:${language}`)
    .digest("hex")}`;

  const cached = await cache.get(key);
  if (cached) return JSON.parse(cached);

  const response = await fetch("https://sentiqra.tech/v1/analyze", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SENTIQRA_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ text, language, analyzers: ["trust-safety"] }),
  });
  const data = await response.json();

  await cache.set(key, JSON.stringify(data), { EX: CACHE_TTL });
  return data;
}

Install dependencies

# Python
pip install redis requests

# JavaScript
npm install redis

Security & Compliance Posture

  • ✓
    Deterministic Caching: Sentiqra's outputs are deterministic - the same input under the same pinned configuration and output profile produces the same analysis. A cached result is the same attested analysis for that configuration, carrying the same fingerprint and configuration ID.
  • ✓
    Cost Reduction: Cache hits avoid repeat API calls entirely. The hit rate depends on your workload's duplication pattern (reply chains, forwarded messages, duplicate reports) - measure yours before budgeting savings.
  • ✓
    Latency Improvement: Cache hits return in <1ms vs the published API p95 target of 500ms. For user-facing moderation, this reduces the perceived latency of content screening.
  • ✓
    No PII in Cache Keys: The cache key is a SHA-256 hash of the input text - the raw text is never stored in Redis. Only the detection result (harmful, group, confidence) is cached.
  • ✓
    Configuration Pinning Safety: Include the detection configuration ID in the cache key prefix to ensure cached results are invalidated when the pinned configuration changes.

Deployment Notes

Cache Key Design

Use sentiqra:{sha256(text:language)} as the cache key. Include the language code in the hash because the same text may have different detections in different languages. Prefix with the detection configuration ID for easy invalidation - cached entries are invalidated whenever the configuration changes.

TTL Strategy

Set a 24-hour TTL. Because Sentiqra is deterministic, the TTL is not for freshness - it's for memory management. The result doesn't expire; the cache entry is evicted to manage Redis memory usage.

Expected Hit Rate

Hit rate depends entirely on your workload's duplication pattern - reply chains, forwarded messages, and duplicate abuse reports are the main sources. Highly duplicative workloads can reach 30–60% or more; measure yours with Redis Monitor hit rate via Redis INFO stats.

Memory Sizing

Each cached detection is ~200 bytes. For 10M unique texts/day with 24h TTL, you need ~2GB of Redis memory. Use Redis with maxmemory and allkeys-lru eviction policy for automatic management.

Cost

Redis Open Source is free. Redis Cloud starts at $30/month for 250MB. The savings from reduced Sentiqra API calls typically far exceed the Redis cost - at Production tier pricing (~$0.0015/call; see pricing), a 40% hit rate on 1M calls/day saves roughly $600/day.

Questions about this integration?

Talk to Solutions Engineering - first response within 1 business day.

Talk to Solutions Engineering →

Related Integrations