1
- import { flatten } from 'lodash'
2
- import { Pinecone } from '@pinecone-database/pinecone'
1
+ import { flatten , isEqual } from 'lodash'
2
+ import { Pinecone , PineconeConfiguration } from '@pinecone-database/pinecone'
3
3
import { PineconeStoreParams , PineconeStore } from '@langchain/pinecone'
4
4
import { Embeddings } from '@langchain/core/embeddings'
5
5
import { Document } from '@langchain/core/documents'
@@ -8,6 +8,23 @@ import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../
8
8
import { addMMRInputParams , resolveVectorStoreOrRetriever } from '../VectorStoreUtils'
9
9
import { index } from '../../../src/indexing'
10
10
11
+ let pineconeClientSingleton : Pinecone
12
+ let pineconeClientOption : PineconeConfiguration
13
+
14
+ const getPineconeClient = ( option : PineconeConfiguration ) => {
15
+ if ( ! pineconeClientSingleton ) {
16
+ // if client doesn't exists
17
+ pineconeClientSingleton = new Pinecone ( option )
18
+ pineconeClientOption = option
19
+ return pineconeClientSingleton
20
+ } else if ( pineconeClientSingleton && ! isEqual ( option , pineconeClientOption ) ) {
21
+ // if client exists but option changed
22
+ pineconeClientSingleton = new Pinecone ( option )
23
+ return pineconeClientSingleton
24
+ }
25
+ return pineconeClientSingleton
26
+ }
27
+
11
28
class Pinecone_VectorStores implements INode {
12
29
label : string
13
30
name : string
@@ -25,7 +42,7 @@ class Pinecone_VectorStores implements INode {
25
42
constructor ( ) {
26
43
this . label = 'Pinecone'
27
44
this . name = 'pinecone'
28
- this . version = 3 .0
45
+ this . version = 4 .0
29
46
this . type = 'Pinecone'
30
47
this . icon = 'pinecone.svg'
31
48
this . category = 'Vector Stores'
@@ -71,6 +88,15 @@ class Pinecone_VectorStores implements INode {
71
88
additionalParams : true ,
72
89
optional : true
73
90
} ,
91
+ {
92
+ label : 'Pinecone Text Key' ,
93
+ name : 'pineconeTextKey' ,
94
+ description : 'The key in the metadata for storing text. Default to `text`' ,
95
+ type : 'string' ,
96
+ placeholder : 'text' ,
97
+ additionalParams : true ,
98
+ optional : true
99
+ } ,
74
100
{
75
101
label : 'Pinecone Metadata Filter' ,
76
102
name : 'pineconeMetadataFilter' ,
@@ -111,13 +137,12 @@ class Pinecone_VectorStores implements INode {
111
137
const docs = nodeData . inputs ?. document as Document [ ]
112
138
const embeddings = nodeData . inputs ?. embeddings as Embeddings
113
139
const recordManager = nodeData . inputs ?. recordManager
140
+ const pineconeTextKey = nodeData . inputs ?. pineconeTextKey as string
114
141
115
142
const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
116
143
const pineconeApiKey = getCredentialParam ( 'pineconeApiKey' , credentialData , nodeData )
117
144
118
- const client = new Pinecone ( {
119
- apiKey : pineconeApiKey
120
- } )
145
+ const client = getPineconeClient ( { apiKey : pineconeApiKey } )
121
146
122
147
const pineconeIndex = client . Index ( _index )
123
148
@@ -130,7 +155,8 @@ class Pinecone_VectorStores implements INode {
130
155
}
131
156
132
157
const obj : PineconeStoreParams = {
133
- pineconeIndex
158
+ pineconeIndex,
159
+ textKey : pineconeTextKey ?? 'text'
134
160
}
135
161
136
162
if ( pineconeNamespace ) obj . namespace = pineconeNamespace
@@ -166,20 +192,18 @@ class Pinecone_VectorStores implements INode {
166
192
const pineconeNamespace = nodeData . inputs ?. pineconeNamespace as string
167
193
const pineconeMetadataFilter = nodeData . inputs ?. pineconeMetadataFilter
168
194
const embeddings = nodeData . inputs ?. embeddings as Embeddings
195
+ const pineconeTextKey = nodeData . inputs ?. pineconeTextKey as string
169
196
170
197
const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
171
198
const pineconeApiKey = getCredentialParam ( 'pineconeApiKey' , credentialData , nodeData )
172
199
173
- const client = new Pinecone ( {
174
- apiKey : pineconeApiKey
175
- } )
176
-
177
- await client . describeIndex ( index )
200
+ const client = getPineconeClient ( { apiKey : pineconeApiKey } )
178
201
179
202
const pineconeIndex = client . Index ( index )
180
203
181
204
const obj : PineconeStoreParams = {
182
- pineconeIndex
205
+ pineconeIndex,
206
+ textKey : pineconeTextKey ?? 'text'
183
207
}
184
208
185
209
if ( pineconeNamespace ) obj . namespace = pineconeNamespace
0 commit comments