Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ContextCompressor ⚡

npm version License: MIT Zero Dependency TypeScript

Zero-dependency token reduction engine for LLM RAG pipelines and AI Agents. Achieves 40-60% token savings while preserving semantic context.


⚡ Features

  • 🚀 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.

📦 Installation

�ash npm install context-compressor


🚀 Quick Start

` 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); `


📄 License

This project is licensed under the MIT License.

About

Zero-dependency token reduction engine for LLM RAG pipelines and AI Agents

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages