Package dev.dokimos.core.evaluators
Class PrecisionEvaluator
java.lang.Object
dev.dokimos.core.BaseEvaluator
dev.dokimos.core.evaluators.PrecisionEvaluator
- All Implemented Interfaces:
Evaluator
Evaluator that measures retrieval precision.
Precision is the fraction of retrieved items that are relevant:
precision = |relevant ∩ retrieved| / |retrieved|
A precision of 1.0 means every retrieved item was relevant (no false positives). A precision of 0.0 means no retrieved items were relevant.
This evaluator supports various RAG use cases beyond document retrieval, including knowledge graph triples, API responses, and semantic matching.
Example usage:
var evaluator = PrecisionEvaluator.builder()
.name("retrieval-precision")
.retrievedKey("retrievedDocs")
.expectedKey("relevantDocs")
.matchingStrategy(MatchingStrategy.byEquality())
.threshold(0.8)
.build();
var testCase = EvalTestCase.builder()
.input("What causes diabetes?")
.actualOutput("retrievedDocs", List.of("doc_1", "doc_2", "doc_3"))
.expectedOutput("relevantDocs", List.of("doc_1", "doc_3", "doc_5"))
.build();
EvalResult result = evaluator.evaluate(testCase);
// precision = 2/3 = 0.667 (doc_1 and doc_3 are relevant)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing PrecisionEvaluator instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic PrecisionEvaluator.Builderbuilder()Creates a new builder for constructing the precision evaluator.Methods inherited from class dev.dokimos.core.BaseEvaluator
evaluate, evaluateAsync, evaluateAsync, name, threshold
-
Method Details
-
builder
Creates a new builder for constructing the precision evaluator.- Returns:
- a new builder
-