← Back

SemCom

Semantic compression for LLM prompts in Python

Problem

LLMs bill by the token. Most prompts sent to GPT-4 or Claude contain a ton of redundancy. Think filler words, verbose phrasing, and repeated context. None of this contributes to the model's understanding, but it inflates every single API call. At scale, shaving off 30-40% of those tokens compounds into serious cost savings.

Solution

SemCom is a semantic compression library for English text. It strips linguistic redundancy while preserving the actual semantic intent. Basically, it compresses the surface form of a prompt without changing what the model understands from it.

The core insight here is that LLMs are trained to extract meaning from noisy, varied text. They don't actually need grammatically complete sentences. SemCom exploits this by aggressively removing articles, auxiliary verbs, and predictable connective tissue while keeping all the load-bearing tokens intact.

Architecture

SemCom Architecture

Key Design Decisions

Meaning-preserving, not lossy. Every compression pass runs a semantic similarity check against the original text using sentence embeddings. If the similarity drops below a certain threshold, the compression is rolled back for that specific segment.

Configurable aggression. You can tune a compression_level from 0.1 (light) to 1.0 (maximum). Higher levels trade occasional grammatical ambiguity for much better token savings.

Drop-in usage. The API surface is just a single function: semcom.compress(text). No weird configuration objects required to get started.

Stack

Python