Skip to main content

jev-relevance

A drop-in relevance filter for LangChain RAG retrievers, powered by TypeSafe Jev. Wrap any BaseRetriever, and Jev decides which retrieved chunks actually answer the query. No chain plumbing, no prompt engineering, one (or a few) API calls.

from jev_relevance import JevRelevanceRetrieverBuilder

retriever = (
    JevRelevanceRetrieverBuilder()
    .with_base_retriever(my_vector_retriever)  # any LangChain BaseRetriever
    .with_top_k(5)
    .build()
)

docs = retriever.invoke("What is the capital of France?")

Because JevRelevanceRetriever is a BaseRetriever, you can swap it into an existing chain without touching anything else. It returns only the chunks that clear the relevance threshold, sorted by Jev score, with the score attached in Document.metadata["relevance"].

Features

  • Drop-in: subclass of BaseRetriever; astream, with_retriever, agent and chain wiring all keep working.
  • Two scoring modes:
    • per_chunk (default): one Jev call per query-passage pair, bounded by max_concurrency. Most accurate.
    • batched: every chunk judged in a single request for the "sub-second" latency case (max 32 chunks).
  • Two providers: TypeSafe (typesafe) and OpenRouter (openrouter), plus a factory that lets you register more without touching the core.
  • fail-open: on scoring errors you get the unfiltered candidates instead of empty context (configurable).
  • Zero magic numbers: every default lives in constants.py and every behavior is builder-parameterized.

Installation

pip install jev-relevance
# or, from this repo:
python -m venv .venv && .venv\Scripts\activate
pip install -e ".[dev]"

Python 3.10+. The library itself only needs langchain-core and langchain-typesafe.

Providers

Provider Default model Base URL
typesafe jev-latest https://api.typesafe.ai
openrouter ~typesafe/jev-latest https://openrouter.ai/api

Credentials are always passed as parameters — the library never reads env vars or .env files itself; that's the caller's job. Supply the key (and any custom base URL) directly on ProviderConfig:

from jev_relevance import JevRelevanceRetrieverBuilder, ProviderConfig

retriever = (
    JevRelevanceRetrieverBuilder()
    .with_base_retriever(my_vector_retriever)
    .with_provider(
        ProviderConfig(name="openrouter", api_key=os.environ["OPENROUTER_API_KEY"])
    )
    .build()
)

Configuration

Everything is available through the builder chain:

Builder method Default Meaning
.with_question_mode("noul" | "score") noul Noul = binary "answers or not"; score = 0..3 rubric
.with_threshold(0.5) 0.5 Noul keep-if score >= threshold
.with_score_threshold(2.0) 2.0 Score-mode keep-if grade >= threshold
.with_scoring_mode("per_chunk" | "batched") per_chunk One call per chunk, or one call for all
.with_top_k(20) 20 Max results returned after filtering
.with_max_concurrency(8) 8 Concurrent Jev calls in per-chunk mode
.with_fail_open(True) True Return unfiltered candidates on scoring error
.with_classifier(classifier) auto Inject a ready TypeSafeClassifier
.with_provider(config) typesafe Which provider config to build from

The same values can be passed directly to JevRelevanceConfig, which validates every field (pydantic) so invalid values fail fast at construction time.

Metadata attached to returned documents:

  • relevance: the Jev value (noul probability 0..1, or score grade 0..3)
  • relevance_confidence: Jev's confidence, score mode only

Question modes

  • noul — "Does this passage answer the query?" Binary yes/no probability. The default; best for a strict relevance gate.
  • score — "How well does this passage answer the query?" Rubric of 0..3 (Off-topic, Tangential, Partly answers, Fully answers), plus Jev's confidence.

Examples

See examples/drop_in.py for a runnable swap-in with a naive keyword retriever:

set TYPESAFE_API_KEY=your-key
python examples/drop_in.py --provider typesafe

set OPENROUTER_API_KEY=your-key
python examples/drop_in.py --provider openrouter

Benchmarks & dashboard

The jev-relevance-evals companion repo holds the BEIR/NFCorpus benchmark harness and a Streamlit dashboard. It scores BM25 candidates three ways on the same frozen pool — plain keyword retrieval, the Jev relevance filter (drop-in retriever), and a cheap OpenRouter LLM judge — and writes full IR metrics plus per-call cost to JSON. On nfcorpus at the default 0.5 threshold, Jev roughly doubles precision at the cost of some recall; see the companion repo for the full results tables and interactive per-query drill-downs.

Development

pip install -e ".[dev]"
python -m pytest

Tests cover builder validation, provider model-mapping, per-chunk/batched scoring, fail-open behavior, and async parity using a mocked classifier — no API keys required.

Release files for jev-relevance 0.1.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 jev-relevance 0.1.0
File Size Uploaded
jev_relevance-0.1.0.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jev-relevance 0.1.0
File Interpreter ABI Platform
jev_relevance-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.2 kB

Release files / jev_relevance-0.1.0.tar.gz

Download URL jev_relevance-0.1.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
36d12c1a55b06af5eb98c35c4c539b926f379fdc137e7d3ad2186452ff215f81
BLAKE2b-256 checksum
How to use checksums
49812b00bbdcae24403a7e63a04d2ddb08290bd7877bfe5cd95060c05a351fca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / jev_relevance-0.1.0-py3-none-any.whl

Download URL jev_relevance-0.1.0-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd930bbb108a3bc4849e7f98e86c464bd7039997e11469e8496f45d27c972d76
BLAKE2b-256 checksum
How to use checksums
5db1ddfd28aa9dc6edd7a06fe56a499ddcc53e33744fd1767689501aa5007370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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