Skip to content

Commit

Permalink
Integrated APIv2 for streaming and non streaming (#163)
Browse files Browse the repository at this point in the history
* Integrated APIv2 for streaming and non streaming

* updated summary types

* updated README

* updates to README

* don't raise error if corpus key or id is available

* parsed muliple corppra keys and update the query

* updated the filters in APIv2 query

* updated with main

* updated package

* updated stream v1 config

* reverted the config for ask news

* bugfix with rerank_num_results

---------

Co-authored-by: Ofer Mendelevitch <ofermend@gmail.com>
  • Loading branch information
adeelehsan and ofermend authored Jul 25, 2024
1 parent 22d5b91 commit 1d6fb2f
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 178 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,26 @@ Note that the variables in the `.env` file all have the `REACT_APP` prefix, as i

```yaml
# These config vars are required for connecting to your Vectara data and issuing requests.
corpus_id: 5
customer_id: 123456789
corpus_id: 5
corpus_key: vectara_docs_1
api_key: "zqt_abcdef..."
```
Note that `corpud_id` can be a set of corpora in which case each query runs against all those corpora.
In such a case, the format is a comma-separated list of corpus IDs, for example:
Notes:
* Vectara APIV2 uses `corpus_key`, but the older `corpus_id` is also supported for backwards compatibility. We encourage you to use `corpus_key` as we may deprecate support for V1 in the future.
* `corpus_key` (or `corpus_id`) can be a set of corpora in which case each query runs against all those corpora. In such a case, the format is a comma-separated list of corpus keys or corpus IDs, for example:

```yaml
corpus_id: "123,234,345"
```

OR

```yaml
corpus_key: "vectara_docs_1,vectara_website_3"
```

### Search header (optional)

These configuration parameters enable you to configure the look and feel of the search header.
Expand Down
2 changes: 1 addition & 1 deletion config/ask-news/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ summary_num_sentences: 3
summary_num_results: 7

enable_source_filters: True
sources: "BBC,NPR,FOX,CNBC,CNN"
sources: "BBC,NPR,FOX,CNBC,CNN"
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/prismjs": "^1.26.0",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@vectara/stream-query-client": "^2.1.0",
"@vectara/stream-query-client": "^3.2.0",
"analytics": "^0.8.9",
"axios": "^0.27.2",
"classnames": "^2.3.2",
Expand Down
2 changes: 2 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.post("/config", (req, res) => {
// Search
endpoint,
corpus_id,
corpus_key,
customer_id,
api_key,

Expand Down Expand Up @@ -118,6 +119,7 @@ app.post("/config", (req, res) => {
// Search
endpoint,
corpus_id,
corpus_key,
customer_id,
api_key,

Expand Down
44 changes: 28 additions & 16 deletions src/contexts/ConfigurationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
interface Config {
// Search
config_endpoint?: string;
config_corpus_key?: string;
config_corpus_id?: string;
config_customer_id?: string;
config_api_key?: string;
Expand Down Expand Up @@ -63,7 +64,7 @@ interface Config {

// Summary
config_summary_default_language?: string;
config_summary_num_results?: number;
config_summary_num_results?: number
config_summary_num_sentences?: number;
config_summary_prompt_name?: string;
config_summary_prompt_text_filename?: string;
Expand Down Expand Up @@ -92,10 +93,11 @@ interface Config {

type ConfigProp = keyof Config;

const requiredConfigVars = ["corpus_id", "customer_id", "api_key", "endpoint"];
const requiredConfigVars = ["corpus_key", "corpus_id", "customer_id", "api_key", "endpoint"];

type Search = {
endpoint?: string;
corpusKey?: string;
corpusId?: string;
customerId?: string;
apiKey?: string;
Expand Down Expand Up @@ -358,19 +360,28 @@ export const ConfigContextProvider = ({ children }: Props) => {
}
}

const missingConfigProps = requiredConfigVars.reduce(
(accum, configVarName) => {
if (config[`config_${configVarName}` as ConfigProp] === undefined)
accum.push(configVarName);
const missingConfigProps = requiredConfigVars.reduce((accum, configVarName) => {
if (configVarName === "corpus_key" || configVarName === "corpus_id" ) {
// Skip this check and handle it separately
return accum;
},
[] as string[]
);
} else {
if (config[`config_${configVarName}` as ConfigProp] === undefined) {
accum.push(configVarName);
}
}
return accum;
}, [] as string[]);

if (config.config_corpus_key === undefined && config.config_corpus_id === undefined) {
missingConfigProps.push("corpus_key or corpus_id");
}

setMissingConfigProps(missingConfigProps);

const {
// Search
config_endpoint,
config_corpus_key,
config_corpus_id,
config_customer_id,
config_api_key,
Expand Down Expand Up @@ -441,6 +452,7 @@ export const ConfigContextProvider = ({ children }: Props) => {

setSearch({
endpoint: config_endpoint,
corpusKey: config_corpus_key,
corpusId: config_corpus_id,
customerId: config_customer_id,
apiKey: config_api_key,
Expand Down Expand Up @@ -501,7 +513,7 @@ export const ConfigContextProvider = ({ children }: Props) => {
}

const getRerankerDiversty = (rerankerNname: string | undefined) => {
if (rerankerNname === "mmr") return config_mmr_diversity_bias ?? rerank.diversityBias ?? 0.3
if (rerankerNname === "mmr") return Number(config_mmr_diversity_bias) ?? rerank.diversityBias ?? 0.3
else return rerank.diversityBias ?? 0.3

}
Expand All @@ -527,8 +539,8 @@ export const ConfigContextProvider = ({ children }: Props) => {
config_summary_default_language as SummaryLanguage,
"auto"
),
summaryNumResults: config_summary_num_results ?? 7,
summaryNumSentences: config_summary_num_sentences ?? 3,
summaryNumResults: Number(config_summary_num_results) ?? 7,
summaryNumSentences: Number(config_summary_num_sentences) ?? 3,
summaryPromptOptions: getPromptOptions(),
summaryPromptName:
config_summary_prompt_name ?? "vectara-summary-ext-24-05-sml",
Expand Down Expand Up @@ -561,15 +573,15 @@ export const ConfigContextProvider = ({ children }: Props) => {

setRerank({
isEnabled: isRankerEnabled(config_reranker_name),
numResults: config_rerank_num_results ?? rerank.numResults,
numResults: Number(config_rerank_num_results ?? rerank.numResults),
id: getRerankerId(config_reranker_name),
diversityBias: getRerankerDiversty(config_reranker_name),
});

setHybrid({
numWords: config_hybrid_search_num_words ?? hybrid.numWords,
lambdaLong: config_hybrid_search_lambda_long ?? hybrid.lambdaLong,
lambdaShort: config_hybrid_search_lambda_short ?? hybrid.lambdaShort,
numWords: Number(config_hybrid_search_num_words) ?? hybrid.numWords,
lambdaLong: Number(config_hybrid_search_lambda_long) ?? hybrid.lambdaLong,
lambdaShort: Number(config_hybrid_search_lambda_short) ?? hybrid.lambdaShort,
});

setResults({
Expand Down
Loading

0 comments on commit 1d6fb2f

Please sign in to comment.