Skip to content

Commit

Permalink
Add tenant and database configs for Chroma Cloud credentials (Flowise…
Browse files Browse the repository at this point in the history
…AI#3872)

* Add tenant and database configs for Chroma Cloud credentials

* Lint fix
  • Loading branch information
itaismith authored and JJK801 committed Feb 3, 2025
1 parent d4a9f0c commit 55a2f83
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 90 deletions.
10 changes: 10 additions & 0 deletions packages/components/credentials/ChromaApi.credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class ChromaApi implements INodeCredential {
label: 'Chroma Api Key',
name: 'chromaApiKey',
type: 'password'
},
{
label: 'Chroma Tenant',
name: 'chromaTenant',
type: 'string'
},
{
label: 'Chroma Database',
name: 'chromaDatabase',
type: 'string'
}
]
}
Expand Down
18 changes: 18 additions & 0 deletions packages/components/nodes/vectorstores/Chroma/Chroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class Chroma_VectorStores implements INode {

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData)
const chromaTenant = getCredentialParam('chromaTenant', credentialData, nodeData)
const chromaDatabase = getCredentialParam('chromaDatabase', credentialData, nodeData)

const flattenDocs = docs && docs.length ? flatten(docs) : []
const finalDocs = []
Expand All @@ -124,9 +126,13 @@ class Chroma_VectorStores implements INode {
collectionName: string
url?: string
chromaApiKey?: string
chromaTenant?: string
chromaDatabase?: string
} = { collectionName }
if (chromaURL) obj.url = chromaURL
if (chromaApiKey) obj.chromaApiKey = chromaApiKey
if (chromaTenant) obj.chromaTenant = chromaTenant
if (chromaDatabase) obj.chromaDatabase = chromaDatabase

try {
if (recordManager) {
Expand Down Expand Up @@ -159,14 +165,20 @@ class Chroma_VectorStores implements INode {

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData)
const chromaTenant = getCredentialParam('chromaTenant', credentialData, nodeData)
const chromaDatabase = getCredentialParam('chromaDatabase', credentialData, nodeData)

const obj: {
collectionName: string
url?: string
chromaApiKey?: string
chromaTenant?: string
chromaDatabase?: string
} = { collectionName }
if (chromaURL) obj.url = chromaURL
if (chromaApiKey) obj.chromaApiKey = chromaApiKey
if (chromaTenant) obj.chromaTenant = chromaTenant
if (chromaDatabase) obj.chromaDatabase = chromaDatabase

try {
if (recordManager) {
Expand Down Expand Up @@ -199,17 +211,23 @@ class Chroma_VectorStores implements INode {

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData)
const chromaTenant = getCredentialParam('chromaTenant', credentialData, nodeData)
const chromaDatabase = getCredentialParam('chromaDatabase', credentialData, nodeData)

const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter

const obj: {
collectionName: string
url?: string
chromaApiKey?: string
chromaTenant?: string
chromaDatabase?: string
filter?: object | undefined
} = { collectionName }
if (chromaURL) obj.url = chromaURL
if (chromaApiKey) obj.chromaApiKey = chromaApiKey
if (chromaTenant) obj.chromaTenant = chromaTenant
if (chromaDatabase) obj.chromaDatabase = chromaDatabase
if (chromaMetadataFilter) {
const metadatafilter = typeof chromaMetadataFilter === 'object' ? chromaMetadataFilter : JSON.parse(chromaMetadataFilter)
obj.filter = metadatafilter
Expand Down
8 changes: 8 additions & 0 deletions packages/components/nodes/vectorstores/Chroma/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface ChromaAuth {

export class ChromaExtended extends Chroma {
chromaApiKey?: string
chromaTenant?: string
chromaDatabase?: string

constructor(embeddings: Embeddings, args: ChromaLibArgs & Partial<ChromaAuth>) {
super(embeddings, args)
Expand All @@ -34,6 +36,12 @@ export class ChromaExtended extends Chroma {
}
}
}
if (this.chromaTenant) {
obj.tenant = this.chromaTenant
}
if (this.chromaDatabase) {
obj.database = this.chromaDatabase
}
this.index = new ChromaClient(obj)
}
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"assemblyai": "^4.2.2",
"axios": "1.6.2",
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.5.11",
"chromadb": "^1.10.0",
"cohere-ai": "^7.7.5",
"composio-core": "^0.4.7",
"couchbase": "4.4.1",
Expand Down
Loading

0 comments on commit 55a2f83

Please sign in to comment.