feat: filter qdrant existing
This commit is contained in:
parent
0a5d453338
commit
0bf298e890
|
|
@ -3,6 +3,9 @@ import { QdrantClient } from '@qdrant/js-client-rest'
|
|||
import { QdrantVectorStore, QdrantLibArgs } from 'langchain/vectorstores/qdrant'
|
||||
import { Embeddings } from 'langchain/embeddings/base'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { VectorStoreRetrieverInput } from 'langchain/vectorstores/base'
|
||||
|
||||
type RetrieverConfig = Partial<VectorStoreRetrieverInput<QdrantVectorStore>>
|
||||
|
||||
class Qdrant_Existing_VectorStores implements INode {
|
||||
label: string
|
||||
|
|
@ -53,7 +56,7 @@ class Qdrant_Existing_VectorStores implements INode {
|
|||
},
|
||||
{
|
||||
label: 'Qdrant Collection Cofiguration',
|
||||
name: 'qdrantCollectionCofiguration',
|
||||
name: 'qdrantCollectionConfiguration',
|
||||
type: 'json',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
|
|
@ -66,6 +69,14 @@ class Qdrant_Existing_VectorStores implements INode {
|
|||
type: 'number',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Qdrant Search Filter',
|
||||
name: 'qdrantFilter',
|
||||
description: 'Only return points which satisfy the conditions',
|
||||
type: 'json',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
this.outputs = [
|
||||
|
|
@ -85,10 +96,12 @@ class Qdrant_Existing_VectorStores implements INode {
|
|||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const qdrantServerUrl = nodeData.inputs?.qdrantServerUrl as string
|
||||
const collectionName = nodeData.inputs?.qdrantCollection as string
|
||||
let qdrantCollectionCofiguration = nodeData.inputs?.qdrantCollectionCofiguration
|
||||
let qdrantCollectionConfiguration = nodeData.inputs?.qdrantCollectionConfiguration
|
||||
const embeddings = nodeData.inputs?.embeddings as Embeddings
|
||||
const output = nodeData.outputs?.output as string
|
||||
const topK = nodeData.inputs?.topK as string
|
||||
let queryFilter = nodeData.inputs?.queryFilter
|
||||
|
||||
const k = topK ? parseFloat(topK) : 4
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
|
|
@ -104,16 +117,26 @@ class Qdrant_Existing_VectorStores implements INode {
|
|||
collectionName
|
||||
}
|
||||
|
||||
if (qdrantCollectionCofiguration) {
|
||||
qdrantCollectionCofiguration =
|
||||
typeof qdrantCollectionCofiguration === 'object' ? qdrantCollectionCofiguration : JSON.parse(qdrantCollectionCofiguration)
|
||||
dbConfig.collectionConfig = qdrantCollectionCofiguration
|
||||
const retrieverConfig: RetrieverConfig = {
|
||||
k
|
||||
}
|
||||
|
||||
if (qdrantCollectionConfiguration) {
|
||||
qdrantCollectionConfiguration =
|
||||
typeof qdrantCollectionConfiguration === 'object'
|
||||
? qdrantCollectionConfiguration
|
||||
: JSON.parse(qdrantCollectionConfiguration)
|
||||
dbConfig.collectionConfig = qdrantCollectionConfiguration
|
||||
}
|
||||
|
||||
if (queryFilter) {
|
||||
retrieverConfig.filter = typeof queryFilter === 'object' ? queryFilter : JSON.parse(queryFilter)
|
||||
}
|
||||
|
||||
const vectorStore = await QdrantVectorStore.fromExistingCollection(embeddings, dbConfig)
|
||||
|
||||
if (output === 'retriever') {
|
||||
const retriever = vectorStore.asRetriever(k)
|
||||
const retriever = vectorStore.asRetriever(retrieverConfig)
|
||||
return retriever
|
||||
} else if (output === 'vectorStore') {
|
||||
;(vectorStore as any).k = k
|
||||
|
|
|
|||
Loading…
Reference in New Issue