@@ -3,8 +3,8 @@ import { Client } from '@opensearch-project/opensearch'
3
3
import { Document } from '@langchain/core/documents'
4
4
import { OpenSearchVectorStore } from '@langchain/community/vectorstores/opensearch'
5
5
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'
8
8
9
9
class OpenSearch_VectorStores implements INode {
10
10
label : string
@@ -18,17 +18,24 @@ class OpenSearch_VectorStores implements INode {
18
18
baseClasses : string [ ]
19
19
inputs : INodeParams [ ]
20
20
outputs : INodeOutputsValue [ ]
21
+ credential : INodeParams
21
22
22
23
constructor ( ) {
23
24
this . label = 'OpenSearch'
24
25
this . name = 'openSearch'
25
- this . version = 1 .0
26
+ this . version = 2 .0
26
27
this . type = 'OpenSearch'
27
28
this . icon = 'opensearch.svg'
28
29
this . category = 'Vector Stores'
29
30
this . description = `Upsert embedded data and perform similarity search upon query using OpenSearch, an open-source, all-in-one vector database`
30
31
this . baseClasses = [ this . type , 'VectorStoreRetriever' , 'BaseRetriever' ]
31
32
this . badge = 'NEW'
33
+ this . credential = {
34
+ label : 'Connect Credential' ,
35
+ name : 'credential' ,
36
+ type : 'credential' ,
37
+ credentialNames : [ 'openSearchUrl' ]
38
+ }
32
39
this . inputs = [
33
40
{
34
41
label : 'Document' ,
@@ -42,12 +49,6 @@ class OpenSearch_VectorStores implements INode {
42
49
name : 'embeddings' ,
43
50
type : 'Embeddings'
44
51
} ,
45
- {
46
- label : 'OpenSearch URL' ,
47
- name : 'opensearchURL' ,
48
- type : 'string' ,
49
- placeholder : 'http://127.0.0.1:9200'
50
- } ,
51
52
{
52
53
label : 'Index Name' ,
53
54
name : 'indexName' ,
@@ -79,12 +80,14 @@ class OpenSearch_VectorStores implements INode {
79
80
80
81
//@ts -ignore
81
82
vectorStoreMethods = {
82
- async upsert ( nodeData : INodeData ) : Promise < Partial < IndexingResult > > {
83
+ async upsert ( nodeData : INodeData , _ : string , options : ICommonObject ) : Promise < Partial < IndexingResult > > {
83
84
const docs = nodeData . inputs ?. document as Document [ ]
84
85
const embeddings = nodeData . inputs ?. embeddings as Embeddings
85
- const opensearchURL = nodeData . inputs ?. opensearchURL as string
86
86
const indexName = nodeData . inputs ?. indexName as string
87
87
88
+ const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
89
+ const opensearchURL = getCredentialParam ( 'openSearchUrl' , credentialData , nodeData )
90
+
88
91
const flattenDocs = docs && docs . length ? flatten ( docs ) : [ ]
89
92
const finalDocs = [ ]
90
93
for ( let i = 0 ; i < flattenDocs . length ; i += 1 ) {
@@ -109,14 +112,16 @@ class OpenSearch_VectorStores implements INode {
109
112
}
110
113
}
111
114
112
- async init ( nodeData : INodeData ) : Promise < any > {
115
+ async init ( nodeData : INodeData , _ : string , options : ICommonObject ) : Promise < any > {
113
116
const embeddings = nodeData . inputs ?. embeddings as Embeddings
114
- const opensearchURL = nodeData . inputs ?. opensearchURL as string
115
117
const indexName = nodeData . inputs ?. indexName as string
116
118
const output = nodeData . outputs ?. output as string
117
119
const topK = nodeData . inputs ?. topK as string
118
120
const k = topK ? parseFloat ( topK ) : 4
119
121
122
+ const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
123
+ const opensearchURL = getCredentialParam ( 'openSearchUrl' , credentialData , nodeData )
124
+
120
125
const client = new Client ( {
121
126
nodes : [ opensearchURL ]
122
127
} )
0 commit comments