fix(aihr): suppress rejected sop answers

This commit is contained in:
2026-07-15 00:43:26 +08:00
parent 05be324738
commit 34effb2319
4 changed files with 25 additions and 4 deletions
@@ -1858,6 +1858,9 @@ public class AihrSopSeedService {
return null;
}
FeedbackFilterResult filtered = filterDownFeedback(queryText, hits);
if (filtered.hits().isEmpty()) {
return noEvidenceResponse(queryText, category, filtered.cautions());
}
return responseFromHits(category, queryText, filtered.hits(), filtered.cautions());
} catch (DataAccessException e) {
return null;
@@ -2198,7 +2201,10 @@ public class AihrSopSeedService {
}
private FeedbackFilterResult filterDownFeedback(String queryText, List<KnowledgeHit> hits) {
Set<Long> rejected = downFeedbackFragmentIds(queryText);
return filterDownFeedback(hits, downFeedbackFragmentIds(queryText));
}
static FeedbackFilterResult filterDownFeedback(List<KnowledgeHit> hits, Set<Long> rejected) {
if (rejected.isEmpty()) {
return new FeedbackFilterResult(hits, List.of());
}
@@ -2207,8 +2213,8 @@ public class AihrSopSeedService {
.toList();
if (filtered.isEmpty()) {
return new FeedbackFilterResult(
hits,
List.of("该问题下命中的片段均曾被点踩,本次保留原结果避免无答案。")
List.of(),
List.of("该问题下命中的片段均曾被点踩,本次不再推送原答案。")
);
}
return new FeedbackFilterResult(filtered, List.of());
@@ -3538,7 +3544,7 @@ public class AihrSopSeedService {
record KnowledgeHit(Long fragmentId, String title, String category, String description, String docId, String content, int idx, double score) {
}
private record FeedbackFilterResult(List<KnowledgeHit> hits, List<String> cautions) {
static record FeedbackFilterResult(List<KnowledgeHit> hits, List<String> cautions) {
}
private record KnowledgeConfig(long knowledgeId, int blockSize, int overlap) {
@@ -10,6 +10,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -102,6 +103,17 @@ public class AihrSopSeedServiceTest {
assertEquals(3L, evidence.get(2).fragmentId());
}
@Test
@Tag("dev")
public void allDownVotedHitsAreSuppressed() {
List<AihrSopSeedService.KnowledgeHit> hits = List.of(hit(1L, "投诉处理 SOP.pdf"));
AihrSopSeedService.FeedbackFilterResult filtered = AihrSopSeedService.filterDownFeedback(hits, Set.of(1L));
assertTrue(filtered.hits().isEmpty());
assertTrue(filtered.cautions().get(0).contains("不再推送"));
}
@Test
@Tag("dev")
public void displaySnippetTextCleansVideoAsrNoise() {