From 7f04f7349ad2f25a7100d7d537686a3a06a25188 Mon Sep 17 00:00:00 2001
From: Jihan el medini <119955059+jelmedini@users.noreply.github.com>
Date: Fri, 9 Aug 2024 10:58:31 -0400
Subject: [PATCH] feat(genqa): filter citations that points to same document
(#4250)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[SVCC-4029](https://coveord.atlassian.net/browse/SVCC-4029)
- Filter citations that points to same documents.
Before:
After:
[SVCC-4029]:
https://coveord.atlassian.net/browse/SVCC-4029?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
---
.../generated-answer-slice.test.ts | 25 +++++++++++++++++++
.../generated-answer-slice.ts | 9 ++++++-
.../generated-answer.cypress.ts | 4 +--
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts b/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts
index 3f82512608f..d76cacd88b3 100644
--- a/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts
+++ b/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts
@@ -80,6 +80,7 @@ describe('generated answer slice', () => {
const newCitations = [
buildMockCitation({
id: 'some-other-id',
+ uri: 'my-uri',
}),
];
const finalState = generatedAnswerReducer(
@@ -95,6 +96,30 @@ describe('generated answer slice', () => {
...newCitations,
]);
});
+
+ it('Shows only citations that have different Uris', () => {
+ const existingCitations = [
+ buildMockCitation({
+ id: 'current-id',
+ uri: 'my-uri',
+ }),
+ ];
+ const newCitations = [
+ buildMockCitation({
+ id: 'some-other-id',
+ uri: 'my-uri',
+ }),
+ ];
+ const finalState = generatedAnswerReducer(
+ {
+ ...getGeneratedAnswerInitialState(),
+ citations: existingCitations,
+ },
+ updateCitations({citations: newCitations})
+ );
+
+ expect(finalState.citations).toEqual([...newCitations]);
+ });
});
describe('#updateError', () => {
diff --git a/packages/headless/src/features/generated-answer/generated-answer-slice.ts b/packages/headless/src/features/generated-answer/generated-answer-slice.ts
index f1935d3b59a..3da7d303558 100644
--- a/packages/headless/src/features/generated-answer/generated-answer-slice.ts
+++ b/packages/headless/src/features/generated-answer/generated-answer-slice.ts
@@ -1,5 +1,6 @@
import {createReducer} from '@reduxjs/toolkit';
import {RETRYABLE_STREAM_ERROR_CODE} from '../../api/generated-answer/generated-answer-client';
+import {GeneratedAnswerCitation} from '../../api/generated-answer/generated-answer-event-payload';
import {
closeGeneratedAnswerFeedbackModal,
dislikeGeneratedAnswer,
@@ -47,7 +48,13 @@ export const generatedAnswerReducer = createReducer(
.addCase(updateCitations, (state, {payload}) => {
state.isLoading = false;
state.isStreaming = true;
- state.citations = state.citations.concat(payload.citations);
+ const citationMap = new Map();
+ for (const citationCollection of [state.citations, payload.citations]) {
+ for (const citation of citationCollection) {
+ citationMap.set(citation.uri, citation);
+ }
+ }
+ state.citations = Array.from(citationMap.values());
delete state.error;
})
.addCase(updateError, (state, {payload}) => {
diff --git a/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts b/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts
index 3f37d68135b..4d61a6cf336 100644
--- a/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts
+++ b/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts
@@ -1124,7 +1124,7 @@ describe('quantic-generated-answer', () => {
const firstTestCitation = {
id: 'some-id-1',
title: 'Some Title 1',
- uri: 'https://www.coveo.com',
+ uri: 'https://www.coveo1.com',
permanentid: 'some-permanent-id-1',
clickUri: exampleLinkUrl,
text: 'example text 1',
@@ -1132,7 +1132,7 @@ describe('quantic-generated-answer', () => {
const secondTestCitation = {
id: 'some-id-2',
title: 'Some Title 2',
- uri: 'https://www.coveo.com',
+ uri: 'https://www.coveo2.com',
permanentid: 'some-permanent-id-2',
clickUri: exampleLinkUrl,
text: 'example text 2',