BaseCompressor (compressors.py)

claw-compactor · ai

compressors.py — Four compression strategies for the Engram Benchmark. Strategies: 1. EngramCompressor — LLM Observer + Reflector (Layer 6 Engram) 2. RuleCompressor — claw-compactor Layers 1-5 (deterministic, no LLM) 3. RandomDropCompressor — Random token drop (LLMLingua-2 baseli

"""compressors.py — Four compression strategies for the Engram Benchmark.

Strategies:
1. EngramCompressor   — LLM Observer + Reflector (Layer 6 Engram)
2. RuleCompressor     — claw-compactor Layers 1-5 (deterministic, no LLM)
3. RandomDropCompressor — Random token drop (LLMLingua-2 baseline proxy)
4. NoCompressor       — Raw text, no compression (baseline)

Python 3.9+ / no external deps beyond stdlib.
EngramCompressor uses the proxy at http://localhost:8403.
"""

from __future__ import annotations

import json
import logging
import os
import random
import re
import sys
import time
import urllib.error
import urllib.request
from pathlib import Path
from typing import Optional

# ---------------------------------------------------------------------------
# Load .env from project root
# ----

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key