LlamaIndex postprocessor for vecr-compress: deterministic retention-guaranteed node compression.
Project description
llama-index-postprocessor-vecr
Retention-guaranteed node compression for LlamaIndex RAG pipelines. This partner package wraps vecr-compress — the only LLM context compressor that makes a deterministic retention contract: order IDs, dates, URLs, emails, and code references are pinned by an auditable regex whitelist before any token-budget packing runs. Filler prose is dropped, high-signal sentences are ranked by question-aware Jaccard scoring, and your retrieved nodes arrive at the synthesizer with all structured facts intact.
Install
pip install llama-index-postprocessor-vecr
This installs vecr-compress and llama-index-core automatically.
30-second example
from llama_index.core.schema import NodeWithScore, TextNode
from llama_index.postprocessor.vecr import VecrNodePostprocessor
nodes = [
NodeWithScore(
node=TextNode(
id_="node-1",
text=(
"The refund for order ORD-99172 was approved on 2026-03-15. "
"The total amount was $1,499.00. "
"Please see https://refunds.example.com/ORD-99172 for details."
),
),
score=0.92,
),
NodeWithScore(
node=TextNode(
id_="node-2",
text="Hi! I hope this message finds you well. Have a great day.",
),
score=0.31,
),
]
processor = VecrNodePostprocessor(budget_tokens=60)
kept = processor.postprocess_nodes(nodes, query_str="refund status for ORD-99172")
for n in kept:
print(n.node.id_, "->", n.node.text[:80])
# node-1 -> The refund for order ORD-99172 was approved ...
# (node-2 dropped: pure filler, no retention match)
The node containing ORD-99172, 2026-03-15, $1,499.00, and the URL is kept because each of those tokens fires a retention rule. The filler-only node is dropped even at an aggressive 60-token budget.
Query-aware scoring
Pass query_str to bias retained sentences toward the user's question:
kept = processor.postprocess_nodes(
nodes,
query_str="what is the refund amount?",
)
Internally, this runs Jaccard overlap between each sentence and the query before the knapsack budget packing step.
Compression telemetry
result = processor.compress_with_report(nodes, query_str="refund amount")
print(f"{result.original_tokens} -> {result.compressed_tokens} tokens ({result.ratio:.1%})")
print(f"Pinned facts: {len(result.retained_matches)}")
Custom retention rules
import re
from vecr_compress import RetentionRule, DEFAULT_RULES
custom_rules = DEFAULT_RULES.with_extra([
RetentionRule(name="sku", pattern=re.compile(r"\bSKU-[A-Z0-9]{6}\b")),
])
processor = VecrNodePostprocessor(budget_tokens=1500, retention_rules=custom_rules)
Links
- Main repo and full docs: https://github.com/h2cker/vecr
- Retention contract details: RETENTION.md
- Issues: https://github.com/h2cker/vecr/issues
License
Apache 2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_postprocessor_vecr-0.1.0.tar.gz.
File metadata
- Download URL: llama_index_postprocessor_vecr-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98378bf1b3e0d4864c16dc5276dcdd23fbbd5af65d1d437ef7273292da99cfad
|
|
| MD5 |
911c62cd5b8467f9729d2dc2e60f6b18
|
|
| BLAKE2b-256 |
548e1f75eca397448277f6122598f5f81b777f4e4d72e4186338b08797c6cffa
|
File details
Details for the file llama_index_postprocessor_vecr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_postprocessor_vecr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65cb531a093ea54c738536c97195df25e30ae8758fd8a39d8e134ab547284ac5
|
|
| MD5 |
3a5f488658068c504ab30dad10f3d0a6
|
|
| BLAKE2b-256 |
bcf7806987ec47462e2e24dfdb36729ac77c8ccb5d5c8d3c0cd2b5f70fc096cb
|