Inferensys

Glossary

Dictionary Compression (LZ)

Dictionary compression, exemplified by the LZ family of algorithms (LZ77, LZW), is a lossless data compression method that replaces repeated sequences of data with references to a dictionary of previously seen sequences.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
MEMORY COMPRESSION TECHNIQUE

What is Dictionary Compression (LZ)?

Dictionary compression is a foundational lossless data compression method central to reducing the storage footprint of agentic memories and other data.

Dictionary compression is a lossless data compression algorithm that replaces repeated sequences of data with compact references to a dynamically built dictionary of previously seen sequences. Pioneered by the LZ77 and LZW algorithms, it operates on the principle that redundancy in data (like repeated words or code patterns) can be encoded more efficiently as pointers. This technique is fundamental to formats like ZIP, GIF, and is conceptually analogous to how an agent might compress a long conversation history by referencing prior statements.

In agentic systems, dictionary compression principles can be applied to memory compression, where recurring states, observations, or tool call outputs are stored once and referenced. This reduces the context window load and storage needs for long-term memory. Unlike pruning or quantization for neural networks, LZ compression is a generic, algorithm-driven method for sequential data, making it a versatile tool in an engineer's optimization toolkit alongside techniques like delta compression and deduplication.

DICTIONARY COMPRESSION (LZ)

Core LZ Algorithm Variants

The LZ family of algorithms forms the backbone of modern lossless data compression. These methods work by building a dictionary of previously seen data sequences and replacing subsequent repetitions with compact references.

01

LZ77 (Sliding Window)

LZ77, published by Abraham Lempel and Jacob Ziv in 1977, is the foundational algorithm. It uses a sliding window divided into two parts:

  • Search Buffer: Contains recently encoded data (the dictionary).
  • Look-Ahead Buffer: Contains data yet to be encoded.

The encoder searches for the longest match of the look-ahead buffer's prefix within the search buffer. It outputs a token consisting of:

  • Offset: Distance back to the start of the match.
  • Length: Length of the matching sequence.
  • Next Symbol: The first non-matching symbol after the match. This scheme is inherently adaptive, as the sliding window continuously updates, making it effective for streaming data. The DEFLATE algorithm (used in gzip and PNG) combines LZ77 with Huffman coding.
02

LZ78 (Explicit Dictionary)

LZ78, published in 1978, differs fundamentally by building an explicit dictionary of previously encountered phrases (substrings).

  • The dictionary starts empty.
  • The encoder parses the input into phrases where each phrase is the longest dictionary match plus one new character.
  • It outputs a token: (dictionary index, new character).
  • The new phrase (match + new character) is then added to the dictionary. Unlike LZ77's sliding window, the LZ78 dictionary grows until a size limit is reached, potentially capturing longer-term repetitions. Its need to transmit the new character with every token can be less efficient on highly repetitive data compared to LZ77.
03

LZW (Lempel–Ziv–Welch)

LZW, a practical refinement of LZ78 by Terry Welch, is one of the most widely implemented algorithms (GIF, TIFF, Unix compress). Key modifications:

  • The dictionary is pre-initialized with all possible single-character strings (e.g., 256 entries for 8-bit data).
  • Output tokens are only dictionary indices; the 'new character' is implied as the first character of the next phrase.
  • The decoder builds the dictionary synchronously, avoiding the need to transmit the dictionary. Process: The encoder finds the longest string W in the dictionary, outputs its index, and adds W + next character to the dictionary. Its simplicity and decent compression ratio led to widespread adoption in early file formats.
04

LZSS (Lempel–Ziv–Storer–Szymanski)

LZSS, introduced by Storer and Szymanski in 1982, is an efficient improvement over LZ77 that resolves a key inefficiency.

  • In LZ77, every token includes a 'next symbol', even for long matches.
  • LZSS uses a flag bit (or byte) to distinguish between two output types:
    1. A match token: (Offset, Length) for sequences longer than a threshold.
    2. A literal character: The raw symbol itself, for no suitable match. This eliminates the overhead of the 'next symbol' for matches, significantly improving compression on moderately redundant data. It is the core algorithm in formats like ZIP (via DEFLATE) and RAR.
05

LZMA (Lempel–Ziv–Markov chain Algorithm)

LZMA, used in the 7z format, represents a modern, high-compression variant. It combines an advanced LZ77-style sliding window match finder with a range coder (an efficient form of arithmetic coding) for entropy coding. Key Features:

  • Uses a large sliding window (up to gigabytes) to find long-distance matches.
  • Employs complex hash chains or binary trees for fast match searching.
  • The output from the LZ77 stage (literal/match decisions, offsets, lengths) is then encoded using a context-based range coder, which adapts probability models based on recent data types (e.g., literal vs. match state, position within a word). This two-stage process—dictionary compression followed by sophisticated statistical compression—achieves very high ratios, especially on text and executable code.
06

Dictionary Management & Trade-offs

The performance of LZ variants hinges on dictionary management strategies, which involve core trade-offs:

  • Sliding Window (LZ77/LZSS/LZMA):
    • Pros: Continuously adaptive, excellent for local repetition and streaming.
    • Cons: Cannot capture repetitions beyond the window size; search complexity increases with window size.
  • Growing Dictionary (LZ78/LZW):
    • Pros: Can capture very long-term, global repetitions.
    • Cons: Dictionary size grows unbounded, requiring reset or pruning; less efficient on data with only short-range redundancy.
  • Match Finding: Algorithms use hash tables, suffix trees, or hash chains to accelerate the search for the longest match, which is the most computationally intensive step in LZ77-style encoding. The choice of variant involves balancing compression ratio, speed, memory usage, and suitability for the data's redundancy structure.
APPLICATION IN AGENTIC MEMORY SYSTEMS

Dictionary Compression (LZ)

Dictionary compression, specifically the Lempel-Ziv (LZ) family of algorithms, is a foundational lossless data compression technique applied to reduce the storage footprint of agentic memory systems.

Dictionary compression is a lossless data compression method that replaces repeated sequences of data with compact references to a dictionary of previously seen sequences. In agentic memory systems, this technique is applied to compress episodic logs, conversation histories, and retrieved context before storage or transmission. Algorithms like LZ77 and LZW excel at compressing natural language and structured text, which are common in agent operations, by building and referencing an adaptive dictionary on the fly.

For autonomous agents operating over extended timeframes, applying LZ compression to memory caches and experience replay buffers significantly reduces I/O latency and storage costs without information loss. This enables more episodes or trajectories to be retained within fixed memory budgets. The technique is often combined with deduplication at the system level and works alongside embedding compression and context summarization within a broader memory compression strategy to maximize the efficiency of long-term knowledge retention.

DICTIONARY COMPRESSION (LZ)

Frequently Asked Questions

Dictionary compression, exemplified by the LZ family of algorithms, is a foundational lossless data compression technique. It is highly relevant to agentic memory systems for reducing the storage footprint of repetitive logs, state histories, and conversational contexts. This FAQ addresses its core mechanisms, variants, and applications in AI engineering.

Dictionary compression is a lossless data compression method that identifies and replaces repeated sequences (phrases) in a data stream with shorter references to a dictionary of previously encountered sequences.

How it works:

  1. Parsing: The algorithm reads the input data sequentially.
  2. Search: For each new position, it looks for the longest match between the upcoming data and a sequence already stored in its dictionary (which can be a sliding window of recent input or a static table).
  3. Encoding: If a match is found, it outputs a token—typically a pair (offset, length)—where offset points backward to the start of the match in the dictionary, and length indicates how many characters to copy.
  4. Literal Output: If no match is found, it outputs the raw character (a literal).
  5. Dictionary Update: The algorithm updates its dictionary with the new sequence, making it available for future matches.

This process exploits redundancy within the data, as many formats (text, code, JSON, agent logs) contain repeated substrings.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.