diff --git a/README.md b/README.md index d893f7ba..2a8830e8 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ The way summarization works can be configured as follows: ux: "summary" # Default language for summary response (if not specified defaults to "auto"). +# accepts two-letter code (en) or three-letter code (eng) summary_default_language: "eng" # Number of sentences before and after relevant text segment used for summarization. @@ -272,14 +273,11 @@ reranker_name: normal | slingshot | mmr rerank_num_results: 50 ``` -To use Vectara's MMR (Maximum Marginal Relevance) functionality please set the `reranker_name = mmr`. +To use Vectara's MMR (Maximum Marginal Relevance) functionality please set the `reranker_name = mmr`, and add a `mmr_diversity_bias` value. ```yaml # Diversity bias factor (0..1) for MMR reranker. The higher the value, the more MMR is preferred over relevance. mmr_diversity_bias: 0.3 - -# number of results to use for reranking -mmr_num_results: 50 ``` ### Authentication (optional) diff --git a/package-lock.json b/package-lock.json index 97c85034..89c05177 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "@types/prismjs": "^1.26.0", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", - "@vectara/stream-query-client": "^1.0.0", + "@vectara/stream-query-client": "^2.1.0", "analytics": "^0.8.9", "axios": "^0.27.2", "classnames": "^2.3.2", @@ -4641,9 +4641,9 @@ "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" }, "node_modules/@vectara/stream-query-client": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@vectara/stream-query-client/-/stream-query-client-1.0.0.tgz", - "integrity": "sha512-S6KA/zzUDGoG7hEzQ/XTpk6NVy2Tru/zUJnuWQbNTr0Lc9fhM30VrlohtxId+8ojP3kYxCZpply7R0leC1RtgA==" + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@vectara/stream-query-client/-/stream-query-client-2.1.0.tgz", + "integrity": "sha512-RsDSweRFAEmZKAdAH6D+ZWPiQEQNxnHU6Cx4aVQ8jwHgnzmIt2jKgLvz4vm4x8Wxktx4LKWwMuZGbbT95cF5+g==" }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", diff --git a/package.json b/package.json index 7f523db0..4ff95056 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/prismjs": "^1.26.0", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", - "@vectara/stream-query-client": "^1.0.0", + "@vectara/stream-query-client": "^2.1.0", "analytics": "^0.8.9", "axios": "^0.27.2", "classnames": "^2.3.2", diff --git a/server/index.js b/server/index.js index 5870debd..14000f9f 100644 --- a/server/index.js +++ b/server/index.js @@ -81,7 +81,6 @@ app.post("/config", (req, res) => { reranker_name, // MMR - mmr_num_results, mmr_diversity_bias, // Hybrid search @@ -159,7 +158,6 @@ app.post("/config", (req, res) => { reranker_name, // MMR - mmr_num_results, mmr_diversity_bias, // Search header diff --git a/src/contexts/ConfigurationContext.tsx b/src/contexts/ConfigurationContext.tsx index c7842ea8..26214200 100644 --- a/src/contexts/ConfigurationContext.tsx +++ b/src/contexts/ConfigurationContext.tsx @@ -80,7 +80,6 @@ interface Config { // MMR - config_mmr_num_results?: number; config_mmr_diversity_bias?: number; // questions @@ -417,7 +416,6 @@ export const ConfigContextProvider = ({ children }: Props) => { // MMR config_mmr_diversity_bias, - config_mmr_num_results, // hybrid search config_hybrid_search_num_words, @@ -549,9 +547,7 @@ export const ConfigContextProvider = ({ children }: Props) => { setRerank({ isEnabled: isRankerEnabled(config_reranker_name), - numResults: config_reranker_name === "mmr" - ? (config_mmr_num_results ?? 50) - : config_rerank_num_results ?? rerank.numResults, + numResults: config_rerank_num_results ?? rerank.numResults, id: getRerankerId(config_reranker_name), diversityBias: getRerankerDiversty(config_reranker_name), }); diff --git a/src/contexts/SearchContext.tsx b/src/contexts/SearchContext.tsx index c3c39f26..102af29a 100644 --- a/src/contexts/SearchContext.tsx +++ b/src/contexts/SearchContext.tsx @@ -23,8 +23,8 @@ import { retrieveHistory, } from "./history"; import { deserializeSearchResponse } from "../utils/deserializeSearchResponse"; -import {FactualConsistencyDetail, streamQuery} from "@vectara/stream-query-client"; import { StreamUpdate } from "@vectara/stream-query-client/lib/types"; +import { streamQuery } from "@vectara/stream-query-client"; interface SearchContextType { filterValue: string; @@ -57,7 +57,7 @@ interface SearchContextType { summarizationError: SearchError | undefined; summarizationResponse: string | undefined; summaryTime: number; - factualConsistencyScore: number; + factualConsistencyScore: number | undefined; language: SummaryLanguage; summaryNumResults: number; summaryNumSentences: number; @@ -117,7 +117,7 @@ export const SearchContextProvider = ({ children }: Props) => { const [summarizationResponse, setSummarizationResponse] = useState(); const [summaryTime, setSummaryTime] = useState(0); - const [factualConsistencyScore, setFactualConsistencyScore] = useState(0); + const [factualConsistencyScore, setFactualConsistencyScore] = useState(); // Citation selection const searchResultsRef = useRef([]); @@ -287,9 +287,7 @@ export const SearchContextProvider = ({ children }: Props) => { const onStreamUpdate = (update: StreamUpdate) => { // If we send multiple requests in rapid succession, we only want to // display the results of the most recent request. - const fcsDetail = update.details?.find( - (detail) => detail.type === "factualConsistency") as - | FactualConsistencyDetail + const fcsDetail = update.details?.factualConsistency if (searchId === searchCount) { if (update.isDone) { setIsSummarizing(false); @@ -297,7 +295,7 @@ export const SearchContextProvider = ({ children }: Props) => { } setSummarizationError(undefined); setSummarizationResponse(update.updatedText ?? undefined); - setFactualConsistencyScore(fcsDetail?.data?.score) + setFactualConsistencyScore(fcsDetail?.score) } }; @@ -317,7 +315,7 @@ export const SearchContextProvider = ({ children }: Props) => { customerId: search.customerId!, corpusIds: search.corpusId!.split(","), endpoint: search.endpoint!, - apiKey: search.apiKey! + apiKey: search.apiKey!, }, onStreamUpdate ); diff --git a/src/ui/components/list/_index.scss b/src/ui/components/list/_index.scss index 1593d99e..eba082de 100644 --- a/src/ui/components/list/_index.scss +++ b/src/ui/components/list/_index.scss @@ -31,4 +31,8 @@ .vuiSummaryCitationColor { background-color: $colorAccentLightShade !important; color: $colorAccent !important; +} + +.vuiSummaryWidth { + width: 100%; } \ No newline at end of file diff --git a/src/views/search/SummaryUx.tsx b/src/views/search/SummaryUx.tsx index 652f6e07..e9214337 100644 --- a/src/views/search/SummaryUx.tsx +++ b/src/views/search/SummaryUx.tsx @@ -68,7 +68,7 @@ export const SummaryUx = () => { - + diff --git a/src/views/search/controls/OptionsDrawer.tsx b/src/views/search/controls/OptionsDrawer.tsx index 94b035f9..1f8f4a5d 100644 --- a/src/views/search/controls/OptionsDrawer.tsx +++ b/src/views/search/controls/OptionsDrawer.tsx @@ -22,10 +22,13 @@ import { import {SUMMARY_LANGUAGES, SummaryLanguage, humanizeLanguage, FCS_MODE, UiText, FcsMode} from "../types"; import { useConfigContext } from "../../../contexts/ConfigurationContext"; -const languageOptions = SUMMARY_LANGUAGES.map((code) => ({ - value: code, - label: humanizeLanguage(code), -})); +const languageOptions = SUMMARY_LANGUAGES.reduce<{ value: string; label: string }[]>((langInfo, code) => { + const label = humanizeLanguage(code); + if (!langInfo.some(option => option.label === label)) { + langInfo.push({ value: code, label }); + } + return langInfo; +}, []); const FcsOptions = FCS_MODE.map((code) => ({ value: code, diff --git a/src/views/search/types.ts b/src/views/search/types.ts index 4d2ddec8..29865e87 100644 --- a/src/views/search/types.ts +++ b/src/views/search/types.ts @@ -64,69 +64,92 @@ export type DeserializedSearchResult = { export const SUMMARY_LANGUAGES = [ "auto", - "eng", - "deu", - "fra", - "zho", - "kor", - "ara", - "rus", - "tha", - "nld", - "ita", - "por", - "spa", - "jpn", - "pol", - "tur", - "heb", - "vie", - "ind", - "ces", - "ukr", - "ell", - "fas", - "hin", - "urd", - "swe", - "ben", - "msa", - "ron", + "eng", "en", + "deu", "de", + "fra", "fr", + "zho", "zh", + "kor", "ko", + "ara", "ar", + "rus", "ru", + "tha", "th", + "nld", "nl", + "ita", "it", + "por", "pt", + "spa", "es", + "jpn", "ja", + "pol", "pl", + "tur", "tr", + "heb", "he", + "vie", "vi", + "ind", "id", + "ces", "cs", + "ukr", "uk", + "ell", "el", + "fas", "fa", + "hin", "hi", + "urd", "ur", + "swe", "sv", + "ben", "bn", + "msa", "ms", + "ron", "ro" ] as const; export type SummaryLanguage = (typeof SUMMARY_LANGUAGES)[number]; -const codeToLanguageMap: Record = { - auto: "Same as query", - eng: "English", - deu: "German", - fra: "French", - zho: "Chinese", - kor: "Korean", - ara: "Arabic", - rus: "Russian", - tha: "Thai", - nld: "Dutch", - ita: "Italian", - por: "Portugese", - spa: "Spanish", - jpn: "Japanese", - pol: "Polish", - tur: "Turkish", - heb: "Hebrew", - vie: "Vietnamese", - ind: "Indonesian", - ces: "Czech", - ukr: "Ukrainian", - ell: "Greek", - fas: "Farsi", - hin: "Hindi", - urd: "Urdu", - swe: "Swedish", - ben: "Bengali", - msa: "Malay", - ron: "Romanian", -} as const; +const languageCodes: { [key: string]: string[] } = { + "Same as query": ["auto"], + English: ["en", "eng"], + Spanish: ["es", "spa"], + French: ["fr", "fra"], + German: ["de", "deu"], + Chinese: ["zh", "zho"], + Japanese: ["ja", "jpn"], + Russian: ["ru", "rus"], + Portuguese: ["pt", "por"], + Italian: ["it", "ita"], + Korean: ["ko", "kor"], + Arabic: ["ar", "ara"], + Dutch: ["nl", "nld"], + Swedish: ["sv", "swe"], + Norwegian: ["no", "nor"], + Danish: ["da", "dan"], + Finnish: ["fi", "fin"], + Polish: ["pl", "pol"], + Czech: ["cs", "ces"], + Hungarian: ["hu", "hun"], + Romanian: ["ro", "ron"], + Turkish: ["tr", "tur"], + Bulgarian: ["bg", "bul"], + Greek: ["el", "ell"], + Hebrew: ["he", "heb"], + Thai: ["th", "tha"], + Ukrainian: ["uk", "ukr"], + Indonesian: ["id", "ind"], + Malay: ["ms", "msa"], + Vietnamese: ["vi", "vie"], + Hindi: ["hi", "hin"], + Bengali: ["bn", "ben"], + Tamil: ["ta", "tam"], + Telugu: ["te", "tel"], + Marathi: ["mr", "mar"], + Urdu: ["ur", "urd"], + Persian: ["fa", "fas"], +}; +const summaryLanguages: string[] = []; + +Object.values(languageCodes).flat().forEach(code => { + summaryLanguages.push(code); +}); + +const codeToLanguageMap = Object.entries(languageCodes).reduce( + (langCodes, [language, codes]) => { + codes.forEach((code) => { + langCodes[code as SummaryLanguage] = language; + }); + return langCodes; + }, + {} as Record +); export const humanizeLanguage = (language: SummaryLanguage): string => { return codeToLanguageMap[language];