Trimwise is an extractive Python library for the step between collecting text and assembling a prompt. Give it a document, a maximum size, and optionally the task you care about. It selects useful fragments from across the document, returns them in source order, and guarantees that the measured result stays within your token, word, or character limit.
This is especially useful when an agent has several sources but cannot place every source in the context window. Instead of taking the first N characters from each article, report, note, or search result, Trimwise gives each source a smarter evidence budget while leaving your system prompt, instructions, examples, and output schema untouched.
Features
- Exact token, word, or character budgets
- Query-aware lexical, semantic, and hybrid trimming
- Verbatim excerpts in original source order
- Source spans for exact provenance
- Multi-source trimming under one shared budget
- Markdown-aware structural selection
- Lightweight lexical mode with no model or API key
- Sync, async, and concurrent batch APIs
- Custom sync and async embedding callbacks
- Optional local FastEmbed CPU and GPU models
- Custom token counters for target models
- Typed Python package supporting Python 3.10–3.14
- Public benchmark covering evidence survival, answer match, and warm latency
- Automatic strategy selection for query and queryless use
- Prompt-ready source labels, wrappers, and omission markers
License
MIT LicenseOther Useful Business Software
$300 Free Credits to Build on Google Cloud
Put your $300 in credit toward real workloads, then keep building with free monthly usage for 20+ products. No commitment and no charge until you upgrade.
Rate This Project
Login To Rate This Project
User Reviews
Be the first to post a review of trimwise!