Distill is built as a modular system designed for high-throughput prompt compression. The architecture is split between a high-performance Python backend and a modern React frontend for visualization.
- Ingestion: The system receives a raw text prompt or a list of context strings.
- Preprocessing: Text is chunked based on maximum sequence lengths and special "anchor" tokens (e.g., newlines).
- Inference: A BERT-based Token Classification model evaluates the "Information Density" of every token.
- Compression Pipeline:
- Context Filtering: Entire irrelevant chunks are discarded.
- Token Pruning: Individual tokens within chunks are removed based on percentile thresholds.
- Reconstruction: The remaining tokens are re-joined into a coherent (though "lossy") prompt.
- Delivery: The compressed prompt is sent to a target LLM (like GPT-4), or returned via API.
- Core Engine: The
distillpackage contains the logic for inference and pruning. - API Layer: FastAPI provides endpoints for remote compression services.
- Models: Local storage for the fine-tuned BERT weights and configuration.
- Dashboard: A React application that visualizes compression ratios, latency improvements, and cost savings.
- Demo: An interactive interface to test the compression algorithm in real-time.
flowchart TD
User[User Input] --> API[API / CLI]
API --> Chunking[Chunking Logic]
Tiktoken[Tiktoken] --> Chunking
Chunking --> BERT[BERT Inference]
Weights[Local Weights] --> BERT
BERT --> Filtering[Two-Tier Filtering]
Filtering --> Context[Context Filter]
Filtering --> Token[Token Filter]
Context --> Assembly[Prompt Assembly]
Token --> Assembly
Assembly --> Output[Target LLM / Output]