Architecture21 articles

Architecture

Articles

  • Multi-Token Prediction: How Future Token Supervision Densifies Representations and Speeds Up LLM Serving

    Standard autoregressive language models are trained under a strict next-token prediction objective. At every sequence position, the model consumes a prefix of tokens and predicts the single immediate successor token using a cross-entropy loss. While this paradigm has scaled language modeling across orders of magnitude, it suffers from an architectural limitation: myopic optimization. By evaluating loss exclusively on the immediate next step, standard training fails to reward representations that

    1 min
  • Executable Code Actions vs. JSON Tool Calling: Architecture, Token Economics, Sandboxing, and Expressivity in Production AI Agents

    Executable Code Actions vs. JSON Tool Calling: Architecture, Token Economics, Sandboxing, and Expressivity in Production AI Agents The dominant paradigm for connecting large language models to external tools has relied on structured JSON function calling. First standardized across commercial APIs via JSON Schema manifests and constrained decoding, this approach frames agent interaction as remote procedure calls (RPC): the model outputs a JSON object specifying a tool name and parameters, the ho

    1 min
  • Vector Databases in Production: Architecture, Filtering Strategies, and Scale Ceilings for pgvector, Qdrant, Milvus, and Pinecone

    The rapid deployment of retrieval-augmented generation (RAG) and semantic search has turned vector databases from specialized academic tooling into core production infrastructure. However, engineering teams face conflicting architectural paradigms. On one side, the relational database ecosystem argues that vector extensions inside existing databases eliminate operational overhead. On the other side, dedicated vector database vendors argue that relational engines cannot handle high-dimensional ge

    1 min
  • Attention Sinks in Large Language Models: How StreamingLLM Prevents Perplexity Explosion in Infinite Sequences

    Autoregressive large language models are trained on fixed context windows, yet real-world applications (such as continuous coding agents, live conversation servers, and document streaming pipelines) require models to process unbounded token sequences. When standard LLMs operate on sequences longer than their pre-training context length, computational complexity and key-value (KV) cache memory scale quadratically and linearly, respectively. A seemingly natural workaround is sliding window attent

    1 min
  • Agent Memory Architectures in Production: Working Context, Episodic Buffers, Semantic Graphs, and State Serialization

    Large Language Models operate as stateless prediction engines: every API call processes an input prompt independently, without retaining memory of previous turns, decisions, or external interactions. While extending context windows to 1 million or 2 million tokens provides temporary capacity for long transcripts, treating raw context windows as long-term memory introduces severe engineering bottlenecks. Unbounded context growth dramatically inflates time-to-first-token (TTFT) latency, increases

    1 min
  • GraphRAG vs. Vector RAG in Production: Architecture, Community Summaries, and Cost-Latency Trade-Offs

    Retrieval-Augmented Generation (RAG) has become the standard architecture for grounding Large Language Models in external knowledge bases. However, production implementations frequently encounter structural limits when relying entirely on naive vector search. Standard Vector RAG fragments documents into arbitrary chunks and retrieves top-k passages via cosine similarity in embedding space. While effective for localized fact retrieval, this approach struggles with global, corpus-wide synthesis an

    1 min
  • Test-Time Compute Scaling in Large Language Models: How Search, Verification, and Reasoning Chains Trade Latency for Accuracy

    Large language model performance has historically been dictated by pre-training compute scaling laws. As formalised by Kaplan et al. and Chinchilla scaling, increasing model parameters, dataset size, and pre-training FLOPs yielded predictable reductions in cross-entropy loss. During inference, however, computation remained strictly linear and deterministic: one forward pass per generated token. The emergence of inference-time reasoning architectures has introduced a third scaling axis: test-tim

    1 min
  • AI Guardrails in Production: Multi-Stage Filtering, Classification Models, and the Latency Tax

    AI Guardrails in Production: Multi-Stage Filtering, Classification Models, and the Latency Tax Production deployments of large language models cannot rely solely on system prompt instructions to maintain safety, prevent prompt injection, or restrict domain scope. System prompt alignment is inherently susceptible to adversarial bypasses, context dilution, and non-deterministic instruction following. To enforce strict security, compliance, and topic boundaries, engineering teams increasingly depl

    1 min
  • Multi-Head Latent Attention: How Low-Rank KV Compression Scales LLM Serving

    Autoregressive transformer inference faces a fundamental hardware constraint during text generation: memory bandwidth saturation. While prefill (processing prompt tokens) is compute-bound and saturates GPU tensor cores, token-by-token generation is memory-bandwidth bound. To generate each subsequent token, the inference engine must load all prior Key and Value vectors from High Bandwidth Memory (HBM) into SRAM. As sequence lengths reach 32k, 64k, or 128k tokens and batch sizes scale, the Key-Va

    1 min
  • LLM Gateways in Production: Multi-Provider Failover, Rate Limiting, and Spend Governance

    LLM Gateways in Production: Multi-Provider Failover, Rate Limiting, and Spend Governance As generative AI workloads transition from experimental prototypes to mission-critical infrastructure, direct client-to-provider API calls introduce substantial operational risk. Relying on hardcoded SDK connections to a single model provider exposes production services to unexpected rate limits, regional outages, silent breaking changes, and uncontrolled token costs. To solve these reliability and governa

    1 min
  • State Space Models in Large Language Models: How Mamba, S4, and Selective Recurrence Challenge Transformer Attention

    Modern large language models rely almost universally on the Transformer architecture. However, the core mechanism powering Transformers, softmax multi-head self-attention, exhibits fundamental scaling limitations. Specifically, standard self-attention requires quadratic time and memory complexity relative to sequence length during prefilling, alongside a linear memory expansion for the key-value (KV) cache during autoregressive token generation. To circumvent these computational bottlenecks, re

    1 min
  • Continuous Batching in Production LLM Serving: Iteration-Level Scheduling, Chunked Prefills, and Throughput Trade-Offs

    Static batching served as the standard execution paradigm for deep learning inference across computer vision and traditional natural language processing for years. In those domains, incoming requests typically feature fixed input dimensions and deterministic execution graphs. Autoregressive large language model serving breaks every assumption underlying static batching. Input prompts vary widely in token length, output generations terminate nondeterministically upon emitting an end-of-sequence t

    1 min
  • Disaggregated Prefill and Decode in Production: Architecture, Economics, and KV Transfer Protocols

    In production large language model serving, the fundamental architectural tension lies between two computationally distinct phases: prefill (processing the input prompt) and decode (generating output tokens autoregressively). In standard co-located serving systems, both phases share the same GPU instances, memory pools, and execution batches. This co-location creates head-of-line blocking, degrades Time to First Token (TTFT), inflates Time Per Output Token (TPOT), and limits cluster-wide hardwar

    1 min
  • Sandboxing LLM Code Execution: Architecture, Isolation Boundaries, and Performance Trade-Offs

    Autonomous AI agents increasingly operate beyond static text generation, leveraging runtime code execution loops to solve software engineering tasks, execute data analysis pipelines, and automate system administration. When an LLM generates and executes Python scripts, bash commands, or package installations, the hosting infrastructure transitions from processing standard API requests to running arbitrary, unauthenticated code. Treating LLM-generated code as inherently hostile is now standard p

    1 min
  • Byte-Pair Encoding in Large Language Models: How Tokenizers Compress Text, Shape Context, and Fail

    Large language models do not process strings directly. Before a single attention weight or linear projection executes, incoming text is converted into a sequence of discrete integers known as tokens. The choice and implementation of the tokenization algorithm establish the model's fundamental vocabulary, define the boundaries of its context window, dictate inference speed, and introduce unique behavioral quirks. Across modern transformer architectures, subword tokenization via Byte-Pair Encodin

    1 min
  • Model Context Protocol (MCP) in Production: Architecture, Security Boundaries, and Latency Overheads

    As autonomous language model agents transition from experimental chat interfaces into enterprise production infrastructure, the architectural bottleneck has shifted from raw model reasoning to external environment integration. In early agent implementations, connecting an LLM to external systems required bespoke tool definitions, vendor-specific function schemas, and custom API wrappers. Every framework maintained its own incompatible tool-calling abstraction, fragmenting integrations across age

    1 min
  • FlashAttention: How IO-Aware Tiling and Online Softmax Solved Transformer Memory Bottlenecks

    Standard multi-head attention is the fundamental computational primitive of modern autoregressive language models. While mathematically straightforward, the operation introduces a severe operational bottleneck as context windows scale. Naive implementations of scaled dot-product attention exhibit quadratic memory complexity $O(N^2)$ and quadratic memory access costs, bounding sequence lengths and leaving modern GPU tensor cores severely underutilized. FlashAttention, introduced by Tri Dao, Dani

    1 min
  • LLM Model Routing and Cascades: Architecture, Economics, and Quality Trade-Offs

    In modern enterprise AI systems, uniform model dispatch, sending all incoming user traffic to a single frontier large language model, is one of the most common architectural inefficiencies. Frontier models like GPT-4o and Claude 3.5 Sonnet provide industry-leading reasoning and code generation capabilities, but their inference costs range between $2.50 and $15.00 per million tokens. Conversely, smaller open-weights or distilled models, such as Llama 3.1 8B or GPT-4o-mini, execute at a fraction o

    1 min
  • Why Dense Vector Search Alone Fails: Architecting Production Hybrid Retrieval for RAG

    In early Retrieval-Augmented Generation (RAG) deployments, single-stage dense vector search served as the standard retrieval primitive. The workflow appeared straightforward: partition a document corpus into chunks, compute vector embeddings for each chunk using a pre-trained bi-encoder, index the vectors in an approximate nearest neighbor (ANN) store, and retrieve the top candidates by cosine similarity against the query embedding. In production systems handling technical documentation, softwa

    1 min
  • Rotary Position Embeddings: How Geometry Solved Long Context in Modern LLMs

    Rotary Position Embedding (RoPE) has become the standard positional encoding mechanism across modern large language models, including Meta's Llama series, Mistral, Qwen, and DeepSeek. Unlike earlier techniques that added positional vectors directly to token representations or modified attention matrices with relative distance penalties, RoPE encodes position through geometric rotations in the complex plane. This design enables models to compute relative token distances while processing individu

    1 min