|
8 | 8 |
|
9 | 9 | [](https://app.ona.com/#https://github.com/siddhant-k-code/distill) |
10 | 10 |
|
11 | | -**Context intelligence layer for AI agents.** |
| 11 | +**Open-source context preprocessing for LLM applications.** |
12 | 12 |
|
13 | | -Deduplicates, compresses, and manages context across sessions - so your agents produce reliable, deterministic outputs. Includes a dedup pipeline with ~12ms overhead and persistent context memory with write-time dedup and hierarchical decay. |
| 13 | +Distill sits between your application and any LLM. It cleans up context before it's sent — deduplicating semantically redundant chunks, compressing conversation history as it ages, and placing cache markers on stable content so Anthropic's prompt cache actually fires. |
14 | 14 |
|
15 | | -Less redundant data. Lower costs. Faster responses. Deterministic results. |
| 15 | +The result: fewer tokens sent, lower cost per request, and context windows that don't fill up with noise. |
16 | 16 |
|
17 | 17 | **[Learn more →](https://distill.siddhantkhare.com)** |
18 | 18 |
|
19 | | -> 📖 Distill implements the 4-layer context engineering stack (Cluster → Select → Rerank → Compress) described in **[The Agentic Engineering Guide](https://agents.siddhantkhare.com/05-context-engineering-stack/)** — a free, open book on AI agent infrastructure. |
| 19 | +> 📖 Distill implements the 4-layer context engineering stack described in **[The Agentic Engineering Guide](https://agents.siddhantkhare.com/05-context-engineering-stack/)** — a free, open book on AI agent infrastructure. |
20 | 20 |
|
21 | 21 | ``` |
22 | | -Context sources → Distill → LLM |
23 | | -(RAG, tools, memory, docs) (reliable outputs) |
| 22 | +RAG / tools / memory / docs |
| 23 | + ↓ |
| 24 | + Distill |
| 25 | + (dedupe · compress · cache) |
| 26 | + ↓ |
| 27 | + LLM |
24 | 28 | ``` |
25 | 29 |
|
26 | 30 | ## The Problem |
27 | 31 |
|
28 | | -LLM outputs are unreliable because context is polluted. "Garbage in, garbage out." |
| 32 | +30–40% of context assembled from multiple sources is semantically redundant. The same information arrives from docs, code, memory, and tool outputs — competing for attention in the same prompt. |
29 | 33 |
|
30 | | -30-40% of context assembled from multiple sources is semantically redundant. Same information from docs, code, memory, and tools competing for attention. This leads to: |
31 | | - |
32 | | -- **Non-deterministic outputs** - Same workflow, different results |
33 | | -- **Confused reasoning** - Signal diluted by repetition |
34 | | -- **Production failures** - Works in demos, breaks at scale |
35 | | - |
36 | | -You can't fix unreliable outputs with better prompts. You need to fix the context that goes in. |
| 34 | +This causes non-deterministic outputs, confused reasoning, and failures that only show up at scale. Better prompts don't fix it. The context going in needs to be clean. |
37 | 35 |
|
38 | 36 | ## How It Works |
39 | 37 |
|
40 | | -Math, not magic. No LLM calls. Fully deterministic. |
| 38 | +No LLM calls. Fully deterministic. ~12ms overhead. |
| 39 | + |
| 40 | +| Stage | What it does | |
| 41 | +|-------|-------------| |
| 42 | +| **Deduplicate** | Cluster semantically similar chunks, keep one representative per cluster | |
| 43 | +| **Compress** | Extractive compression — remove noise, preserve signal | |
| 44 | +| **Summarize** | Progressively condense conversation history as turns age | |
| 45 | +| **Cache** | Annotate stable prefixes with `cache_control`, track TTL per prefix | |
41 | 46 |
|
42 | | -| Step | What it does | Benefit | |
43 | | -|------|--------------|---------| |
44 | | -| **Deduplicate** | Remove redundant information across sources | More reliable outputs | |
45 | | -| **Compress** | Keep what matters, remove the noise | Lower token costs | |
46 | | -| **Summarize** | Condense older context intelligently | Longer sessions | |
47 | | -| **Cache** | Instant retrieval for repeated patterns | Faster responses | |
| 47 | +All four stages chain together via `POST /v1/pipeline` or `distill pipeline` CLI. |
48 | 48 |
|
49 | | -### Pipeline |
| 49 | +### Dedup pipeline |
50 | 50 |
|
51 | 51 | ``` |
52 | 52 | Query → Over-fetch (50) → Cluster → Select → MMR Re-rank (8) → LLM |
53 | 53 | ``` |
54 | 54 |
|
55 | | -1. **Over-fetch** - Retrieve 3-5x more chunks than needed |
56 | | -2. **Cluster** - Group semantically similar chunks (agglomerative clustering) |
57 | | -3. **Select** - Pick best representative from each cluster |
58 | | -4. **MMR Re-rank** - Balance relevance and diversity |
| 55 | +1. **Over-fetch** — retrieve 3–5× more chunks than needed |
| 56 | +2. **Cluster** — group semantically similar chunks (agglomerative clustering) |
| 57 | +3. **Select** — pick the best representative from each cluster |
| 58 | +4. **MMR Re-rank** — balance relevance and diversity |
59 | 59 |
|
60 | | -**Result:** Deterministic, diverse context in ~12ms. No LLM calls. Fully auditable. |
| 60 | +**Result:** Deterministic, diverse context. No LLM calls. Fully auditable. |
61 | 61 |
|
62 | 62 | ## Installation |
63 | 63 |
|
|
0 commit comments