mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 03:01:10 +03:00
Addition of Pinecone MMR search
This commit is contained in:
@@ -23,11 +23,11 @@ class Pinecone_VectorStores implements INode {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'Pinecone'
|
this.label = 'Pinecone'
|
||||||
this.name = 'pinecone'
|
this.name = 'pinecone'
|
||||||
this.version = 1.0
|
this.version = 2.0
|
||||||
this.type = 'Pinecone'
|
this.type = 'Pinecone'
|
||||||
this.icon = 'pinecone.svg'
|
this.icon = 'pinecone.svg'
|
||||||
this.category = 'Vector Stores'
|
this.category = 'Vector Stores'
|
||||||
this.description = `Upsert embedded data and perform similarity search upon query using Pinecone, a leading fully managed hosted vector database`
|
this.description = `Upsert embedded data and perform search upon query using Pinecone, a leading fully managed hosted vector database`
|
||||||
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
|
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
|
||||||
this.badge = 'NEW'
|
this.badge = 'NEW'
|
||||||
this.credential = {
|
this.credential = {
|
||||||
@@ -77,6 +77,43 @@ class Pinecone_VectorStores implements INode {
|
|||||||
type: 'number',
|
type: 'number',
|
||||||
additionalParams: true,
|
additionalParams: true,
|
||||||
optional: true
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Search Type',
|
||||||
|
name: 'searchType',
|
||||||
|
type: 'options',
|
||||||
|
default: 'similarity',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Similarity',
|
||||||
|
name: 'similarity'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Max Marginal Relevance',
|
||||||
|
name: 'mmr'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Fetch K (for MMR Search)',
|
||||||
|
name: 'fetchK',
|
||||||
|
description: 'Number of initial documents to fetch for MMR reranking. Default to 20. Used only when the search type is MMR',
|
||||||
|
placeholder: '20',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Lambda (for MMR Search)',
|
||||||
|
name: 'lambda',
|
||||||
|
description:
|
||||||
|
'Number between 0 and 1 that determines the degree of diversity among the results, where 0 corresponds to maximum diversity and 1 to minimum diversity. Used only when the search type is MMR',
|
||||||
|
placeholder: '0.5',
|
||||||
|
type: 'number',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
this.outputs = [
|
this.outputs = [
|
||||||
@@ -141,6 +178,7 @@ class Pinecone_VectorStores implements INode {
|
|||||||
const docs = nodeData.inputs?.document as Document[]
|
const docs = nodeData.inputs?.document as Document[]
|
||||||
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 searchType = nodeData.outputs?.searchType as string
|
||||||
const topK = nodeData.inputs?.topK as string
|
const topK = nodeData.inputs?.topK as string
|
||||||
const k = topK ? parseFloat(topK) : 4
|
const k = topK ? parseFloat(topK) : 4
|
||||||
|
|
||||||
@@ -176,8 +214,25 @@ class Pinecone_VectorStores implements INode {
|
|||||||
const vectorStore = await PineconeStore.fromExistingIndex(embeddings, obj)
|
const vectorStore = await PineconeStore.fromExistingIndex(embeddings, obj)
|
||||||
|
|
||||||
if (output === 'retriever') {
|
if (output === 'retriever') {
|
||||||
const retriever = vectorStore.asRetriever(k)
|
if ('mmr' === searchType) {
|
||||||
return retriever
|
const fetchK = nodeData.inputs?.fetchK as string
|
||||||
|
const lambda = nodeData.inputs?.lambda as string
|
||||||
|
const f = fetchK ? parseInt(fetchK) : 20
|
||||||
|
const l = lambda ? parseFloat(lambda) : 0.5
|
||||||
|
const retriever = vectorStore.asRetriever({
|
||||||
|
searchType: 'mmr',
|
||||||
|
k: 5,
|
||||||
|
searchKwargs: {
|
||||||
|
fetchK: f,
|
||||||
|
lambda: l
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return retriever
|
||||||
|
} else {
|
||||||
|
// "searchType" is "similarity"
|
||||||
|
const retriever = vectorStore.asRetriever(k)
|
||||||
|
return retriever
|
||||||
|
}
|
||||||
} else if (output === 'vectorStore') {
|
} else if (output === 'vectorStore') {
|
||||||
;(vectorStore as any).k = k
|
;(vectorStore as any).k = k
|
||||||
return vectorStore
|
return vectorStore
|
||||||
|
|||||||
Reference in New Issue
Block a user