diff --git a/README.md b/README.md index cf422d6..800d6cc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # Stream-Query-Client -Stream-Query-Client is the easiest way to use Vectara's streaming query API. Simply provide a query configuration and a callback to instantly receive stream updates. +Stream-Query-Client is the easiest way to use Vectara's streaming query API in your JavaScript applications. Simply provide a query configuration and a callback to instantly receive stream updates. > [!TIP] > diff --git a/src/client.ts b/src/client.ts index 58868fd..b82a4c6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -20,17 +20,22 @@ export const streamQuery = async ( "Content-Type": "application/json", }; - const lambda = - typeof config.queryValue === "undefined" || - config.queryValue.trim().split(" ").length > config.hybridNumWords - ? config.hybridLambdaLong - : config.hybridLambdaShort; + // Normalizes lambda to ensure that: + // - lambda is between 0 and 1 + // - lambda is always a positive number + let normalizedLambda = config.lambda ?? 0.025; + if (normalizedLambda > 1) { + normalizedLambda = 1.0; + } else if (normalizedLambda < 0) { + normalizedLambda = 0; + } + const corpusKeyList = config.corpusIds.map((id) => { return { customerId: config.customerId, corpusId: id, lexicalInterpolationConfig: { - lambda: lambda, + lambda: normalizedLambda, }, metadataFilter: config.filter ? `doc.source = '${config.filter}'` @@ -38,6 +43,21 @@ export const streamQuery = async ( }; }); + const rerankingConfig = !config.rerank + ? {} + : { + rerankingConfig: { + rerankerId: config.rerankerId, + ...(config.rerankerId === 272725718 + ? { + mmrConfig: { + diversityBias: config.rerankDiversityBias, + }, + } + : {}), + }, + }; + const requestBody = JSON.stringify({ query: [ { @@ -62,20 +82,7 @@ export const streamQuery = async ( }, }, ], - ...(config.rerank - ? { - rerankingConfig: { - rerankerId: config.rerankerId, - ...(config.rerankerId === 272725718 - ? { - mmrConfig: { - diversityBias: config.rerankDiversityBias, - }, - } - : {}), - }, - } - : {}), + ...rerankingConfig, }, ], }); diff --git a/src/types.ts b/src/types.ts index c498670..2c565da 100644 --- a/src/types.ts +++ b/src/types.ts @@ -48,14 +48,24 @@ export type StreamQueryConfig = { // The language the summary should be in. language?: SummaryLanguage; + // Reranking orders your search results for increased relevance. rerank?: boolean; + + // Specify how many search results to retrieve and rerank. rerankNumResults?: number; + + // Which reranker will be used. rerankerId?: number; + + // Diversity bias ranges from 0 to 1. + // 0 will optimize for results that are as closely related to the query as possible. + // 1 will optimize for results that are as diverse as possible. rerankDiversityBias?: number; - hybridNumWords: number; - hybridLambdaShort?: number; - hybridLambdaLong?: number; + // A number from 0.0 -> 1.0 that determines how much to leverage neural search and keyword search. + // A value of 0.0 is purely neural search, where a value of 1.0 is purely keyword search. + // Numbers in between are a combination of the two, leaning one way or another. + lambda?: number; // The number of search results to include in creating the summary summaryNumResults?: number;