Skip to content

Weaviate - expose Hybrid Search #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/components/nodes/vectorstores/VectorStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ export const resolveVectorStoreOrRetriever = (
const searchType = nodeData.outputs?.searchType as string
const topK = nodeData.inputs?.topK as string
const k = topK ? parseFloat(topK) : 4
const alpha = nodeData.inputs?.alpha

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

if (output === 'retriever') {
const searchKwargs: Record<string, any> = {}
if (alpha !== undefined) {
searchKwargs.alpha = parseFloat(alpha)
}
if ('mmr' === searchType) {
const fetchK = nodeData.inputs?.fetchK as string
const lambda = nodeData.inputs?.lambda as string
Expand All @@ -25,13 +30,18 @@ export const resolveVectorStoreOrRetriever = (
k: k,
filter,
searchKwargs: {
//...searchKwargs,
fetchK: f,
lambda: l
}
})
} else {
// "searchType" is "similarity"
return vectorStore.asRetriever(k, filter)
return vectorStore.asRetriever({
k: k,
filter: filter,
searchKwargs: Object.keys(searchKwargs).length > 0 ? searchKwargs : undefined
})
}
} else if (output === 'vectorStore') {
;(vectorStore as any).k = k
Expand Down
12 changes: 11 additions & 1 deletion packages/components/nodes/vectorstores/Weaviate/Weaviate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Weaviate_VectorStores implements INode {
constructor() {
this.label = 'Weaviate'
this.name = 'weaviate'
this.version = 3.0
this.version = 4.0
this.type = 'Weaviate'
this.icon = 'weaviate.png'
this.category = 'Vector Stores'
Expand Down Expand Up @@ -124,6 +124,16 @@ class Weaviate_VectorStores implements INode {
}
]
addMMRInputParams(this.inputs)
this.inputs.push({
label: 'Alpha (for Hybrid Search)',
name: 'alpha',
description:
'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.',
placeholder: '1',
type: 'number',
additionalParams: true,
optional: true
})
this.outputs = [
{
label: 'Weaviate Retriever',
Expand Down