mirror of https://github.com/FlowiseAI/Flowise.git
Added Opensearch credential (#2458)
* Added Openserch credential * fix issues detected by linter * rename to camelcase openSearchUrl * Update OpenSearch.ts --------- Co-authored-by: patrick <patrick.alves@br.experian.com> Co-authored-by: Henry Heng <henryheng@flowiseai.com>bugfix/Auth-Bypass
parent
ff2381741e
commit
265de4e97e
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class OpenSearchUrl implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
description: string
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'OpenSearch'
|
||||||
|
this.name = 'openSearchUrl'
|
||||||
|
this.version = 1.0
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'OpenSearch Url',
|
||||||
|
name: 'openSearchUrl',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: OpenSearchUrl }
|
||||||
|
|
@ -3,8 +3,8 @@ import { Client } from '@opensearch-project/opensearch'
|
||||||
import { Document } from '@langchain/core/documents'
|
import { Document } from '@langchain/core/documents'
|
||||||
import { OpenSearchVectorStore } from '@langchain/community/vectorstores/opensearch'
|
import { OpenSearchVectorStore } from '@langchain/community/vectorstores/opensearch'
|
||||||
import { Embeddings } from '@langchain/core/embeddings'
|
import { Embeddings } from '@langchain/core/embeddings'
|
||||||
import { INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
|
||||||
import { getBaseClasses } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
|
||||||
class OpenSearch_VectorStores implements INode {
|
class OpenSearch_VectorStores implements INode {
|
||||||
label: string
|
label: string
|
||||||
|
|
@ -18,17 +18,24 @@ class OpenSearch_VectorStores implements INode {
|
||||||
baseClasses: string[]
|
baseClasses: string[]
|
||||||
inputs: INodeParams[]
|
inputs: INodeParams[]
|
||||||
outputs: INodeOutputsValue[]
|
outputs: INodeOutputsValue[]
|
||||||
|
credential: INodeParams
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'OpenSearch'
|
this.label = 'OpenSearch'
|
||||||
this.name = 'openSearch'
|
this.name = 'openSearch'
|
||||||
this.version = 1.0
|
this.version = 2.0
|
||||||
this.type = 'OpenSearch'
|
this.type = 'OpenSearch'
|
||||||
this.icon = 'opensearch.svg'
|
this.icon = 'opensearch.svg'
|
||||||
this.category = 'Vector Stores'
|
this.category = 'Vector Stores'
|
||||||
this.description = `Upsert embedded data and perform similarity search upon query using OpenSearch, an open-source, all-in-one vector database`
|
this.description = `Upsert embedded data and perform similarity search upon query using OpenSearch, an open-source, all-in-one vector database`
|
||||||
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
|
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
|
||||||
this.badge = 'NEW'
|
this.badge = 'NEW'
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
credentialNames: ['openSearchUrl']
|
||||||
|
}
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
label: 'Document',
|
label: 'Document',
|
||||||
|
|
@ -42,12 +49,6 @@ class OpenSearch_VectorStores implements INode {
|
||||||
name: 'embeddings',
|
name: 'embeddings',
|
||||||
type: 'Embeddings'
|
type: 'Embeddings'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: 'OpenSearch URL',
|
|
||||||
name: 'opensearchURL',
|
|
||||||
type: 'string',
|
|
||||||
placeholder: 'http://127.0.0.1:9200'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Index Name',
|
label: 'Index Name',
|
||||||
name: 'indexName',
|
name: 'indexName',
|
||||||
|
|
@ -79,12 +80,14 @@ class OpenSearch_VectorStores implements INode {
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
vectorStoreMethods = {
|
vectorStoreMethods = {
|
||||||
async upsert(nodeData: INodeData): Promise<Partial<IndexingResult>> {
|
async upsert(nodeData: INodeData, _: string, options: ICommonObject): Promise<Partial<IndexingResult>> {
|
||||||
const docs = nodeData.inputs?.document as Document[]
|
const docs = nodeData.inputs?.document as Document[]
|
||||||
const embeddings = nodeData.inputs?.embeddings as Embeddings
|
const embeddings = nodeData.inputs?.embeddings as Embeddings
|
||||||
const opensearchURL = nodeData.inputs?.opensearchURL as string
|
|
||||||
const indexName = nodeData.inputs?.indexName as string
|
const indexName = nodeData.inputs?.indexName as string
|
||||||
|
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
|
||||||
|
|
||||||
const flattenDocs = docs && docs.length ? flatten(docs) : []
|
const flattenDocs = docs && docs.length ? flatten(docs) : []
|
||||||
const finalDocs = []
|
const finalDocs = []
|
||||||
for (let i = 0; i < flattenDocs.length; i += 1) {
|
for (let i = 0; i < flattenDocs.length; i += 1) {
|
||||||
|
|
@ -109,14 +112,16 @@ class OpenSearch_VectorStores implements INode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(nodeData: INodeData): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
const embeddings = nodeData.inputs?.embeddings as Embeddings
|
const embeddings = nodeData.inputs?.embeddings as Embeddings
|
||||||
const opensearchURL = nodeData.inputs?.opensearchURL as string
|
|
||||||
const indexName = nodeData.inputs?.indexName as string
|
const indexName = nodeData.inputs?.indexName as string
|
||||||
const output = nodeData.outputs?.output as string
|
const output = nodeData.outputs?.output as string
|
||||||
const topK = nodeData.inputs?.topK as string
|
const topK = nodeData.inputs?.topK as string
|
||||||
const k = topK ? parseFloat(topK) : 4
|
const k = topK ? parseFloat(topK) : 4
|
||||||
|
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
nodes: [opensearchURL]
|
nodes: [opensearchURL]
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue