Skip to content

Commit 983f77d

Browse files
gururiseJJK801
authored andcommitted
Weaviate - expose Hybrid Search (FlowiseAI#4127)
Hybrid Search for Weaviate
1 parent 5a3eb65 commit 983f77d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/components/nodes/vectorstores/VectorStoreUtils.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ export const resolveVectorStoreOrRetriever = (
1010
const searchType = nodeData.outputs?.searchType as string
1111
const topK = nodeData.inputs?.topK as string
1212
const k = topK ? parseFloat(topK) : 4
13+
const alpha = nodeData.inputs?.alpha
1314

1415
// If it is already pre-defined in lc_kwargs, then don't pass it again
1516
const filter = vectorStore?.lc_kwargs?.filter ? undefined : metadataFilter
1617

1718
if (output === 'retriever') {
19+
const searchKwargs: Record<string, any> = {}
20+
if (alpha !== undefined) {
21+
searchKwargs.alpha = parseFloat(alpha)
22+
}
1823
if ('mmr' === searchType) {
1924
const fetchK = nodeData.inputs?.fetchK as string
2025
const lambda = nodeData.inputs?.lambda as string
@@ -25,13 +30,18 @@ export const resolveVectorStoreOrRetriever = (
2530
k: k,
2631
filter,
2732
searchKwargs: {
33+
//...searchKwargs,
2834
fetchK: f,
2935
lambda: l
3036
}
3137
})
3238
} else {
3339
// "searchType" is "similarity"
34-
return vectorStore.asRetriever(k, filter)
40+
return vectorStore.asRetriever({
41+
k: k,
42+
filter: filter,
43+
searchKwargs: Object.keys(searchKwargs).length > 0 ? searchKwargs : undefined
44+
})
3545
}
3646
} else if (output === 'vectorStore') {
3747
;(vectorStore as any).k = k

packages/components/nodes/vectorstores/Weaviate/Weaviate.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Weaviate_VectorStores implements INode {
2626
constructor() {
2727
this.label = 'Weaviate'
2828
this.name = 'weaviate'
29-
this.version = 3.0
29+
this.version = 4.0
3030
this.type = 'Weaviate'
3131
this.icon = 'weaviate.png'
3232
this.category = 'Vector Stores'
@@ -124,6 +124,16 @@ class Weaviate_VectorStores implements INode {
124124
}
125125
]
126126
addMMRInputParams(this.inputs)
127+
this.inputs.push({
128+
label: 'Alpha (for Hybrid Search)',
129+
name: 'alpha',
130+
description:
131+
'Number between 0 and 1 that determines the weighting of keyword (BM25) portion of the hybrid search. A value of 1 is a pure vector search, while 0 is a pure keyword search.',
132+
placeholder: '1',
133+
type: 'number',
134+
additionalParams: true,
135+
optional: true
136+
})
127137
this.outputs = [
128138
{
129139
label: 'Weaviate Retriever',

0 commit comments

Comments
 (0)