JevRetriever
Adaptive evidence retrieval on top of your existing retriever.
JevRetriever does not replace your search system. You give it any base retriever—dense, BM25, hybrid, MMR, similarity search, vector database adapter, or your own implementation—and Jev decides whether the accumulated evidence is sufficient or whether another retrieval is needed.
Install
pip install jevretrieve
For local development:
pip install -r requirements.txt
Quick Start
from jevretrieve import JevRetriever, RetrievedDocument
class MyRetriever:
def retrieve(
self,
query: str,
top_k: int = 5,
) -> list[RetrievedDocument]:
return [
RetrievedDocument(
document_id="doc-1",
text="Your retrieved document text",
score=0.91,
)
]
retriever = JevRetriever(
base_retriever=MyRetriever(),
max_retrievals=10,
jev_api_key="YOUR_TYPESAFE_KEY",
)
result = retriever.retrieve(
"What caused the incident and who was responsible?"
)
for document in result.documents:
print(document.text)
How It Works
Your base retriever
|
v
Evidence
|
v
Jev judges
|
+----+----------------+
| |
sufficient? not sufficient
| |
YES |
| more evidence useful?
STOP +---+---+
| |
NO YES
| |
STOP retrieve again
|
v
Jev judges again
|
...
|
max retrieval limit
|
STOP
JevRetriever follows a simple adaptive evidence loop:
- Your base retriever retrieves evidence for the user's query.
- Jev evaluates the accumulated evidence.
- If the evidence is sufficient, retrieval stops.
- If the evidence is substantially redundant, retrieval stops.
- Otherwise, JevRetriever calls the same base retriever again using the same original query.
- The newly retrieved evidence is added to the accumulated evidence.
- Jev evaluates the complete accumulated evidence again.
- The process continues until stopping conditions are met or the maximum retrieval limit is reached.
Jev always evaluates the original user question against the accumulated evidence.
The base retriever remains responsible for deciding which documents are returned. JevRetriever controls the retrieval loop and stopping decision.
Base Retriever Contract
JevRetriever only requires a retriever with this interface:
class MyRetriever:
def retrieve(
self,
query: str,
top_k: int = 5,
) -> list[RetrievedDocument]:
...
The retriever can use any backend or retrieval strategy.
For example:
- Dense retrieval
- BM25
- Hybrid search
- MMR
- Vector database search
- Keyword search
- Custom retrieval systems
- Application-specific retrievers
JevRetriever does not require a specific retrieval framework.
Retrieval Budget
max_retrievals is a hard upper bound on calls to your base retriever.
The library default is:
max_retrievals=10
For example:
retriever = JevRetriever(
base_retriever=my_retriever,
max_retrievals=10,
jev_api_key="YOUR_TYPESAFE_KEY",
)
The retriever may stop earlier when:
- the accumulated evidence is sufficient, or
- the evidence is substantially redundant.
The hard retrieval limit prevents the controller from continuing indefinitely.
Retrieval Depth
The base retriever is called repeatedly with an increasing top_k value.
For example, with:
top_k=5
the retrieval loop uses:
retrieval 1 → top_k = 5
retrieval 2 → top_k = 10
retrieval 3 → top_k = 15
...
This allows compatible base retrievers to expose additional evidence on later retrieval passes while keeping the original query unchanged.
The exact behavior of repeated retrieval depends on the base retriever.
Evidence Accumulation
Documents from every retrieval pass are accumulated and evaluated together.
For example:
Retrieval 1
↓
documents A, B, C
Retrieval 2
↓
documents A, B, C, D, E
Retrieval 3
↓
documents A, B, C, D, E, F, G
Jev evaluates the complete accumulated evidence rather than evaluating each retrieval independently.
Deduplication
JevRetriever removes duplicate documents using document_id.
This means that if the same document is returned by multiple retrieval passes, it appears only once in the final result.
Example:
RetrievedDocument(
document_id="doc-123",
text="Example evidence",
)
The document_id should identify the document consistently across retrieval
calls.
If a document does not provide a document_id, JevRetriever assigns an
internal anonymous identifier for that retrieval result.
Evidence Assessment
Jev evaluates the accumulated evidence using several dimensions:
sufficiencycoveragerelevanceredundancymissing_information
Example:
result.assessment.sufficiency
result.assessment.coverage
result.assessment.relevance
result.assessment.redundancy
result.assessment.missing_information
The values for the score-based fields are normalized between 0.0 and
1.0.
Stopping Behavior
By default, JevRetriever uses the following thresholds:
sufficiency_threshold=0.85
coverage_threshold=0.85
redundancy_threshold=0.65
Evidence is considered sufficient when both:
sufficiency >= 0.85
coverage >= 0.85
Retrieval also stops when:
redundancy >= 0.65
The thresholds can be customized:
retriever = JevRetriever(
base_retriever=my_retriever,
max_retrievals=10,
sufficiency_threshold=0.90,
coverage_threshold=0.90,
redundancy_threshold=0.70,
jev_api_key="YOUR_TYPESAFE_KEY",
)
All threshold values must be between 0.0 and 1.0.
Result Object
JevRetriever.retrieve() returns a RetrievalResult.
Available fields include:
result.query
result.documents
result.assessment
result.decisions
result.retrieval_calls
result.jev_calls
result.input_tokens
result.output_tokens
result.total_jev_tokens
result.total_cost
result.iterations
query
The original user query.
documents
All unique documents accumulated during retrieval.
assessment
Jev's final assessment of the accumulated evidence.
decisions
The controller decision made after each retrieval iteration.
Each decision contains:
decision.action
decision.reason
decision.query
decision.retrieval_number
The current controller uses:
STOP
RETRIEVE_MORE
retrieval_calls
Number of calls made to the base retriever.
jev_calls
Number of Jev evaluations performed.
input_tokens
Total Jev input tokens reported by the API.
output_tokens
Total Jev output tokens reported by the API.
total_jev_tokens
Convenience property:
result.input_tokens + result.output_tokens
total_cost
Total Jev cost when available from the API.
iterations
Number of retrieval iterations performed.
API Key
JevRetriever uses the TypeSafe Jev API.
You can provide the API key directly:
retriever = JevRetriever(
base_retriever=my_retriever,
jev_api_key="YOUR_TYPESAFE_KEY",
)
Or set the environment variable:
TYPESAFE_API_KEY=YOUR_TYPESAFE_KEY
Then:
retriever = JevRetriever(
base_retriever=my_retriever,
)
The environment-variable approach is recommended for applications so that API keys do not need to be hard-coded into source files.
Jev Model
The default Jev model is:
jev_model="jev-latest"
It can be configured:
retriever = JevRetriever(
base_retriever=my_retriever,
jev_model="jev-latest",
jev_api_key="YOUR_TYPESAFE_KEY",
)
Custom Jev Client
For testing or advanced integrations, a custom JevClient can be supplied:
from jevretrieve import JevRetriever
retriever = JevRetriever(
base_retriever=my_retriever,
jev_client=my_jev_client,
)
This is useful for:
- Unit testing
- Integration testing
- Custom API clients
- Controlled experiments
Backend-Agnostic Design
JevRetriever does not assume anything about how your application retrieves documents.
Your existing retrieval system remains responsible for:
- indexing
- embeddings
- vector search
- keyword search
- ranking
- filtering
- metadata
- document storage
JevRetriever adds an adaptive evidence-control layer around that retriever.
Your Application
|
v
JevRetriever
/ \
/ \
v v
Base Retriever Jev Evaluation
| |
v v
Evidence Stop / Continue
\ /
\ /
v v
Final Evidence
Example Architecture
A typical application can use JevRetriever like this:
User Question
|
v
JevRetriever
|
+-----------------------+
| |
v v
Base Retriever Jev Evaluation
| |
v v
Documents Evidence Judgment
| |
+-----------+-----------+
|
v
Continue / Stop
|
v
Final Evidence
|
v
LLM Answer
The final answer generation remains outside JevRetriever.
JevRetriever is responsible for gathering and evaluating evidence.
Example With a Custom Retriever
from jevretrieve import JevRetriever, RetrievedDocument
class MyHybridRetriever:
def retrieve(
self,
query: str,
top_k: int = 5,
) -> list[RetrievedDocument]:
return [
RetrievedDocument(
document_id=f"doc-{index}",
text=f"Retrieved evidence {index}",
score=1.0 / index,
)
for index in range(1, top_k + 1)
]
retriever = JevRetriever(
base_retriever=MyHybridRetriever(),
max_retrievals=10,
)
result = retriever.retrieve(
"What caused the production incident?"
)
print("Retrieval calls:", result.retrieval_calls)
print("Jev calls:", result.jev_calls)
print("Documents:", len(result.documents))
for decision in result.decisions:
print(
decision.retrieval_number,
decision.action,
decision.reason,
)
Example Output
A result can look conceptually like:
Retrieval calls: 2
Jev calls: 2
Documents: 8
1 RETRIEVE_MORE Evidence is not yet sufficient. Retrieving more evidence.
2 STOP Evidence is sufficient and complete enough.
The exact result depends on the base retriever and Jev's evaluation.
Current MVP Scope
JevRetriever currently focuses on a small, explicit responsibility:
- Generic base retriever interface
- Jev evidence judgment
- Adaptive stopping
- Evidence accumulation
- Document deduplication
- Increasing retrieval depth across iterations
- Retrieval budget / hard upper limit
- Token telemetry
- Optional cost telemetry
- Backend-agnostic design
- No required vector database
- No required embedding model
- No required retrieval framework
The controller intentionally keeps retrieval simple: the original query is used for repeated retrieval passes rather than automatically rewriting or diversifying the query.
Requirements
- Python 3.10+
requests
Install dependencies with:
pip install -r requirements.txt
Development
Clone the repository and install the package in editable mode:
pip install -e .
Run the test suite:
python -m pytest
Build the package:
python -m build
Validate the distributions:
twine check dist/*
Testing
The test suite uses deterministic fake retrievers and fake Jev clients for core controller and retrieval-loop behavior.
This keeps the unit tests independent of live API calls.
The tests cover behavior including:
- stopping when evidence is sufficient
- retrieving again when evidence is insufficient
- stopping on substantial redundancy
- respecting the maximum retrieval limit
- preserving the original query
- accumulating evidence
- deduplicating documents
- rejecting invalid configuration
- rejecting empty queries
Project Structure
jevretrieve/
├── src/
│ └── jevretrieve/
│ ├── __init__.py
│ ├── client.py
│ ├── controller.py
│ ├── evaluator.py
│ ├── models.py
│ └── retriever.py
│
├── tests/
│ ├── test_models.py
│ └── test_retriever.py
│
├── examples/
│ └── basic.py
│
├── README.md
├── requirements.txt
└── pyproject.toml
Design Principle
The central design principle is:
Your retriever finds evidence. Jev decides when there is enough evidence.
This keeps JevRetriever independent from the underlying search technology while providing an adaptive retrieval loop around existing retrieval systems.
Status
JevRetriever is an early-stage package focused on the core adaptive evidence retrieval loop.
The API and behavior may evolve as the package develops.
License
MIT
Metadata
Release files for jevretrieve 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jevretrieve-0.1.2.tar.gz | 19.3 kB | Without provenance | Details for jevretrieve-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jevretrieve-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for jevretrieve-0.1.2-py3-none-any.whl |
Total release size: 32.9 kB
Release files / jevretrieve-0.1.2.tar.gz
| Download URL | jevretrieve-0.1.2.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
863c700686c8a1246f8f45b81cf11f877c77f5fb040012e4298511c3201a445c
|
|
BLAKE2b-256 checksum How to use checksums |
ceb680cca7122f445134d851f8808be51a9ccbd153e05b824db8e807960e541e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / jevretrieve-0.1.2-py3-none-any.whl
| Download URL | jevretrieve-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91a7d30ce0b4ec5540bda25a59238a8184954c9009976d3121ee805923e996ba
|
|
BLAKE2b-256 checksum How to use checksums |
4ed2cd25d86819578407861d3b60641e256e64472cbee060950d3c5409179ab3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for jevretrieve 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.