sageRefiner provides state-of-the-art context compression algorithms to reduce token usage while maintaining semantic quality for Large Language Model applications.
8 Compression Algorithms
High Compression Ratios: 2-10x compression while preserving key information
Flexible Configuration: YAML/dict-based configuration
Production Ready: Battle-tested in the SAGE framework
# Basic installation
pip install isage-refiner
# With benchmark support
pip install isage-refiner[benchmark]
# Development mode
git clone https://github.com/intellistream/sageRefiner.git
cd sageRefiner
pip install -e .
from sage_refiner import LLMLingua2Compressor
# Initialize compressor
compressor = LLMLingua2Compressor()
# Compress context
result = compressor.compress(
context="Your long document text here...",
question="What is the main topic?",
target_token=500,
)
print(f"Compression rate: {result['compression_rate']:.2%}")
print(f"Compressed: {result['compressed_context']}")
| Algorithm | Model | Best For |
|---|---|---|
| LongRefiner | Qwen/Llama + LoRA | High-quality semantic compression |
| REFORM | Any Llama/Qwen | Fast attention-based selection |
| Provence | DeBERTa | Document-level filtering |
| LLMLingua2 | BERT | Speed-critical applications |
| LongLLMLingua | GPT-2/Llama | Long document scenarios |
| RECOMP-Abst | T5 | Summarization-style compression |
| RECOMP-Extr | BERT | Sentence extraction |
| EHPC | Llama-8B | Evaluator heads selection |
from sage_refiner import RefinerConfig
config = RefinerConfig(
algorithm="llmlingua2",
target_token=500,
force_tokens=["important", "keyword"],
)
# Basic compression
python examples/basic_compression.py
# Compare algorithms
python examples/algorithm_comparison.py
This repository is an L3 algorithm library in the SAGE layered architecture.
torch, transformers: required by algorithm compute pathsnumpy, pyyaml, tqdm, rich: required for algorithm runtime/config/outputThe benchmarks module provides a comprehensive evaluation framework for all compression
algorithms:
# Quick comparison of multiple algorithms
pip install isage-refiner[benchmark]
sage-refiner-bench compare \
--algorithms baseline,longrefiner,reform,provence \
--samples 100
# Detailed evaluation with budget sweep
sage-refiner-bench sweep \
--algorithm longrefiner \
--budgets 512,1024,2048,4096
For detailed benchmarking documentation, see benchmarks/README.md and benchmarks/STRUCTURE.md.
@software{sageRefiner2025,
title = {sageRefiner: Context Compression for LLM},
author = {SAGE Team},
year = {2025},
url = {https://github.com/intellistream/sageRefiner}
}
Apache License 2.0
For quick setup:
bash utils/installation/quickstart.sh # Full installation
bash utils/hooks/setup-hooks.sh # Setup pre-commit hooks
Python
91.4%
Shell
8.6%
sageRefiner provides state-of-the-art context compression algorithms to reduce token usage while maintaining semantic quality for Large Language Model applications.
8 Compression Algorithms
High Compression Ratios: 2-10x compression while preserving key information
Flexible Configuration: YAML/dict-based configuration
Production Ready: Battle-tested in the SAGE framework
# Basic installation
pip install isage-refiner
# With benchmark support
pip install isage-refiner[benchmark]
# Development mode
git clone https://github.com/intellistream/sageRefiner.git
cd sageRefiner
pip install -e .
from sage_refiner import LLMLingua2Compressor
# Initialize compressor
compressor = LLMLingua2Compressor()
# Compress context
result = compressor.compress(
context="Your long document text here...",
question="What is the main topic?",
target_token=500,
)
print(f"Compression rate: {result['compression_rate']:.2%}")
print(f"Compressed: {result['compressed_context']}")
| Algorithm | Model | Best For |
|---|---|---|
| LongRefiner | Qwen/Llama + LoRA | High-quality semantic compression |
| REFORM | Any Llama/Qwen | Fast attention-based selection |
| Provence | DeBERTa | Document-level filtering |
| LLMLingua2 | BERT | Speed-critical applications |
| LongLLMLingua | GPT-2/Llama | Long document scenarios |
| RECOMP-Abst | T5 | Summarization-style compression |
| RECOMP-Extr | BERT | Sentence extraction |
| EHPC | Llama-8B | Evaluator heads selection |
from sage_refiner import RefinerConfig
config = RefinerConfig(
algorithm="llmlingua2",
target_token=500,
force_tokens=["important", "keyword"],
)
# Basic compression
python examples/basic_compression.py
# Compare algorithms
python examples/algorithm_comparison.py
This repository is an L3 algorithm library in the SAGE layered architecture.
torch, transformers: required by algorithm compute pathsnumpy, pyyaml, tqdm, rich: required for algorithm runtime/config/outputThe benchmarks module provides a comprehensive evaluation framework for all compression
algorithms:
# Quick comparison of multiple algorithms
pip install isage-refiner[benchmark]
sage-refiner-bench compare \
--algorithms baseline,longrefiner,reform,provence \
--samples 100
# Detailed evaluation with budget sweep
sage-refiner-bench sweep \
--algorithm longrefiner \
--budgets 512,1024,2048,4096
For detailed benchmarking documentation, see benchmarks/README.md and benchmarks/STRUCTURE.md.
@software{sageRefiner2025,
title = {sageRefiner: Context Compression for LLM},
author = {SAGE Team},
year = {2025},
url = {https://github.com/intellistream/sageRefiner}
}
Apache License 2.0
For quick setup:
bash utils/installation/quickstart.sh # Full installation
bash utils/hooks/setup-hooks.sh # Setup pre-commit hooks
Python
91.4%
Shell
8.6%