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 { QdrantVectorStore, QdrantLibArgs } from 'langchain/vectorstores/qdrant'
|
||||||
import { Embeddings } from 'langchain/embeddings/base'
|
import { Embeddings } from 'langchain/embeddings/base'
|
||||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
import { VectorStoreRetrieverInput } from 'langchain/vectorstores/base'
|
||||||
|
|
||||||
|
type RetrieverConfig = Partial<VectorStoreRetrieverInput<QdrantVectorStore>>
|
||||||
|
|
||||||
class Qdrant_Existing_VectorStores implements INode {
|
class Qdrant_Existing_VectorStores implements INode {
|
||||||
label: string
|
label: string
|
||||||
|
|
@ -53,7 +56,7 @@ class Qdrant_Existing_VectorStores implements INode {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Qdrant Collection Cofiguration',
|
label: 'Qdrant Collection Cofiguration',
|
||||||
name: 'qdrantCollectionCofiguration',
|
name: 'qdrantCollectionConfiguration',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
optional: true,
|
optional: true,
|
||||||
additionalParams: true
|
additionalParams: true
|
||||||
|
|
@ -66,6 +69,14 @@ class Qdrant_Existing_VectorStores implements INode {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
additionalParams: true,
|
additionalParams: true,
|
||||||
optional: 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 = [
|
this.outputs = [
|
||||||
|
|
@ -85,10 +96,12 @@ class Qdrant_Existing_VectorStores implements INode {
|
||||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
const qdrantServerUrl = nodeData.inputs?.qdrantServerUrl as string
|
const qdrantServerUrl = nodeData.inputs?.qdrantServerUrl as string
|
||||||
const collectionName = nodeData.inputs?.qdrantCollection 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 embeddings = nodeData.inputs?.embeddings as Embeddings
|
||||||
const output = nodeData.outputs?.output as string
|
const output = nodeData.outputs?.output as string
|
||||||
const topK = nodeData.inputs?.topK as string
|
const topK = nodeData.inputs?.topK as string
|
||||||
|
let queryFilter = nodeData.inputs?.queryFilter
|
||||||
|
|
||||||
const k = topK ? parseFloat(topK) : 4
|
const k = topK ? parseFloat(topK) : 4
|
||||||
|
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
|
@ -104,16 +117,26 @@ class Qdrant_Existing_VectorStores implements INode {
|
||||||
collectionName
|
collectionName
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qdrantCollectionCofiguration) {
|
const retrieverConfig: RetrieverConfig = {
|
||||||
qdrantCollectionCofiguration =
|
k
|
||||||
typeof qdrantCollectionCofiguration === 'object' ? qdrantCollectionCofiguration : JSON.parse(qdrantCollectionCofiguration)
|
}
|
||||||
dbConfig.collectionConfig = qdrantCollectionCofiguration
|
|
||||||
|
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)
|
const vectorStore = await QdrantVectorStore.fromExistingCollection(embeddings, dbConfig)
|
||||||
|
|
||||||
if (output === 'retriever') {
|
if (output === 'retriever') {
|
||||||
const retriever = vectorStore.asRetriever(k)
|
const retriever = vectorStore.asRetriever(retrieverConfig)
|
||||||
return retriever
|
return retriever
|
||||||
} else if (output === 'vectorStore') {
|
} else if (output === 'vectorStore') {
|
||||||
;(vectorStore as any).k = k
|
;(vectorStore as any).k = k
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue