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.1.0.tar.gz (112.7 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.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_highsnr-0.1.0.tar.gz
  • Upload date:
  • Size: 112.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for langchain_highsnr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e45f6804c43ed58e05354aa8f362eef027acc415b2be81fcd43e95dfdc470f00
MD5 e7440baf65e1a44c964165d4a03e3535
BLAKE2b-256 4b55b89fd22a7e42d08ae41851d2062af6a45edad1ac6465902c1af44576140e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_highsnr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e20403d7c0518d9cfa0e7139547ede0414800c78f9c2c39ab0ba2a7fc2ca440
MD5 a1c9b96c56af83cf2c0719672a33a09b
BLAKE2b-256 a35284199200faf22f08169be0bfaebaaf446b10fc4c59b123b5bdd50bda04d0

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