Skip to content

Commit

Permalink
Feature/Add content and metadata key for qdrant (FlowiseAI#2997)
Browse files Browse the repository at this point in the history
add content and metadata key for qdrant
  • Loading branch information
HenryHengZJ authored Aug 11, 2024
1 parent d4b4168 commit 68769f4
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions packages/components/nodes/vectorstores/Qdrant/Qdrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Qdrant_VectorStores implements INode {
constructor() {
this.label = 'Qdrant'
this.name = 'qdrant'
this.version = 3.0
this.version = 4.0
this.type = 'Qdrant'
this.icon = 'qdrant.png'
this.category = 'Vector Stores'
Expand Down Expand Up @@ -85,6 +85,24 @@ class Qdrant_VectorStores implements INode {
default: 1536,
additionalParams: true
},
{
label: 'Content Key',
name: 'contentPayloadKey',
description: 'The key for storing text. Default to `content`',
type: 'string',
default: 'content',
optional: true,
additionalParams: true
},
{
label: 'Metadata Key',
name: 'metadataPayloadKey',
description: 'The key for storing metadata. Default to `metadata`',
type: 'string',
default: 'metadata',
optional: true,
additionalParams: true
},
{
label: 'Upsert Batch Size',
name: 'batchSize',
Expand Down Expand Up @@ -168,6 +186,8 @@ class Qdrant_VectorStores implements INode {
const qdrantVectorDimension = nodeData.inputs?.qdrantVectorDimension
const recordManager = nodeData.inputs?.recordManager
const _batchSize = nodeData.inputs?.batchSize
const contentPayloadKey = nodeData.inputs?.contentPayloadKey || 'content'
const metadataPayloadKey = nodeData.inputs?.metadataPayloadKey || 'metadata'

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData)
Expand Down Expand Up @@ -197,7 +217,9 @@ class Qdrant_VectorStores implements INode {
size: qdrantVectorDimension ? parseInt(qdrantVectorDimension, 10) : 1536,
distance: qdrantSimilarity ?? 'Cosine'
}
}
},
contentPayloadKey,
metadataPayloadKey
}

try {
Expand All @@ -220,8 +242,8 @@ class Qdrant_VectorStores implements INode {
id: documentOptions?.ids?.length ? documentOptions?.ids[idx] : uuid(),
vector: embedding,
payload: {
content: documents[idx].pageContent,
metadata: documents[idx].metadata,
[contentPayloadKey]: documents[idx].pageContent,
[metadataPayloadKey]: documents[idx].metadata,
customPayload: documentOptions?.customPayload?.length ? documentOptions?.customPayload[idx] : undefined
}
}))
Expand Down Expand Up @@ -367,6 +389,8 @@ class Qdrant_VectorStores implements INode {
const output = nodeData.outputs?.output as string
const topK = nodeData.inputs?.topK as string
let queryFilter = nodeData.inputs?.qdrantFilter
const contentPayloadKey = nodeData.inputs?.contentPayloadKey || 'content'
const metadataPayloadKey = nodeData.inputs?.metadataPayloadKey || 'metadata'

const k = topK ? parseFloat(topK) : 4

Expand All @@ -383,7 +407,9 @@ class Qdrant_VectorStores implements INode {

const dbConfig: QdrantLibArgs = {
client,
collectionName
collectionName,
contentPayloadKey,
metadataPayloadKey
}

const retrieverConfig: RetrieverConfig = {
Expand Down

0 comments on commit 68769f4

Please sign in to comment.