@@ -100,6 +100,43 @@ class Chroma_VectorStores implements INode {
100100 ]
101101 }
102102
103+ private _buildChromaConfig (
104+ collectionName : string ,
105+ chromaURL : string | undefined ,
106+ chromaApiKey : string | undefined ,
107+ chromaTenant : string | undefined ,
108+ chromaDatabase : string | undefined
109+ ) : ICommonObject {
110+ const obj : {
111+ collectionName : string
112+ url ?: string
113+ chromaCloudAPIKey ?: string
114+ clientParams ?: {
115+ host ?: string
116+ port ?: number
117+ ssl ?: boolean
118+ tenant ?: string
119+ database ?: string
120+ }
121+ } = { collectionName }
122+
123+ if ( chromaURL ) obj . url = chromaURL
124+ if ( chromaApiKey ) obj . chromaCloudAPIKey = chromaApiKey
125+
126+ if ( chromaTenant || chromaDatabase ) {
127+ obj . clientParams = { }
128+ if ( chromaTenant ) obj . clientParams . tenant = chromaTenant
129+ if ( chromaDatabase ) obj . clientParams . database = chromaDatabase
130+ if ( chromaApiKey ) {
131+ obj . clientParams . host = 'api.trychroma.com'
132+ obj . clientParams . port = 8000
133+ obj . clientParams . ssl = true
134+ }
135+ }
136+
137+ return obj
138+ }
139+
103140 //@ts -ignore
104141 vectorStoreMethods = {
105142 async upsert ( nodeData : INodeData , options : ICommonObject ) : Promise < Partial < IndexingResult > > {
@@ -122,32 +159,7 @@ class Chroma_VectorStores implements INode {
122159 }
123160 }
124161
125- const obj : {
126- collectionName : string
127- url ?: string
128- chromaCloudAPIKey ?: string
129- clientParams ?: {
130- host ?: string
131- port ?: number
132- ssl ?: boolean
133- tenant ?: string
134- database ?: string
135- }
136- } = { collectionName }
137-
138- if ( chromaURL ) obj . url = chromaURL
139- if ( chromaApiKey ) obj . chromaCloudAPIKey = chromaApiKey
140-
141- if ( chromaTenant || chromaDatabase ) {
142- obj . clientParams = { }
143- if ( chromaTenant ) obj . clientParams . tenant = chromaTenant
144- if ( chromaDatabase ) obj . clientParams . database = chromaDatabase
145- if ( chromaApiKey ) {
146- obj . clientParams . host = 'api.trychroma.com'
147- obj . clientParams . port = 8000
148- obj . clientParams . ssl = true
149- }
150- }
162+ const obj = this . _buildChromaConfig ( collectionName , chromaURL , chromaApiKey , chromaTenant , chromaDatabase )
151163
152164 try {
153165 if ( recordManager ) {
@@ -183,32 +195,7 @@ class Chroma_VectorStores implements INode {
183195 const chromaTenant = getCredentialParam ( 'chromaTenant' , credentialData , nodeData )
184196 const chromaDatabase = getCredentialParam ( 'chromaDatabase' , credentialData , nodeData )
185197
186- const obj : {
187- collectionName : string
188- url ?: string
189- chromaCloudAPIKey ?: string
190- clientParams ?: {
191- host ?: string
192- port ?: number
193- ssl ?: boolean
194- tenant ?: string
195- database ?: string
196- }
197- } = { collectionName }
198-
199- if ( chromaURL ) obj . url = chromaURL
200- if ( chromaApiKey ) obj . chromaCloudAPIKey = chromaApiKey
201-
202- if ( chromaTenant || chromaDatabase ) {
203- obj . clientParams = { }
204- if ( chromaTenant ) obj . clientParams . tenant = chromaTenant
205- if ( chromaDatabase ) obj . clientParams . database = chromaDatabase
206- if ( chromaApiKey ) {
207- obj . clientParams . host = 'api.trychroma.com'
208- obj . clientParams . port = 8000
209- obj . clientParams . ssl = true
210- }
211- }
198+ const obj = this . _buildChromaConfig ( collectionName , chromaURL , chromaApiKey , chromaTenant , chromaDatabase )
212199
213200 try {
214201 if ( recordManager ) {
@@ -249,33 +236,7 @@ class Chroma_VectorStores implements INode {
249236 const chromaDatabase = getCredentialParam ( 'chromaDatabase' , credentialData , nodeData )
250237 const chromaMetadataFilter = nodeData . inputs ?. chromaMetadataFilter
251238
252- const obj : {
253- collectionName : string
254- url ?: string
255- chromaCloudAPIKey ?: string
256- clientParams ?: {
257- host ?: string
258- port ?: number
259- ssl ?: boolean
260- tenant ?: string
261- database ?: string
262- }
263- filter ?: object | undefined
264- } = { collectionName }
265-
266- if ( chromaURL ) obj . url = chromaURL
267- if ( chromaApiKey ) obj . chromaCloudAPIKey = chromaApiKey
268-
269- if ( chromaTenant || chromaDatabase ) {
270- obj . clientParams = { }
271- if ( chromaTenant ) obj . clientParams . tenant = chromaTenant
272- if ( chromaDatabase ) obj . clientParams . database = chromaDatabase
273- if ( chromaApiKey ) {
274- obj . clientParams . host = 'api.trychroma.com'
275- obj . clientParams . port = 8000
276- obj . clientParams . ssl = true
277- }
278- }
239+ const obj : ICommonObject = this . _buildChromaConfig ( collectionName , chromaURL , chromaApiKey , chromaTenant , chromaDatabase )
279240
280241 if ( chromaMetadataFilter ) {
281242 const metadatafilter = typeof chromaMetadataFilter === 'object' ? chromaMetadataFilter : parseJsonBody ( chromaMetadataFilter )
0 commit comments