mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
Feature/add ability to upload file from chat (#3059)
add ability to upload file from chat
This commit is contained in:
@@ -6,8 +6,9 @@ import { Document } from '@langchain/core/documents'
|
||||
import { QdrantVectorStore, QdrantLibArgs } from '@langchain/qdrant'
|
||||
import { Embeddings } from '@langchain/core/embeddings'
|
||||
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { FLOWISE_CHATID, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { index } from '../../../src/indexing'
|
||||
import { howToUseFileUpload } from '../VectorStoreUtils'
|
||||
|
||||
type RetrieverConfig = Partial<VectorStoreRetrieverInput<QdrantVectorStore>>
|
||||
type QdrantAddDocumentOptions = {
|
||||
@@ -32,7 +33,7 @@ class Qdrant_VectorStores implements INode {
|
||||
constructor() {
|
||||
this.label = 'Qdrant'
|
||||
this.name = 'qdrant'
|
||||
this.version = 4.0
|
||||
this.version = 5.0
|
||||
this.type = 'Qdrant'
|
||||
this.icon = 'qdrant.png'
|
||||
this.category = 'Vector Stores'
|
||||
@@ -78,6 +79,18 @@ class Qdrant_VectorStores implements INode {
|
||||
name: 'qdrantCollection',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
label: 'File Upload',
|
||||
name: 'fileUpload',
|
||||
description: 'Allow file upload on the chat',
|
||||
hint: {
|
||||
label: 'How to use',
|
||||
value: howToUseFileUpload
|
||||
},
|
||||
type: 'boolean',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Vector Dimension',
|
||||
name: 'qdrantVectorDimension',
|
||||
@@ -188,6 +201,7 @@ class Qdrant_VectorStores implements INode {
|
||||
const _batchSize = nodeData.inputs?.batchSize
|
||||
const contentPayloadKey = nodeData.inputs?.contentPayloadKey || 'content'
|
||||
const metadataPayloadKey = nodeData.inputs?.metadataPayloadKey || 'metadata'
|
||||
const isFileUploadEnabled = nodeData.inputs?.fileUpload as boolean
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData)
|
||||
@@ -204,6 +218,9 @@ class Qdrant_VectorStores implements INode {
|
||||
const finalDocs = []
|
||||
for (let i = 0; i < flattenDocs.length; i += 1) {
|
||||
if (flattenDocs[i] && flattenDocs[i].pageContent) {
|
||||
if (isFileUploadEnabled && options.chatId) {
|
||||
flattenDocs[i].metadata = { ...flattenDocs[i].metadata, [FLOWISE_CHATID]: options.chatId }
|
||||
}
|
||||
finalDocs.push(new Document(flattenDocs[i]))
|
||||
}
|
||||
}
|
||||
@@ -391,6 +408,7 @@ class Qdrant_VectorStores implements INode {
|
||||
let queryFilter = nodeData.inputs?.qdrantFilter
|
||||
const contentPayloadKey = nodeData.inputs?.contentPayloadKey || 'content'
|
||||
const metadataPayloadKey = nodeData.inputs?.metadataPayloadKey || 'metadata'
|
||||
const isFileUploadEnabled = nodeData.inputs?.fileUpload as boolean
|
||||
|
||||
const k = topK ? parseFloat(topK) : 4
|
||||
|
||||
@@ -434,6 +452,25 @@ class Qdrant_VectorStores implements INode {
|
||||
if (queryFilter) {
|
||||
retrieverConfig.filter = typeof queryFilter === 'object' ? queryFilter : JSON.parse(queryFilter)
|
||||
}
|
||||
if (isFileUploadEnabled && options.chatId) {
|
||||
retrieverConfig.filter = retrieverConfig.filter || {}
|
||||
|
||||
retrieverConfig.filter.should = Array.isArray(retrieverConfig.filter.should) ? retrieverConfig.filter.should : []
|
||||
|
||||
retrieverConfig.filter.should.push(
|
||||
{
|
||||
key: `metadata.${FLOWISE_CHATID}`,
|
||||
match: {
|
||||
value: options.chatId
|
||||
}
|
||||
},
|
||||
{
|
||||
is_empty: {
|
||||
key: `metadata.${FLOWISE_CHATID}`
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const vectorStore = await QdrantVectorStore.fromExistingCollection(embeddings, dbConfig)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user