← Back to TahsinReza.com
40x Token Cost Reduction
MIT Open Source License
BM25 Ranked Retrieval

What is TAH?

TAH (Take a Hint) is a binary knowledge cartridge standard invented by Tahsin Reza. It encodes domain expertise locally so language models can retrieve targeted knowledge without loading massive context windows.

File Architecture

.tah -- Self-contained binary cartridge: Bloom filter, shard index, and payload shards (with provenance -- source URL, ingestion timestamp) all in one file. Byte-offset seeking for retrieval.
.hat -- Optional companion file (Memoria's "Atlas Handshake" packaging). Splits the Bloom filter and byte-offset index out of an existing .tah into their own binary file, leaving payload-only bytes behind.
BM25 -- Probabilistic ranking. Term-frequency + IDF scoring over retrieved shards.
Querying a 400-page computer architecture textbook via raw context injection costs ~$5.20 in tokens. Via a TAH cartridge: under $0.12. Same knowledge, 40x cheaper.
# Standard query invocation (BM25) python tah_query.py cartridge.tah "your query here" # Ranked top-N results python tah_search.py cartridge.tah "query" --top 5 # Cross-cartridge routing (unknown domain) python meta_query.py "query" --top 5

Design Patterns

Key architectural concepts from the SunsetWars and SunsetPulse repositories — patterns that emerge from using TAH in production systems.

Pattern

Domain Cartridge Isolation

Each specialized agent or worker gets its own private domain cartridge rather than a shared mega-context. A lead-scorer agent loads only lead-scoring knowledge; a neighborhood-explainer loads only neighborhood data. Cartridges are swapped at spawn time via a single query, not rebuilt per request. This enables horizontal scaling: many parallel specialized workers, each carrying exactly what they need and nothing they don't.

Architecture Isolation Scaling
Pattern

Spawn-Time Knowledge Assembly

Rather than maintaining a single large shared context or hard-coding prompts with domain facts, the TAH pattern assembles exactly the knowledge an agent needs at the moment it spawns — pulling the relevant shards from a cartridge, not reloading the full source. This decouples the knowledge base (which can grow) from the agent's context window (which must stay bounded). Changing domain knowledge means rebuilding the cartridge, not touching the agent code.

Spawn-Time Knowledge Decoupling Context Efficiency
Pattern

Cross-Cartridge Routing

When the right cartridge for a query isn't known in advance, meta_query.py routes the query across multiple cartridges simultaneously and returns the highest-ranked shards regardless of source. Useful for general-purpose agents that operate across several domains — they ask once and get back the best match from whichever cartridge actually contains the answer.

Routing Multi-Cartridge BM25

Bug Analysis & Fixes

Adversarial audit work that identified and corrected defects in the TAH retrieval implementation — including a critical BM25 ranking bug that caused degenerate results across all queries for an extended period.

Bug Fix

BM25 Ranker: Degenerate Shortest-Shard Return

Critical defect discovered and fixed (promoted to canonical path 2026-06-17): the BM25 query ranker returned the same shortest shard for every query regardless of content. Root cause: document frequency hardcoded to 0 and tf=1.0, meaning score depended on shard length alone. The correct fix (real term-frequency + per-term IDF) existed in the upstream repository but had never been deployed to the live query path.

Impact: Any conclusion drawn about TAH retrieval quality before 2026-06-17 was based on degenerate results. BM25 is now verified correct.

Bug Fix BM25 Ranking Critical

Deployments & Use Cases

Real-world integrations of the TAH standard across different domains and platforms, drawn from the public SunsetWars ecosystem and other implementations.

SunsetWars

Conversational AI with Local LLM Augmentation

SunsetWars includes production-ready integration scripts for Telegram bots powered by TAH cartridges backed by Ollama (local LLM), Groq (fast inference), and standard OpenAI-compatible endpoints. The pattern: a user message arrives via Telegram, triggers a TAH query for domain context, and that context is injected into the LLM prompt alongside the message. No full-document loading; no context overflow. All integration code is in the public repository.

Telegram Ollama Groq Local LLM
SunsetPulse

Real Estate Domain Intelligence

Tahsin's own flagship integration: private TAH cartridges encoding real estate domain knowledge (neighborhood data, comp analysis patterns, lead scoring heuristics) deployed inside SunsetPulse. Specialized Claude workers (lead-scorer, follow-up-writer, neighborhood-explainer, comp-analyst) each query their own private cartridge rather than loading raw context. Result: sub-second domain expertise at a fraction of the API cost.

Production SunsetPulse Real Estate Domain Cartridges
SunsetPulse

WorldofTah — Per-Character Micro-Shards for LLM Embodiment

An experimental game engine inside the SunsetPulse monorepo demonstrating TAH at its most granular: each character is a single tiny .tah shard. The game runs a village simulation where residents generate music (Strudel.cc patterns, produced via a local LLM) and vote each other out through a "Musical Tribunal" each round. The loser is banished by "THE SILENCE"; a replacement spawns. Ghosts of the banished persist as a separate character class.

The TAH pattern here is inverted from the knowledge-retrieval use case. Each shard does not encode a domain knowledge base — it encodes a single character's identity and accumulated history. At each game tick, the character's shard is loaded to seed the LLM prompt, allowing the model to become that character rather than merely know about them. Three TAH type variants cover distinct character classes:

TAH Type Variants in WorldofTah

TAH-AGRI -- Village residents & player session. Daily life logs, agricultural/resource activity.
TAH-EVOL -- Units / evolved characters. Accumulates social standing, punishments, suspicion level.
TAH-CINE -- Ghost characters. Cinematic biography; post-banishment identity preserved in a lightweight shard.

Because each shard is tiny (a single JSON object), loading a character's full context costs essentially nothing. The LLM receives exactly who this character is — name, role, recent history — and nothing else. State evolves each tick: punishments, credits lost, and suspicion accumulate in the shard over the game's lifetime.

Game Engine Character Embodiment Micro-Shards Ollama Strudel.cc State Persistence
MirrorArchive

Bread Factory Inferno — TAH-Grounded Game Assistant

A separate game-assistant scaffold built around Bread Factory Inferno, a desktop JRPG / management-horror prototype: an underground "miracle" bread factory that could end world hunger, but corrupts into metric-gaming, dehumanization, and weaponization when human attention drops. The in-world terminal assistant is TAH-backed — grounding an in-game AI character in structured cartridge knowledge rather than a free-floating prompt.

Game Engine JRPG Character AI
Pattern

Other Known Use Cases

Additional domains where the cartridge pattern has been applied or is well-suited:

  • Legal document retrieval — cartridges per jurisdiction or practice area
  • Technical documentation search — SDK / API docs as queryable cartridges
  • Customer support knowledge bases — product cartridges swapped per query category
  • Multi-agent AI operations harnesses — each specialized agent queries its own domain cartridge at spawn time, enabling parallel expertise without context duplication
  • Code intelligence — codebase sharded into queryable cartridges for symbol lookup and architectural review
  • Interactive fiction & NPC memory — per-character micro-shards accumulate history across sessions, feeding LLM character embodiment without growing context cost
Legal Documentation Support Multi-Agent Code Intelligence Interactive Fiction

Benchmark Results

Ground-truth performance measurements comparing TAH retrieval against raw context injection across representative domain queries.

Test Case Raw Context TAH (BM25 fixed) Result
400-page architecture textbook query ~$5.20 / query ~$0.12 / query 40x cheaper
Session log history search ("did we discuss X?") Impossible (context limit) < 2s retrieval Enabled
Skills discovery (which skill handles X?) Read files sequentially Single BM25 query Orders of magnitude faster
BM25 pre-fix (degenerate ranker) N/A Same shortest shard always Broken until 2026-06-17
BM25 post-fix (correct IDF scoring) N/A Correct term-weighted ranking Verified live

Explore the Source

All TAH work originates from Tahsin Reza's public GitHub repositories. The format specification, builder, and query implementation are open source.

SunsetWars

The canonical TAH implementation: builder, query engine, Bloom filter, BM25 ranker, Telegram + Ollama + Groq integrations.

github.com/tahsrz/SunsetWars →

SunsetPulse

Production deployment of TAH in a real estate AI platform. Next.js 14, TypeScript, monorepo. Best example of domain-cartridge architecture in action.

github.com/tahsrz/sunset-pulse →