diff --git a/packages/components/credentials/VectaraApi.credential.ts b/packages/components/credentials/VectaraApi.credential.ts new file mode 100644 index 000000000..96ad29a66 --- /dev/null +++ b/packages/components/credentials/VectaraApi.credential.ts @@ -0,0 +1,34 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class VectaraAPI implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'Vectara API' + this.name = 'vectaraApi' + this.version = 1.0 + this.inputs = [ + { + label: 'Vectara Customer ID', + name: 'customerID', + type: 'string' + }, + { + label: 'Vectara Corpus ID', + name: 'corpusID', + type: 'string' + }, + { + label: 'Vectara API Key', + name: 'apiKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: VectaraAPI } diff --git a/packages/components/nodes/vectorstores/Vectara_Existing/Vectara_Existing.ts b/packages/components/nodes/vectorstores/Vectara_Existing/Vectara_Existing.ts index fcf0b1aad..725a9e329 100644 --- a/packages/components/nodes/vectorstores/Vectara_Existing/Vectara_Existing.ts +++ b/packages/components/nodes/vectorstores/Vectara_Existing/Vectara_Existing.ts @@ -1,42 +1,36 @@ -import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface' -import { getBaseClasses } from '../../../src/utils' +import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara' class VectaraExisting_VectorStores implements INode { label: string name: string + version: number description: string type: string icon: string category: string baseClasses: string[] inputs: INodeParams[] + credential: INodeParams outputs: INodeOutputsValue[] constructor() { this.label = 'Vectara Load Existing Index' this.name = 'vectaraExistingIndex' + this.version = 1.0 this.type = 'Vectara' this.icon = 'vectara.png' this.category = 'Vector Stores' this.description = 'Load existing index from Vectara (i.e: Document has been upserted)' this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['vectaraApi'] + } this.inputs = [ - { - label: 'Vectara Customer ID', - name: 'customerID', - type: 'string' - }, - { - label: 'Vectara Corpus ID', - name: 'corpusID', - type: 'string' - }, - { - label: 'Vectara API Key', - name: 'apiKey', - type: 'password' - }, { label: 'Vectara Metadata Filter', name: 'filter', @@ -74,10 +68,12 @@ class VectaraExisting_VectorStores implements INode { } ] } - async init(nodeData: INodeData): Promise { - const customerId = nodeData.inputs?.customerID as number - const corpusId = nodeData.inputs?.corpusID as number - const apiKey = nodeData.inputs?.apiKey as string + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const apiKey = getCredentialParam('apiKey', credentialData, nodeData) + const customerId = getCredentialParam('customerID', credentialData, nodeData) + const corpusId = getCredentialParam('corpusID', credentialData, nodeData) + const vectaraMetadatafilter = nodeData.inputs?.filter as VectaraFilter const lambda = nodeData.inputs?.lambda as number const output = nodeData.outputs?.output as string diff --git a/packages/components/nodes/vectorstores/Vectara_Upsert/Vectara_Upsert.ts b/packages/components/nodes/vectorstores/Vectara_Upsert/Vectara_Upsert.ts index ea44f3c9b..bc236060e 100644 --- a/packages/components/nodes/vectorstores/Vectara_Upsert/Vectara_Upsert.ts +++ b/packages/components/nodes/vectorstores/Vectara_Upsert/Vectara_Upsert.ts @@ -1,6 +1,6 @@ -import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface' +import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface' import { Embeddings } from 'langchain/embeddings/base' -import { getBaseClasses } from '../../../src/utils' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara' import { Document } from 'langchain/document' import { flatten } from 'lodash' @@ -8,38 +8,32 @@ import { flatten } from 'lodash' class VectaraExisting_VectorStores implements INode { label: string name: string + version: number description: string type: string icon: string category: string baseClasses: string[] inputs: INodeParams[] + credential: INodeParams outputs: INodeOutputsValue[] constructor() { this.label = 'Vectara Upsert Document' this.name = 'vectaraExisting' + this.version = 1.0 this.type = 'Vectara' this.icon = 'vectara.png' this.category = 'Vector Stores' this.description = 'Upsert documents to Vectara' this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['vectaraApi'] + } this.inputs = [ - { - label: 'Vectara Customer ID', - name: 'customerID', - type: 'string' - }, - { - label: 'Vectara Corpus ID', - name: 'corpusID', - type: 'string' - }, - { - label: 'Vectara API Key', - name: 'apiKey', - type: 'password' - }, { label: 'Document', name: 'document', @@ -83,10 +77,12 @@ class VectaraExisting_VectorStores implements INode { } ] } - async init(nodeData: INodeData): Promise { - const customerId = nodeData.inputs?.customerID as number - const corpusId = nodeData.inputs?.corpusID as number - const apiKey = nodeData.inputs?.apiKey as string + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const apiKey = getCredentialParam('apiKey', credentialData, nodeData) + const customerId = getCredentialParam('customerID', credentialData, nodeData) + const corpusId = getCredentialParam('corpusID', credentialData, nodeData) + const docs = nodeData.inputs?.document as Document[] const embeddings = {} as Embeddings const vectaraMetadatafilter = nodeData.inputs?.filter as VectaraFilter