Adding AzureSearch AI as vector store

This commit is contained in:
2025-05-16 22:01:05 -05:00
parent 226b51a6a1
commit 3beb160c22
18 changed files with 2751 additions and 96 deletions

2
retriever/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
.env

59
retriever/index.js Normal file
View File

@@ -0,0 +1,59 @@
import {
AzureAISearchVectorStore,
AzureAISearchQueryType,
} from "@langchain/community/vectorstores/azure_aisearch";
import { OpenAIEmbeddings, AzureOpenAIEmbeddings } from "@langchain/openai";
const query = process.argv[2] || "What is CX Automation?";
// the RAG widget uses the OpenAIEmbeddings class but the config will not work because you cannot pass in the api-version param. DO NOT USE
// const embedding = new OpenAIEmbeddings({
// openAIApiKey: openAIApiKey,
// configuration: {
// baseURL: `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}?api-version=${azureOpenAIApiVersion}`,
// },
// })
const embedding = new AzureOpenAIEmbeddings({
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
});
const store = new AzureAISearchVectorStore(embedding, {
endpoint: process.env.AZURE_AISEARCH_ENDPOINT,
key: process.env.AZURE_AISEARCH_KEY,
indexName: process.env.AZURE_AISEARCH_INDEX_NAME,
search: {
type: AzureAISearchQueryType.SimilarityHybrid,
},
});
function getSourceId(document) {
if (document.metadata) {
const mergedMetadata = Object.values(document.metadata).join("");
const metatDataObj = JSON.parse(mergedMetadata);
return metatDataObj.source;
} else return undefined;
}
const resultDocuments = await store.similaritySearch(query);
const sources = resultDocuments.map((doc) => ({
source_id: getSourceId(doc),
text: doc.pageContent,
}));
const cqaSources = {
instances: [
{
sources: sources,
question: query,
knowledgebase_description: process.env.AZURE_AISEARCH_INDEX_NAME,
extra_guidance: "",
language_code: "en-GB",
},
],
};
console.log(JSON.stringify(cqaSources, null, 2));

2425
retriever/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
retriever/package.json Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "retriever",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "node --env-file=.env index.js \"What is Verint?\""
},
"author": "",
"license": "MIT",
"description": "",
"dependencies": {
"@azure/search-documents": "^12.1.0",
"@langchain/community": "^0.3.43",
"@langchain/core": "^0.3.56"
},
"type": "module"
}