Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mrderyk committed Apr 3, 2024
1 parent 7bd49a0 commit a2b3e75
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
>
Expand Down
47 changes: 27 additions & 20 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,44 @@ 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}'`
: undefined,
};
});

const rerankingConfig = !config.rerank
? {}
: {
rerankingConfig: {
rerankerId: config.rerankerId,
...(config.rerankerId === 272725718
? {
mmrConfig: {
diversityBias: config.rerankDiversityBias,
},
}
: {}),
},
};

const requestBody = JSON.stringify({
query: [
{
Expand All @@ -62,20 +82,7 @@ export const streamQuery = async (
},
},
],
...(config.rerank
? {
rerankingConfig: {
rerankerId: config.rerankerId,
...(config.rerankerId === 272725718
? {
mmrConfig: {
diversityBias: config.rerankDiversityBias,
},
}
: {}),
},
}
: {}),
...rerankingConfig,
},
],
});
Expand Down
16 changes: 13 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a2b3e75

Please sign in to comment.