Skip to main content

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

Project description

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

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

langchain_highsnr-0.2.0.tar.gz (112.6 kB view details)

Uploaded Source

Built Distribution

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

langchain_highsnr-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_highsnr-0.2.0.tar.gz.

File metadata

  • Download URL: langchain_highsnr-0.2.0.tar.gz
  • Upload date:
  • Size: 112.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langchain_highsnr-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0392c983740923149e6902dc2156b566cee368508a1742b59c96f1d85727bc12
MD5 9d66537fc82d02b986b0c7873f16f5c5
BLAKE2b-256 eb8a989631cb15d82e2d19219d03bbbcb1ce2b92da04697e461e011454148648

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_highsnr-0.2.0.tar.gz:

Publisher: publish.yml on HighSNRInc/langchain-highsnr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_highsnr-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_highsnr-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b506203fb15ff8f75eb476dfd1b3367180d50af8488dfd26207c5bb68b9038e
MD5 07312ebd86e28421a2c82f844f37da40
BLAKE2b-256 7f59493dff2cce35a3954317d8f1fa944a52b0c7b72feebe778789a57846aa9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_highsnr-0.2.0-py3-none-any.whl:

Publisher: publish.yml on HighSNRInc/langchain-highsnr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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