Add detect_batch and adetect_batch with concurrent execution
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with BaseDetector in base.py:47, then read the batch implementations in lettucedetect/detectors/llm.py:614 and lettucedetect/detectors/rag_fact_checker.py:102, along with the referenced issues and batch decision. Run uv run --extra dev pytest tests/test_detector_contract_pytest.py -q to inspect the existing contract tests. Done means batch calls preserve order and single-call results, report per-request failures, obey concurrency limits, and pass the stated contract and acceptance checks.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Parent: #175 · Epic: #126 · Blocked by: #161, #165, #171, and the decision elsewhere on the batch result type and failure reporting
Branch from stateless_core; open the PR against it.
Problem
LLMDetector.predict_prompt_batch runs a hard-coded pool of 30 threads and raises on the first failure, dropping the results of requests that succeeded. No other detector has a real batch method.
Current behavior
lettucedetect/detectors/llm.py:614ThreadPoolExecutor(max_workers=30).lettucedetect/detectors/rag_fact_checker.py:102predict_prompt_batchis a plain loop.base.py:47predict_prompt_batchis abstract.
Steps
- Add
detect_batch(requests, *, min_score=0.0, include_tokens=False, include_detail=False)andadetect_batchtoBaseDetector. One result per request in input order; an empty sequence returns an empty result. Result type and per-request failure reporting follow the batch decision, and successes are returned alongside failures. - The default implementation runs
detectconcurrently in a pool ofmax_concurrencythreads (config.max_concurrency, default 30, forLLMJudgeDetectorandGenerativeDetector; the constructor keywordmax_concurrency, default 30, forRAGFactCheckerDetector, from #170). The pool only limits how many requests of one batch are submitted at once. The limit across calls is the per-instance semaphore each detector already has (#158, #163, #170), which everydetectgoes through. async def adetect_batch(requests, *, min_score=0.0, include_tokens=False, include_detail=False)runsdetect_batchin a worker thread (asyncio.to_thread) and returns the same result type. Detectors that overridedetect_batch(for example #177) getadetect_batchwithout changes; none overrides it. Whole-batch errors (step 4) are raised from the awaited call; per-request failures are reported as the batch decision says, identically todetect_batch. The pool of step 2 runs inside that one worker thread. Because the bound comes from the per-instance semaphore and not from the pool, two gatheredadetect_batchcalls, or a batch running next to singledetectandadetectcalls, together stay withinmax_concurrencyclient calls in flight.include_tokens/include_detailunsupported →InvalidInputErrorfor the whole batch before any request runs. Messages refer torequests[i]by position, never text.- Add the batch section to the contract suite: order, empty input, equal to single calls, failure reporting.
Acceptance criteria
- At most
max_concurrencyclient calls in flight on one detector instance (test with a counting fake client), fordetect_batchand foradetect_batch, counted across entry points: twoadetect_batchcalls gathered together, and a batch running next to singledetectandadetectcalls. ForRAGFactCheckerDetectorthe counted unit is a concurrentdetectcall. - A batch with many more requests than
max_concurrency(for example 100 requests withmax_concurrency=2) completes with every result correct and no deadlock. -
adetect_batchequalsdetect_batchfor the same requests (results, order, per-request failures), and the event loop keeps running while it awaits (loop ticker test). - Cancelling
adetect_batchmid-batch leaves the detector usable: no deadlock, the worker pool shuts down once its in-flight calls finish, no exception reaches the loop, and the nextdetect_batchreturns the right results. -
adetect_batch([])returns an empty result; unsupported flags raise the sameInvalidInputErrorfrom the awaited call before any request runs. - Each result equals the single
detectresult; order preserved. - One failing request doesn't discard the others, reported per the decision.
- Contract suite batch section passes for every detector class that exists at this point.
- Existing tests pass; follows CONTRIBUTING "Errors and logging".
Start here
uv run --extra dev pytest tests/test_detector_contract_pytest.py -q
- Lingua principale
- Python
- Stelle
- 615
- Fork
- 60
- Merge medio
- 1g 8h
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di KRLabsOrg/LettuceDetect
-
Stop-hook --min-confidence drops every --llm-model span (missing confidence treated as 0.0), reporting hallucinated answers as cleanForse già presa @Clannad47 l’ha presa 18 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
KRLabsOrg/LettuceDetect#117 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
KRLabsOrg/LettuceDetect#108 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 Mezza giornata Idoneità per principianti 70/100
KRLabsOrg/LettuceDetect#104 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
KRLabsOrg/LettuceDetect#181 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
KRLabsOrg/LettuceDetect#180 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di KRLabsOrg/LettuceDetect
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
igormcsouza/tether#278 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
aws-samples/sample-per-model-bedrock#803 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation p1
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
huggingface/accelerate#4511 ·
I maintainer di solito rispondono entro 1 giorno
-
follow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno