Trimwise is an open-source Python library for selecting the most relevant, verbatim passages from a known source under exact token, word, or character budgets. It preserves source order and returns original character spans for auditability, with lexical, semantic, and hybrid selection modes. Built for RAG, agents, and prompt pipelines, with reproducible benchmarks and a public research artifact.
No reviews yetBe the first to leave a review for Trimwise
Maker
📌
Hey Product Hunt! I’m Aakash, the developer behind Trimwise.
While building AI agents, I kept running into the same problem: large source documents, retrieved passages, search results, and tool outputs all had to fit alongside the actual instructions in a limited prompt budget.
Like many developers, I started with simple prefix truncation: text[:N].
It was fast, but unreliable. The useful evidence might be near the beginning, buried in the middle, split across multiple sections, or just beyond N. I repeatedly ended up building custom chunking, ranking, and prompt-assembly logic for each project.
Trimwise grew out of a simpler contract I wanted:
Select the most relevant text from a known source, keep it verbatim, preserve its original order, and stay within an exact token, word, or character budget.
It is an open-source Python library with:
• lightweight lexical selection that requires no embedding model
• optional semantic and hybrid selection
• exact configurable budgets
• source-backed excerpts instead of generated summaries
• original character spans for tracing selected text back to its source
It is designed as a prompt-assembly primitive for RAG systems, agents, document workflows, and other applications where provenance and predictable limits matter.
I also released the benchmark cases, frozen outputs, scoring code, retrieval baselines, component studies, manuscript, and reproduction instructions. On the released 160-case author-annotated benchmark, the evaluated Trimwise configurations preserved complete required source spans more often than the specific compression adapters and fixed-window retrieval baselines tested. The paper also documents the failures and limitations rather than treating the benchmark as universal proof.
I’d especially appreciate feedback on the API, real-world use cases, missing selection strategies, and cases where Trimwise chooses the wrong evidence.
Thanks for checking it out!