Skip to content

Commit 2ecffc1

Browse files
alexcheng1982markpollack
authored andcommitted
Refactor data filtering in RelevancyEvaluator
Replace Objects::nonNull and instanceof checks with StringUtils::hasText for more efficient and cleaner content filtering. This change simplifies the stream operation in the getContent method, improving readability and potentially performance.
1 parent 202148d commit 2ecffc1

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

spring-ai-core/src/main/java/org/springframework/ai/evaluation/RelevancyEvaluator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import java.util.Collections;
77
import java.util.List;
8-
import java.util.Objects;
98
import java.util.stream.Collectors;
9+
import org.springframework.util.StringUtils;
1010

1111
public class RelevancyEvaluator implements Evaluator {
1212

@@ -57,9 +57,7 @@ protected String doGetSupportingData(EvaluationRequest evaluationRequest) {
5757
List<Content> data = evaluationRequest.getDataList();
5858
return data.stream()
5959
.map(Content::getContent)
60-
.filter(Objects::nonNull)
61-
.filter(c -> c instanceof String)
62-
.map(Object::toString)
60+
.filter(StringUtils::hasText)
6361
.collect(Collectors.joining(System.lineSeparator()));
6462
}
6563

0 commit comments

Comments
 (0)