Adding CQA Retriever
This commit is contained in:
parent
65fb3532e3
commit
93362b209b
57
CQA_Retriever/README.md
Normal file
57
CQA_Retriever/README.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# CQA Retriever Package
|
||||||
|
|
||||||
|
- [Hub Package Readme](_studio_dependencies/README.md)
|
||||||
|
- [Widget Readme](widget/<widget_name>/_studio_dependencies/README.md)
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
- [Setup Widget Development](widget/README.md)
|
||||||
|
|
||||||
|
## Studio
|
||||||
|
|
||||||
|
Items which are provided to IVA Studio's Workspace and publications are in a
|
||||||
|
\_studio_dependencies directory.
|
||||||
|
|
||||||
|
Each widget provided in this package has its own directory under widget/
|
||||||
|
|
||||||
|
## Hub Package
|
||||||
|
|
||||||
|
Hub Package is configured through a few locations. Utilize the structure
|
||||||
|
below to understand the relationship and purpose of the different
|
||||||
|
files and locations.
|
||||||
|
|
||||||
|
File content will have instances of {{ Hub Version }} replaced with the
|
||||||
|
identified version based on git Tag.
|
||||||
|
|
||||||
|
```
|
||||||
|
/
|
||||||
|
├───\_studio\_dependencies/
|
||||||
|
│ ├───ConversationFlowExport/ -- Export of example conversation flows
|
||||||
|
│ ├───DynamicQuery/
|
||||||
|
│ ├───Engagement/
|
||||||
|
│ ├───GlobalVariable/
|
||||||
|
│ ├───ProxyScript/
|
||||||
|
│ ├───README.md -- Hub Readme Document
|
||||||
|
│ └───HubPackage.json -- Hub Name/Description and Official Verint Package
|
||||||
|
└───widget/
|
||||||
|
├───README.md -- General Development documentation
|
||||||
|
├───{widgetName}/
|
||||||
|
│ ├───\_studio\_dependencies/
|
||||||
|
│ │ └───README.md -- Widget Readme Document
|
||||||
|
│ ├───widget.config.json -- Widget Name and Description
|
||||||
|
│ └───README.md -- Development Notes for specific widget
|
||||||
|
└───{widgetName2}/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Versioning
|
||||||
|
|
||||||
|
Publication and versioning is determined by repository tags.
|
||||||
|
|
||||||
|
v1.0.0-alpha - This will indicate an alpha build (draft, alpha, beta) are
|
||||||
|
supported and anything else will result in a draft.
|
||||||
|
|
||||||
|
The published commit will be stored and used to compare with the new tag. The semantic version change will determine the increment type (MAJOR, MINOR, PATCH).
|
||||||
|
|
||||||
|
If the working directory has changes (is dirty), then it will publish as a draft-PATCH.
|
||||||
|
|
||||||
|
If publishing a version tag v1.0.0 then it will be marked as published.
|
||||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,74 @@
|
|||||||
|
const filter = {
|
||||||
|
filterExpression: CQA_RetrieverSettings.filterExpression,
|
||||||
|
};
|
||||||
|
|
||||||
|
const embedding = new langchain.openai.AzureOpenAIEmbeddings({
|
||||||
|
azureOpenAIApiInstanceName:
|
||||||
|
CQA_RetrieverSettings.azure_openai_api.instance_name,
|
||||||
|
azureOpenAIApiDeploymentName:
|
||||||
|
CQA_RetrieverSettings.azure_openai_api.deployment_name,
|
||||||
|
azureOpenAIApiVersion: CQA_RetrieverSettings.azure_openai_api.version,
|
||||||
|
azureOpenAIApiKey: CQA_RetrieverSettings.azure_openai_api.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
const store =
|
||||||
|
new langchain.community.vectorstores.azure_aisearch.AzureAISearchVectorStore(
|
||||||
|
embedding,
|
||||||
|
{
|
||||||
|
endpoint: CQA_RetrieverSettings.azure_aisearch.endpoint,
|
||||||
|
key: CQA_RetrieverSettings.azure_aisearch.key,
|
||||||
|
indexName: CQA_RetrieverSettings.azure_aisearch.index_name,
|
||||||
|
search: {
|
||||||
|
type: langchain.community.vectorstores.azure_aisearch
|
||||||
|
.AzureAISearchQueryType.SimilarityHybrid,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function getSourceId(document) {
|
||||||
|
if (document.metadata) {
|
||||||
|
const mergedMetadata = Object.values(document.metadata).join("");
|
||||||
|
const metatDataObj = JSON.parse(mergedMetadata);
|
||||||
|
|
||||||
|
if ("sourceURL" in metatDataObj) {
|
||||||
|
return metatDataObj.sourceURL;
|
||||||
|
}
|
||||||
|
if ("source" in metatDataObj) {
|
||||||
|
return metatDataObj.source;
|
||||||
|
}
|
||||||
|
if ("source_id" in metatDataObj) {
|
||||||
|
return metatDataObj.source_id;
|
||||||
|
}
|
||||||
|
if ("sourceName" in metatDataObj) {
|
||||||
|
return metatDataObj.sourceName;
|
||||||
|
}
|
||||||
|
} else return "no source found";
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
async retrieve(query) {
|
||||||
|
const resultDocuments = await store.similaritySearch(query, 20, filter);
|
||||||
|
const sources = resultDocuments.map((doc) => ({
|
||||||
|
source_id: getSourceId(doc),
|
||||||
|
text: doc.pageContent,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const cqaSources = {
|
||||||
|
instances: [
|
||||||
|
{
|
||||||
|
sources: sources,
|
||||||
|
question: query,
|
||||||
|
generate_question: true,
|
||||||
|
knowledgebase_description: "iva-vector-demo",
|
||||||
|
extra_guidance: "",
|
||||||
|
language_code: "en-GB",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (CQA_RetrieverSettings.debug)
|
||||||
|
console.log(JSON.stringify(cqaSources, null, 2));
|
||||||
|
|
||||||
|
return cqaSources;
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"azure_aisearch": {
|
||||||
|
"endpoint": "https://iva-demo-vector-service.search.windows.net",
|
||||||
|
"key": "<azure_aisearch_key>",
|
||||||
|
"index_name": "iva-vector-demo"
|
||||||
|
},
|
||||||
|
"azure_openai_api": {
|
||||||
|
"key": "<azure_openai_key>",
|
||||||
|
"instance_name": "iva-open-ai",
|
||||||
|
"deployment_name": "text-embedding-3-small",
|
||||||
|
"embeddings_deployment_name": null,
|
||||||
|
"version": "2024-08-01-preview"
|
||||||
|
},
|
||||||
|
"filterExpression": "search.in(company, 'Verint')",
|
||||||
|
"debug": true
|
||||||
|
}
|
||||||
5
CQA_Retriever/_studio_dependencies/HubPackage.json
Normal file
5
CQA_Retriever/_studio_dependencies/HubPackage.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Name": "CQA Retriever",
|
||||||
|
"Description": "Example of a RAG retriever using the CQA API",
|
||||||
|
"OfficialVerintPackage": false
|
||||||
|
}
|
||||||
80
CQA_Retriever/_studio_dependencies/README.md
Normal file
80
CQA_Retriever/_studio_dependencies/README.md
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# CQA Retriever
|
||||||
|
|
||||||
|
This package provides an example RAG process using Azure AI Search for Retrieval and the Verint DaVinci Contextual Question Answer (CQA) Service.
|
||||||
|
|
||||||
|
## What's New: Updated [24/05/2025]
|
||||||
|
|
||||||
|
- Initial Release
|
||||||
|
|
||||||
|
## Setup Instructions
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- This package requires the CQA Widget to be installed and configured.
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
1. Copy the CQA_Retriever and CQA_RetieverSettings files into **Global Variables**
|
||||||
|
2. _Optional:_ Import the Example Conversation Flow and Intent
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
#### CQA_RetieverSettings
|
||||||
|
|
||||||
|
Fill out the settings below.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"azure_aisearch": {
|
||||||
|
"endpoint": "https://iva-demo-vector-service.search.windows.net",
|
||||||
|
"key": "<azure_aisearch_key>",
|
||||||
|
"index_name": "iva-vector-demo"
|
||||||
|
},
|
||||||
|
"azure_openai_api": {
|
||||||
|
"key": "<azure_openai_key>",
|
||||||
|
"instance_name": "iva-open-ai",
|
||||||
|
"deployment_name": "text-embedding-3-small",
|
||||||
|
"embeddings_deployment_name": null,
|
||||||
|
"version": "2024-08-01-preview"
|
||||||
|
},
|
||||||
|
"filterExpression": "search.in(company, 'Verint')",
|
||||||
|
"debug": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Package Content Details
|
||||||
|
|
||||||
|
### CQA_RetieverSettings
|
||||||
|
|
||||||
|
A global variable JSON object with environment-specific settings. See above for details.
|
||||||
|
|
||||||
|
### CQA_Retriever
|
||||||
|
|
||||||
|
A global variable function which handles the logic and API calls used to retrieve documents for Context.
|
||||||
|
|
||||||
|
### Example code block that should be using in your Conversation Flows
|
||||||
|
|
||||||
|
This is included in the Example Conversation Flow if you have imported that.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(async () => {
|
||||||
|
console.log(`CQA Retrieval: ${conversationData.cqa_question}`);
|
||||||
|
conversationData.cqa_source = await CQA_Retriever().retrieve(
|
||||||
|
conversationData.cqa_question
|
||||||
|
);
|
||||||
|
})()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error.message);
|
||||||
|
recognizedObject.answers.push(error.message);
|
||||||
|
recognizedObject.errorInfo = {
|
||||||
|
...recognizedObject.errorInfo,
|
||||||
|
label: {
|
||||||
|
data: error.toJSON ? error.toJSON() : {},
|
||||||
|
message: error.message,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
next(0);
|
||||||
|
});
|
||||||
|
```
|
||||||
7
CQA_Retriever/widget/README.md
Normal file
7
CQA_Retriever/widget/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Vue 3 + Vite
|
||||||
|
|
||||||
|
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||||
|
|
||||||
|
## Recommended IDE Setup
|
||||||
|
|
||||||
|
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
|
||||||
Loading…
x
Reference in New Issue
Block a user