Skip to main content

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

License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_postprocessor_vecr-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_postprocessor_vecr-0.1.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_postprocessor_vecr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 98378bf1b3e0d4864c16dc5276dcdd23fbbd5af65d1d437ef7273292da99cfad
MD5 911c62cd5b8467f9729d2dc2e60f6b18
BLAKE2b-256 548e1f75eca397448277f6122598f5f81b777f4e4d72e4186338b08797c6cffa

See more details on using hashes here.

File details

Details for the file llama_index_postprocessor_vecr-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_postprocessor_vecr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65cb531a093ea54c738536c97195df25e30ae8758fd8a39d8e134ab547284ac5
MD5 3a5f488658068c504ab30dad10f3d0a6
BLAKE2b-256 bcf7806987ec47462e2e24dfdb36729ac77c8ccb5d5c8d3c0cd2b5f70fc096cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page