arcaeon-dedup
Strip repeated text from an agent's context before it costs you tokens. Pure stdlib. No LLM, no embeddings, no network. Cheap enough to run on every call.
pip install arcaeon-dedup
Why
Retrieved chunks, tool outputs, conversation history, and memory stores fill up with literal repeats — the same doc pulled twice by two retrievers, the same boilerplate header on every result, a chunk that overlaps its neighbour, the same error line logged forty times. Every redundant copy is pure token waste, and you pay for it on every call that carries it.
Most "dedup" tooling is built for training corpora, or needs embeddings + a vector DB to run. For agent context you want something that costs essentially nothing, so you can put it in front of every context assembly without thinking about it.
arcaeon-dedup uses SimHash to find candidate pairs fast, then verifies every
candidate by direct feature overlap before it drops anything. The verification step
is the whole safety story — see below for why a bare similarity threshold is not one.
Use
from arcaeon_dedup import dedupe
doc = "Docs: the API returns 200 on success. See the reference for details."
chunks = [
doc,
doc.replace(". ", ". "), # same doc, refetched — whitespace noise only
"The database connection timed out after 30 seconds.",
]
kept, report = dedupe(chunks)
# kept -> 2 items (the repeat dropped, order preserved)
# report -> deduped: kept 2, removed 1 repeat(s); ~69 chars / ~17 tokens saved
Tuning:
dedupe(chunks, min_overlap=0.95, max_hamming=12, k=1, keep="first")
min_overlap(default 0.95): the verification gate. A candidate pair is only dropped if its measured feature overlap — the minimum of character-4-gram and word-bigram Jaccard, after normalizing case, punctuation, and whitespace — is at least this.1.0drops only exact matches after normalization. Below ~0.7 you are deleting content that is merely related, which is silent data loss.max_hamming(default 12, of 64 bits): how wide the candidate net is thrown. Raising it finds more candidates to verify; it does not weaken the gate above.k(default 1): SimHash shingle size, candidate generation only.keep:"first"keeps the earliest of each cluster (best for chronological context — the original stays);"longest"keeps the fullest phrasing. Clusters are formed against fixed representatives, so nothing is ever dropped against an item it wasn't verified against.
Also exported: simhash(text), hamming(a, b) if you want the primitives directly.
What it removes / what it will not
Removes: near-verbatim repeats. Identical text; text differing only in whitespace, case, punctuation, or wrapper noise; the same passage retrieved twice. That is the common and expensive case, and it is the one this can do safely.
Will not: collapse paraphrase — and it must not pretend to. No lexical distance
separates "reworded, same meaning" from "one word changed, opposite meaning."
Charge the customer $19 and Refund the customer $19 are lexically closer than
any two honest paraphrases of the same sentence. So are Alice owes Bob $100 and
Bob owes Alice $100 — identical bag of words, opposite fact. Any setting aggressive
enough to collapse a paraphrase deletes those too, and deleting those is deleting
facts out of an agent's context with a report that says it saved you tokens. If you
need paraphrase collapsed, that requires semantics: use embeddings.
The one thing it can still get wrong, stated plainly rather than left for you to
find: a single inserted or substituted token inside a long document leaves the two
strings overwhelmingly identical, so past some length a one-word change reads as a
repeat. No threshold fixes this in general — it is the same theorem as above. If
one-token inversions are load-bearing in your corpus (medical, legal, financial
records), pass min_overlap=1.0 and drop only exact matches.
MIT. Built by Arcaeon — the evidence layer for AI.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arcaeon_dedup-0.1.1.tar.gz.
File metadata
- Download URL: arcaeon_dedup-0.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2528581e2102e2a1cff64c3328c7589d8c1b67f85a656fb2d0d8da1f4ea08f0e
|
|
| MD5 |
e6a389a1cd6373f48f3136092384cb9c
|
|
| BLAKE2b-256 |
ed009cc6db3fb4210782b13d6fcca288d27d8090e64febb0b56e07cb890d6cfe
|
File details
Details for the file arcaeon_dedup-0.1.1-py3-none-any.whl.
File metadata
- Download URL: arcaeon_dedup-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e07aecd7dcae8acb9120141f1077276ca4281bc6c91a179f68344c545623b574
|
|
| MD5 |
b3f362f86fd06a21f407fdd8a98fcddb
|
|
| BLAKE2b-256 |
7df6345dea60bb08c8cd655b282a46e0e09d652069cafe1bb5efe1bead7a774f
|