Skip to content

Commit 946e159

Browse files
authored
Merge pull request FlowiseAI#1243 from FlowiseAI/feature/VectorStoreRevamp
Feature/add vector upsert ability
2 parents 47cc4fe + 6878723 commit 946e159

File tree

114 files changed

+10048
-4466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+10048
-4466
lines changed

packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class MRKLAgentChat_Agents implements INode {
1818
inputs: INodeParams[]
1919

2020
constructor() {
21-
this.label = 'MRKL Agent for Chat Models'
21+
this.label = 'ReAct Agent for Chat Models'
2222
this.name = 'mrklAgentChat'
2323
this.version = 1.0
2424
this.type = 'AgentExecutor'
2525
this.category = 'Agents'
2626
this.icon = 'agent.svg'
27-
this.description = 'Agent that uses the ReAct Framework to decide what action to take, optimized to be used with Chat Models'
27+
this.description = 'Agent that uses the ReAct logic to decide what action to take, optimized to be used with Chat Models'
2828
this.baseClasses = [this.type, ...getBaseClasses(AgentExecutor)]
2929
this.inputs = [
3030
{

packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class MRKLAgentLLM_Agents implements INode {
1818
inputs: INodeParams[]
1919

2020
constructor() {
21-
this.label = 'MRKL Agent for LLMs'
21+
this.label = 'ReAct Agent for LLMs'
2222
this.name = 'mrklAgentLLM'
2323
this.version = 1.0
2424
this.type = 'AgentExecutor'
2525
this.category = 'Agents'
2626
this.icon = 'agent.svg'
27-
this.description = 'Agent that uses the ReAct Framework to decide what action to take, optimized to be used with LLMs'
27+
this.description = 'Agent that uses the ReAct logic to decide what action to take, optimized to be used with LLMs'
2828
this.baseClasses = [this.type, ...getBaseClasses(AgentExecutor)]
2929
this.inputs = [
3030
{

packages/components/nodes/retrievers/HydeRetriever/HydeRetriever.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class HydeRetriever_Retrievers implements INode {
104104
const promptKey = nodeData.inputs?.promptKey as PromptKey
105105
const customPrompt = nodeData.inputs?.customPrompt as string
106106
const topK = nodeData.inputs?.topK as string
107-
const k = topK ? parseInt(topK, 10) : 4
107+
const k = topK ? parseFloat(topK) : 4
108108

109109
const obj: HydeRetrieverOptions<any> = {
110110
llm,

packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ZapierNLA_Tools implements INode {
1111
type: string
1212
icon: string
1313
category: string
14+
badge: string
1415
baseClasses: string[]
1516
inputs: INodeParams[]
1617
credential: INodeParams
@@ -23,6 +24,7 @@ class ZapierNLA_Tools implements INode {
2324
this.icon = 'zapier.svg'
2425
this.category = 'Tools'
2526
this.description = "Access to apps and actions on Zapier's platform through a natural language API interface"
27+
this.badge = 'DEPRECATING'
2628
this.inputs = []
2729
this.credential = {
2830
label: 'Connect Credential',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { flatten } from 'lodash'
2+
import { Chroma } from 'langchain/vectorstores/chroma'
3+
import { Embeddings } from 'langchain/embeddings/base'
4+
import { Document } from 'langchain/document'
5+
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
6+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
7+
import { ChromaExtended } from './core'
8+
9+
class Chroma_VectorStores implements INode {
10+
label: string
11+
name: string
12+
version: number
13+
description: string
14+
type: string
15+
icon: string
16+
category: string
17+
badge: string
18+
baseClasses: string[]
19+
inputs: INodeParams[]
20+
credential: INodeParams
21+
outputs: INodeOutputsValue[]
22+
23+
constructor() {
24+
this.label = 'Chroma'
25+
this.name = 'chroma'
26+
this.version = 1.0
27+
this.type = 'Chroma'
28+
this.icon = 'chroma.svg'
29+
this.category = 'Vector Stores'
30+
this.description = 'Upsert embedded data and perform similarity search upon query using Chroma, an open-source embedding database'
31+
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
32+
this.badge = 'NEW'
33+
this.credential = {
34+
label: 'Connect Credential',
35+
name: 'credential',
36+
type: 'credential',
37+
description: 'Only needed if you have chroma on cloud services with X-Api-key',
38+
optional: true,
39+
credentialNames: ['chromaApi']
40+
}
41+
this.inputs = [
42+
{
43+
label: 'Document',
44+
name: 'document',
45+
type: 'Document',
46+
list: true,
47+
optional: true
48+
},
49+
{
50+
label: 'Embeddings',
51+
name: 'embeddings',
52+
type: 'Embeddings'
53+
},
54+
{
55+
label: 'Collection Name',
56+
name: 'collectionName',
57+
type: 'string'
58+
},
59+
{
60+
label: 'Chroma URL',
61+
name: 'chromaURL',
62+
type: 'string',
63+
optional: true
64+
},
65+
{
66+
label: 'Chroma Metadata Filter',
67+
name: 'chromaMetadataFilter',
68+
type: 'json',
69+
optional: true,
70+
additionalParams: true
71+
},
72+
{
73+
label: 'Top K',
74+
name: 'topK',
75+
description: 'Number of top results to fetch. Default to 4',
76+
placeholder: '4',
77+
type: 'number',
78+
additionalParams: true,
79+
optional: true
80+
}
81+
]
82+
this.outputs = [
83+
{
84+
label: 'Chroma Retriever',
85+
name: 'retriever',
86+
baseClasses: this.baseClasses
87+
},
88+
{
89+
label: 'Chroma Vector Store',
90+
name: 'vectorStore',
91+
baseClasses: [this.type, ...getBaseClasses(Chroma)]
92+
}
93+
]
94+
}
95+
96+
//@ts-ignore
97+
vectorStoreMethods = {
98+
async upsert(nodeData: INodeData, options: ICommonObject): Promise<void> {
99+
const collectionName = nodeData.inputs?.collectionName as string
100+
const docs = nodeData.inputs?.document as Document[]
101+
const embeddings = nodeData.inputs?.embeddings as Embeddings
102+
const chromaURL = nodeData.inputs?.chromaURL as string
103+
104+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
105+
const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData)
106+
107+
const flattenDocs = docs && docs.length ? flatten(docs) : []
108+
const finalDocs = []
109+
for (let i = 0; i < flattenDocs.length; i += 1) {
110+
if (flattenDocs[i] && flattenDocs[i].pageContent) {
111+
finalDocs.push(new Document(flattenDocs[i]))
112+
}
113+
}
114+
115+
const obj: {
116+
collectionName: string
117+
url?: string
118+
chromaApiKey?: string
119+
} = { collectionName }
120+
if (chromaURL) obj.url = chromaURL
121+
if (chromaApiKey) obj.chromaApiKey = chromaApiKey
122+
123+
try {
124+
await ChromaExtended.fromDocuments(finalDocs, embeddings, obj)
125+
} catch (e) {
126+
throw new Error(e)
127+
}
128+
}
129+
}
130+
131+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
132+
const collectionName = nodeData.inputs?.collectionName as string
133+
const embeddings = nodeData.inputs?.embeddings as Embeddings
134+
const chromaURL = nodeData.inputs?.chromaURL as string
135+
const output = nodeData.outputs?.output as string
136+
const topK = nodeData.inputs?.topK as string
137+
const k = topK ? parseFloat(topK) : 4
138+
139+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
140+
const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData)
141+
142+
const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter
143+
144+
const obj: {
145+
collectionName: string
146+
url?: string
147+
chromaApiKey?: string
148+
filter?: object | undefined
149+
} = { collectionName }
150+
if (chromaURL) obj.url = chromaURL
151+
if (chromaApiKey) obj.chromaApiKey = chromaApiKey
152+
if (chromaMetadataFilter) {
153+
const metadatafilter = typeof chromaMetadataFilter === 'object' ? chromaMetadataFilter : JSON.parse(chromaMetadataFilter)
154+
obj.filter = metadatafilter
155+
}
156+
157+
const vectorStore = await ChromaExtended.fromExistingCollection(embeddings, obj)
158+
159+
if (output === 'retriever') {
160+
const retriever = vectorStore.asRetriever(k)
161+
return retriever
162+
} else if (output === 'vectorStore') {
163+
;(vectorStore as any).k = k
164+
return vectorStore
165+
}
166+
return vectorStore
167+
}
168+
}
169+
170+
module.exports = { nodeClass: Chroma_VectorStores }

packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Chroma_Existing_VectorStores implements INode {
1212
type: string
1313
icon: string
1414
category: string
15+
badge: string
1516
baseClasses: string[]
1617
inputs: INodeParams[]
1718
credential: INodeParams
@@ -26,6 +27,7 @@ class Chroma_Existing_VectorStores implements INode {
2627
this.category = 'Vector Stores'
2728
this.description = 'Load existing index from Chroma (i.e: Document has been upserted)'
2829
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
30+
this.badge = 'DEPRECATING'
2931
this.credential = {
3032
label: 'Connect Credential',
3133
name: 'credential',

packages/components/nodes/vectorstores/Chroma/Chroma_Upsert.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ChromaUpsert_VectorStores implements INode {
1414
type: string
1515
icon: string
1616
category: string
17+
badge: string
1718
baseClasses: string[]
1819
inputs: INodeParams[]
1920
credential: INodeParams
@@ -28,6 +29,7 @@ class ChromaUpsert_VectorStores implements INode {
2829
this.category = 'Vector Stores'
2930
this.description = 'Upsert documents to Chroma'
3031
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
32+
this.badge = 'DEPRECATING'
3133
this.credential = {
3234
label: 'Connect Credential',
3335
name: 'credential',

packages/components/nodes/vectorstores/Elasticsearch/ElasticSearchBase.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export abstract class ElasticSearchBase {
2121
type: string
2222
icon: string
2323
category: string
24+
badge: string
2425
baseClasses: string[]
2526
inputs: INodeParams[]
2627
credential: INodeParams
@@ -30,6 +31,7 @@ export abstract class ElasticSearchBase {
3031
this.type = 'Elasticsearch'
3132
this.icon = 'elasticsearch.png'
3233
this.category = 'Vector Stores'
34+
this.badge = 'DEPRECATING'
3335
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
3436
this.credential = {
3537
label: 'Connect Credential',

0 commit comments

Comments
 (0)