Skip to content

Commit 265de4e

Browse files
patrickreinanpatrickalvesexperianHenryHengZJ
authored
Added Opensearch credential (FlowiseAI#2458)
* Added Openserch credential * fix issues detected by linter * rename to camelcase openSearchUrl * Update OpenSearch.ts --------- Co-authored-by: patrick <[email protected]> Co-authored-by: Henry Heng <[email protected]>
1 parent ff23817 commit 265de4e

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class OpenSearchUrl implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
description: string
8+
inputs: INodeParams[]
9+
10+
constructor() {
11+
this.label = 'OpenSearch'
12+
this.name = 'openSearchUrl'
13+
this.version = 1.0
14+
this.inputs = [
15+
{
16+
label: 'OpenSearch Url',
17+
name: 'openSearchUrl',
18+
type: 'string'
19+
}
20+
]
21+
}
22+
}
23+
24+
module.exports = { credClass: OpenSearchUrl }

packages/components/nodes/vectorstores/OpenSearch/OpenSearch.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Client } from '@opensearch-project/opensearch'
33
import { Document } from '@langchain/core/documents'
44
import { OpenSearchVectorStore } from '@langchain/community/vectorstores/opensearch'
55
import { Embeddings } from '@langchain/core/embeddings'
6-
import { INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
7-
import { getBaseClasses } from '../../../src/utils'
6+
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
7+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
88

99
class OpenSearch_VectorStores implements INode {
1010
label: string
@@ -18,17 +18,24 @@ class OpenSearch_VectorStores implements INode {
1818
baseClasses: string[]
1919
inputs: INodeParams[]
2020
outputs: INodeOutputsValue[]
21+
credential: INodeParams
2122

2223
constructor() {
2324
this.label = 'OpenSearch'
2425
this.name = 'openSearch'
25-
this.version = 1.0
26+
this.version = 2.0
2627
this.type = 'OpenSearch'
2728
this.icon = 'opensearch.svg'
2829
this.category = 'Vector Stores'
2930
this.description = `Upsert embedded data and perform similarity search upon query using OpenSearch, an open-source, all-in-one vector database`
3031
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
3132
this.badge = 'NEW'
33+
this.credential = {
34+
label: 'Connect Credential',
35+
name: 'credential',
36+
type: 'credential',
37+
credentialNames: ['openSearchUrl']
38+
}
3239
this.inputs = [
3340
{
3441
label: 'Document',
@@ -42,12 +49,6 @@ class OpenSearch_VectorStores implements INode {
4249
name: 'embeddings',
4350
type: 'Embeddings'
4451
},
45-
{
46-
label: 'OpenSearch URL',
47-
name: 'opensearchURL',
48-
type: 'string',
49-
placeholder: 'http://127.0.0.1:9200'
50-
},
5152
{
5253
label: 'Index Name',
5354
name: 'indexName',
@@ -79,12 +80,14 @@ class OpenSearch_VectorStores implements INode {
7980

8081
//@ts-ignore
8182
vectorStoreMethods = {
82-
async upsert(nodeData: INodeData): Promise<Partial<IndexingResult>> {
83+
async upsert(nodeData: INodeData, _: string, options: ICommonObject): Promise<Partial<IndexingResult>> {
8384
const docs = nodeData.inputs?.document as Document[]
8485
const embeddings = nodeData.inputs?.embeddings as Embeddings
85-
const opensearchURL = nodeData.inputs?.opensearchURL as string
8686
const indexName = nodeData.inputs?.indexName as string
8787

88+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
89+
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
90+
8891
const flattenDocs = docs && docs.length ? flatten(docs) : []
8992
const finalDocs = []
9093
for (let i = 0; i < flattenDocs.length; i += 1) {
@@ -109,14 +112,16 @@ class OpenSearch_VectorStores implements INode {
109112
}
110113
}
111114

112-
async init(nodeData: INodeData): Promise<any> {
115+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
113116
const embeddings = nodeData.inputs?.embeddings as Embeddings
114-
const opensearchURL = nodeData.inputs?.opensearchURL as string
115117
const indexName = nodeData.inputs?.indexName as string
116118
const output = nodeData.outputs?.output as string
117119
const topK = nodeData.inputs?.topK as string
118120
const k = topK ? parseFloat(topK) : 4
119121

122+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
123+
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
124+
120125
const client = new Client({
121126
nodes: [opensearchURL]
122127
})

0 commit comments

Comments
 (0)