Trimwise for LlamaIndex
TrimwiseNodePostprocessor trims retrieved plain TextNode evidence under one
shared allowance. It subclasses LlamaIndex's native BaseNodePostprocessor and
uses Trimwise's public sync/async context APIs. Core Trimwise has no LlamaIndex dependency.
Install
python -m pip install llama-index-postprocessor-trimwise==0.1.0
Requires Python 3.10 or later. For the PDF playground, use the complete repository checkout and its separate environment described below.
Run from source
With a Python 3.10+ virtual environment activated, run from the repository root:
python -m pip install -e . -e './integrations/llama-index[test]'
python integrations/llama-index/examples/minimal.py
python -m pytest integrations/llama-index/tests -c integrations/llama-index/pyproject.toml
For the repository's UV-managed environment, use
uv pip install --python .venv/bin/python -e . -e './integrations/llama-index[test]'
and run the commands with .venv/bin/python.
The example creates a tiny SummaryIndex, whose default retriever returns every
node, then trims and prints the evidence and source provenance. It demonstrates
framework wiring, not retrieval quality. No embedding model, answer model,
model download, external inference API, or API key is needed. Trimwise may fetch
and cache its small tiktoken vocabulary on first use.
PDF playground
The standalone LlamaIndex PDF example accepts user PDFs, performs native retrieval, and compares answers with and without this integration. It has its own lockfile and CPU-only environment; demo dependencies are kept out of this package. Run it from a complete repository checkout.
Use after retrieval
from llama_index.postprocessor.trimwise import TrimwiseNodePostprocessor
processor = TrimwiseNodePostprocessor(limit=300, strategy="lexical")
# retrieved = your_retriever.retrieve(question)
# retained = processor.postprocess_nodes(retrieved, query_str=question)
# retained = await processor.apostprocess_nodes(retrieved, query_str=question)
For an existing index and explicitly configured answer model, use the native hook:
query_engine = index.as_query_engine(llm=llm, node_postprocessors=[processor])
limit is required. Optional fields are unit (tokens, words, characters),
strategy, token_counter, and trimmer=Trimmer(...). Defaults are tokens and
automatic strategy: lexical with a nonblank question, structural without one.
Use query_str or a QueryBundle, following the base LlamaIndex API. Semantic and
hybrid strategies can use a caller-configured embedding callback on the Trimmer;
FastEmbed remains optional. Native asynchronous callbacks run on the invoking
event loop. Cancellation reaches those callbacks, though CPU worker work already
running may finish. Validation and backend errors propagate to the caller.
Budget and provenance contract
- One operation covers all retrieved nodes. The budget bounds the sum of
independently measured text outputs, including omission markers. It excludes
LlamaIndex's rendered metadata, labels, separators, templates, instructions, and
answer space. Measure the complete prompt separately with your model's tokenizer;
concatenation can change token totals.
token_counteroverrideso200k_base. - Only plain
TextNodeobjects are supported. Image, index, multimodal, and other node types raiseTypeErrorrather than silently losing non-text content. - Returned
NodeWithScoreobjects are deep copies in input order; empty evidence rows are omitted. IDs, existing metadata, relationships, text templates, and retrieval scores remain associated with their original node. Scores still describe retrieval of the original evidence; they are not recomputed. - Provenance is stored in
node.metadata["trimwise"]:source_index, originalstart_char_idx/end_char_idxunderoriginal_start_char_idx/original_end_char_idx, andspanscontaining inclusivestartand exclusiveendPython-string offsets within the original input node's plain text. Retained spans can be disjoint; omission markers have no source span. These are not offsets into the new output or coordinates on a PDF page. Keep original nodes for highlighting. - When text changes, the copied node's contiguous character offsets and cached embedding are cleared because they no longer describe the excerpt. Unchanged text retains those fields. Input nodes are never modified.
- The
trimwisemetadata key is reserved; a collision raisesValueError. Start each question from original retrieved nodes. Provenance is excluded from both LLM and embedding metadata rendering; user metadata exclusions are preserved. - Runtime Trimmer instances and token counters are excluded from Pydantic serialization. Reattach callbacks when reconstructing a processor from config.
Trimming does not establish answer correctness, enforce document permissions, or sanitize hostile document instructions.
Runtime dependencies are trimwise>=0.7,<0.8 and
llama-index-core>=0.14.25,<0.15. Core Trimwise has no LlamaIndex dependency.
Framework compatibility does not imply upstream listing.
Publishing preparation
Its independent PyPI release workflow and exact Trusted Publisher settings are documented in the release guide. Merging changes or pushing an integration tag does not publish a release.
Metadata
Release files for llama-index-postprocessor-trimwise 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llama_index_postprocessor_trimwise-0.1.0.tar.gz | 11.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_postprocessor_trimwise-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / llama_index_postprocessor_trimwise-0.1.0.tar.gz
| Download URL | llama_index_postprocessor_trimwise-0.1.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10bc102a1153da426b671aa523226a2b933f9d1922d3bde3c462622bf58f5f46
|
|
BLAKE2b-256 checksum How to use checksums |
94084077374c74e60901df4262b742a7dde232e33ebd0a4a373f7a64b231ae25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logRelease files / llama_index_postprocessor_trimwise-0.1.0-py3-none-any.whl
| Download URL | llama_index_postprocessor_trimwise-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a57ffa4bc699d26e49d0fb72d91fe1d6188f7d966696f161682abf0b312facb4
|
|
BLAKE2b-256 checksum How to use checksums |
afff0692ef37fb38ee3da186c946b255fbf3c9797397c0cfec4b15d2de66599a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for llama-index-postprocessor-trimwise 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for llama_index_postprocessor_trimwise-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.