MMR Search for Pinecone, Weaviate, Zep and Supabase

This commit is contained in:
vinodkiran
2023-12-22 12:08:48 +05:30
parent 579f66e57e
commit 56b043264a
5 changed files with 98 additions and 109 deletions
@@ -5,6 +5,7 @@ import { Embeddings } from 'langchain/embeddings/base'
import { Document } from 'langchain/document'
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { addMMRInputParams, resolveVectorStoreOrRetriever } from '../VectorStoreUtils'
class Zep_VectorStores implements INode {
label: string
@@ -23,12 +24,12 @@ class Zep_VectorStores implements INode {
constructor() {
this.label = 'Zep'
this.name = 'zep'
this.version = 1.0
this.version = 2.0
this.type = 'Zep'
this.icon = 'zep.svg'
this.category = 'Vector Stores'
this.description =
'Upsert embedded data and perform similarity search upon query using Zep, a fast and scalable building block for LLM apps'
'Upsert embedded data and perform similarity or mmr search upon query using Zep, a fast and scalable building block for LLM apps'
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
this.badge = 'NEW'
this.credential = {
@@ -88,6 +89,7 @@ class Zep_VectorStores implements INode {
optional: true
}
]
addMMRInputParams(this.inputs)
this.outputs = [
{
label: 'Zep Retriever',
@@ -144,9 +146,6 @@ class Zep_VectorStores implements INode {
const zepMetadataFilter = nodeData.inputs?.zepMetadataFilter
const dimension = nodeData.inputs?.dimension as number
const embeddings = nodeData.inputs?.embeddings as Embeddings
const output = nodeData.outputs?.output as string
const topK = nodeData.inputs?.topK as string
const k = topK ? parseFloat(topK) : 4
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const apiKey = getCredentialParam('apiKey', credentialData, nodeData)
@@ -165,14 +164,7 @@ class Zep_VectorStores implements INode {
const vectorStore = await ZepExistingVS.fromExistingIndex(embeddings, zepConfig)
if (output === 'retriever') {
const retriever = vectorStore.asRetriever(k)
return retriever
} else if (output === 'vectorStore') {
;(vectorStore as any).k = k
return vectorStore
}
return vectorStore
return resolveVectorStoreOrRetriever(nodeData, vectorStore)
}
}
@@ -210,7 +202,7 @@ class ZepExistingVS extends ZepVectorStore {
this.args = args
}
async initalizeCollection(args: IZepConfig & Partial<ZepFilter>) {
async initializeCollection(args: IZepConfig & Partial<ZepFilter>) {
this.client = await ZepClient.init(args.apiUrl, args.apiKey)
try {
this.collection = await this.client.document.getCollection(args.collectionName)
@@ -259,7 +251,7 @@ class ZepExistingVS extends ZepVectorStore {
const newfilter = {
where: { and: ANDFilters }
}
await this.initalizeCollection(this.args!).catch((err) => {
await this.initializeCollection(this.args!).catch((err) => {
console.error('Error initializing collection:', err)
throw err
})