Skip to content

Commit

Permalink
feat(genqa): filter citations that points to same document (#4250)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmedini authored Aug 9, 2024
1 parent 03d065b commit 7f04f73
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('generated answer slice', () => {
const newCitations = [
buildMockCitation({
id: 'some-other-id',
uri: 'my-uri',
}),
];
const finalState = generatedAnswerReducer(
Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<string, GeneratedAnswerCitation>();
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}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,15 @@ 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',
};
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',
Expand Down

0 comments on commit 7f04f73

Please sign in to comment.