clef-compactor
Query-aware RAG context compaction using Cloudflare's Clef.
Your retrieval pipeline returns 12 chunks. Your LLM reads all of them. You pay for all of them. clef-compactor scores each document against the query using Clef's 64k context window and cuts the noise.
Delete, do not rewrite. Documents are kept verbatim or removed with an auditable reason. Never summarized.
Quick start
pip install clef-compactor
export CLEF_ACCOUNT_ID=your_id
export CLEF_API_TOKEN=your_token
from clef_compactor import ClefCompactor
compactor = ClefCompactor()
result = compactor.compact(
question="What is the refund policy?",
documents=retrieved_chunks,
token_budget=1000,
)
# result.kept: documents that survived
# result.dropped: [{doc, score, reason}] for the ones cut
# result.total_output_tokens < result.total_input_tokens
CLI
clef-compact -q "refund policy" -d "doc1..." "doc2..." --budget 1000
Why Clef for compaction?
Clef's 64k context window means you can score more documents in a single pass than with laya (32k). The quality is higher (BFCL 98.76 vs laya's 38.13), which means fewer false positives when scoring document relevance.
For sub-10ms local compaction, see laya-compactor.
License
Apache 2.0
Metadata
Release files for clef-compactor 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| clef_compactor-0.1.0.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clef_compactor-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / clef_compactor-0.1.0.tar.gz
| Download URL | clef_compactor-0.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fbee6885bb1211763690f4803d36654ab752a679455ada562bc2046a347b1914
|
|
BLAKE2b-256 checksum How to use checksums |
5620fcbff29215532912384f2ac640b234327f2b01cb01e7844640646d1e3a43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / clef_compactor-0.1.0-py3-none-any.whl
| Download URL | clef_compactor-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5072990c7051d281d2cac18f934c7cc8d9879a489514a4c50358f642fd5fa271
|
|
BLAKE2b-256 checksum How to use checksums |
c793dbbc893e2e6367a13834165d3c16817a0edf3dfcf4a1d28f7dafd1b16f99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|