Zero-dependency token reduction engine for LLM RAG pipelines and AI Agents. Achieves 40-60% token savings while preserving semantic context.
- 🚀 Token Reduction: Reduces redundant stop words and boilerplate HTML/Markdown formatting to save 40-60% API costs.
- 🎯 Semantic Density Scoring: Uses information density scoring to prune low-value text while retaining critical context (code snippets, API endpoints, key metrics).
- 🔒 Zero External Dependencies: Pure TypeScript engine built for high-throughput LLM pipelines.
- 📊 Detailed Metrics: Returns exact character savings, estimated original & compressed token counts, and reduction ratio.
�ash npm install context-compressor
` ypescript import { ContextCompressor } from 'context-compressor';
const compressor = new ContextCompressor();
const verboseRAGContext =
The system was initialized on Jan 10, 2025 in the primary AWS US-East region.
Database configuration specifies PostgreSQL 15 with connection pooling enabled.
const result = compressor.compress(verboseRAGContext);
console.log(result.compressedText); // Database configuration specifies PostgreSQL 15 with connection pooling enabled.
console.log(result.savedTokensRatio); // 0.45 (45% saved!) console.log(result.estimatedCompressedTokens); `
This project is licensed under the MIT License.