@@ -3,6 +3,9 @@ import { QdrantClient } from '@qdrant/js-client-rest'
3
3
import { QdrantVectorStore , QdrantLibArgs } from 'langchain/vectorstores/qdrant'
4
4
import { Embeddings } from 'langchain/embeddings/base'
5
5
import { getBaseClasses , getCredentialData , getCredentialParam } from '../../../src/utils'
6
+ import { VectorStoreRetrieverInput } from 'langchain/vectorstores/base'
7
+
8
+ type RetrieverConfig = Partial < VectorStoreRetrieverInput < QdrantVectorStore > >
6
9
7
10
class Qdrant_Existing_VectorStores implements INode {
8
11
label : string
@@ -53,7 +56,7 @@ class Qdrant_Existing_VectorStores implements INode {
53
56
} ,
54
57
{
55
58
label : 'Qdrant Collection Cofiguration' ,
56
- name : 'qdrantCollectionCofiguration ' ,
59
+ name : 'qdrantCollectionConfiguration ' ,
57
60
type : 'json' ,
58
61
optional : true ,
59
62
additionalParams : true
@@ -66,6 +69,14 @@ class Qdrant_Existing_VectorStores implements INode {
66
69
type : 'number' ,
67
70
additionalParams : true ,
68
71
optional : true
72
+ } ,
73
+ {
74
+ label : 'Qdrant Search Filter' ,
75
+ name : 'qdrantFilter' ,
76
+ description : 'Only return points which satisfy the conditions' ,
77
+ type : 'json' ,
78
+ additionalParams : true ,
79
+ optional : true
69
80
}
70
81
]
71
82
this . outputs = [
@@ -85,10 +96,12 @@ class Qdrant_Existing_VectorStores implements INode {
85
96
async init ( nodeData : INodeData , _ : string , options : ICommonObject ) : Promise < any > {
86
97
const qdrantServerUrl = nodeData . inputs ?. qdrantServerUrl as string
87
98
const collectionName = nodeData . inputs ?. qdrantCollection as string
88
- let qdrantCollectionCofiguration = nodeData . inputs ?. qdrantCollectionCofiguration
99
+ let qdrantCollectionConfiguration = nodeData . inputs ?. qdrantCollectionConfiguration
89
100
const embeddings = nodeData . inputs ?. embeddings as Embeddings
90
101
const output = nodeData . outputs ?. output as string
91
102
const topK = nodeData . inputs ?. topK as string
103
+ let queryFilter = nodeData . inputs ?. queryFilter
104
+
92
105
const k = topK ? parseFloat ( topK ) : 4
93
106
94
107
const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
@@ -104,16 +117,26 @@ class Qdrant_Existing_VectorStores implements INode {
104
117
collectionName
105
118
}
106
119
107
- if ( qdrantCollectionCofiguration ) {
108
- qdrantCollectionCofiguration =
109
- typeof qdrantCollectionCofiguration === 'object' ? qdrantCollectionCofiguration : JSON . parse ( qdrantCollectionCofiguration )
110
- dbConfig . collectionConfig = qdrantCollectionCofiguration
120
+ const retrieverConfig : RetrieverConfig = {
121
+ k
122
+ }
123
+
124
+ if ( qdrantCollectionConfiguration ) {
125
+ qdrantCollectionConfiguration =
126
+ typeof qdrantCollectionConfiguration === 'object'
127
+ ? qdrantCollectionConfiguration
128
+ : JSON . parse ( qdrantCollectionConfiguration )
129
+ dbConfig . collectionConfig = qdrantCollectionConfiguration
130
+ }
131
+
132
+ if ( queryFilter ) {
133
+ retrieverConfig . filter = typeof queryFilter === 'object' ? queryFilter : JSON . parse ( queryFilter )
111
134
}
112
135
113
136
const vectorStore = await QdrantVectorStore . fromExistingCollection ( embeddings , dbConfig )
114
137
115
138
if ( output === 'retriever' ) {
116
- const retriever = vectorStore . asRetriever ( k )
139
+ const retriever = vectorStore . asRetriever ( retrieverConfig )
117
140
return retriever
118
141
} else if ( output === 'vectorStore' ) {
119
142
; ( vectorStore as any ) . k = k
0 commit comments