Skip to main content

langchain-highsnr

LangChain integration for HighSNR — compress documents to a token budget, keeping the highest-signal content.

pip install langchain-highsnr

Get an API key at console.high-snr.com. Requires Python 3.9+ and langchain-core>=0.3.0.


What it does

HighSNR selects the most informative chunks from a document and discards the rest, staying within a token budget. Compression is deterministic, privacy-first, and sub-second for most documents.

Class Position in pipeline Use case
HighSNRDocumentTransformer Before embedding Compress raw docs before indexing
HighSNRDocumentCompressor After retrieval Compress retrieved chunks before LLM

Usage

HighSNRDocumentTransformer — compress before indexing

from langchain_highsnr import HighSNRDocumentTransformer
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings

transformer = HighSNRDocumentTransformer(
    api_key="snr-...",       # or set HIGHSNR_API_KEY env var
    max_output_tokens=800,   # token budget per document
    context_hint="clinical trial methodology",  # optional topic hint
)

compressed = transformer.transform_documents(raw_docs)
vectorstore = FAISS.from_documents(compressed, OpenAIEmbeddings())
Parameter Default Description
api_key None Falls back to HIGHSNR_API_KEY env var
max_output_tokens 1000 Token budget per document
include_boundaries True Keep first and last chunk
context_hint None Topic/query to bias chunk selection

HighSNRDocumentCompressor — compress after retrieval

The user's query is automatically used as the selection hint.

from langchain_highsnr import HighSNRDocumentCompressor
from langchain.retrievers import ContextualCompressionRetriever

compressor = HighSNRDocumentCompressor(
    api_key="snr-...",
    max_output_tokens=2000,
)

retriever = ContextualCompressionRetriever(
    base_compressor=compressor,
    base_retriever=vectorstore.as_retriever(search_kwargs={"k": 20}),
)

docs = retriever.invoke("what is the main finding?")
Parameter Default Description
api_key None Falls back to HIGHSNR_API_KEY env var
max_output_tokens 2000 Token budget across all chunks
include_boundaries False Keep first/last chunk
group_by_source True Group chunks by metadata["source"] — one API call per source document (benchmark-validated)

Benchmarks

Evaluated on LongBench v1 with GPT-4o (n=200 per dataset). At 80% budget with hint:

  • HotpotQA: F1 70.96 — exceeds full-context GPT-4o (69.71)
  • Qasper: F1 45.21 — 96% of full-context GPT-4o (47.22)

Full results, scripts, and reproduction instructions: github.com/HighSNRInc/highsnr-benchmarks


Environment variables

Variable Description
HIGHSNR_API_KEY API key — alternative to passing api_key in the constructor
HIGHSNR_API_URL Override the API base URL (default: https://api.high-snr.com)

Links

Metadata

Release files for langchain-highsnr 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-highsnr 0.2.0
File Size Uploaded Provenance Actions
langchain_highsnr-0.2.0.tar.gz 112.6 kB With provenance Details for langchain_highsnr-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-highsnr 0.2.0
File Interpreter ABI Platform Actions
langchain_highsnr-0.2.0-py3-none-any.whl Python 3 none any Details for langchain_highsnr-0.2.0-py3-none-any.whl

Total release size: 120.4 kB

Release files / langchain_highsnr-0.2.0.tar.gz

Download URL langchain_highsnr-0.2.0.tar.gz
Size 112.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0392c983740923149e6902dc2156b566cee368508a1742b59c96f1d85727bc12
BLAKE2b-256 checksum
How to use checksums
eb8a989631cb15d82e2d19219d03bbbcb1ce2b92da04697e461e011454148648
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 31, 2026.

Transparency log

Release files / langchain_highsnr-0.2.0-py3-none-any.whl

Download URL langchain_highsnr-0.2.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b506203fb15ff8f75eb476dfd1b3367180d50af8488dfd26207c5bb68b9038e
BLAKE2b-256 checksum
How to use checksums
7f59493dff2cce35a3954317d8f1fa944a52b0c7b72feebe778789a57846aa9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 31, 2026.

Transparency log

Security for langchain-highsnr 0.2.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.

Select from 2 files

Attestation for langchain_highsnr-0.2.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 May 31, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page