Skip to content
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

Bug Fix: Correct Parameter Type for KnnSearch$Builder.k Method in ElasticsearchVectorStore.java #1915

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yezhoujie
Copy link

Bug Fix

Correct Parameter Type for KnnSearch$Builder.k Method in ElasticsearchVectorStore.java

Description

This PR addresses a bug in ElasticsearchVectorStore.java where an incorrect parameter type was passed to the KnnSearch$Builder.k method of the ElasticSearchClient during the execution of similaritySearch. The issue caused the following error:

Handler dispatch failed: java.lang.NoSuchMethodError: 'co.elastic.clients.elasticsearch._types.KnnSearch$Builder co.elastic.clients.elasticsearch._types.KnnSearch$Builder.k(java.lang.Long)'

Root Cause

The KnnSearch$Builder.k method in elasticsearch-rest-client:8.15.4 requires an Integer parameter, but the code passed a long value, leading to the NoSuchMethodError.

SearchResponse<Document> res = this.elasticsearchClient.search(
					sr -> sr.index(this.options.getIndexName())
						.knn(knn -> knn.queryVector(EmbeddingUtils.toList(vectors))
							.similarity(finalThreshold)
							.k((long) searchRequest.getTopK())
							.field("embedding")
							.numCandidates((long) (1.5 * searchRequest.getTopK()))
							.filter(fl -> fl.queryString(
									qs -> qs.query(getElasticsearchQueryString(searchRequest.getFilterExpression()))))),
					Document.class);

Fix

The fix involves changing the parameter type from long to Integer when calling the KnnSearch$Builder.k method.

Changes

Updated ElasticsearchVectorStore.java to pass an Integer parameter to the KnnSearch$Builder.k method.

…sticsearchVectorStore.java

Addresses a bug in ElasticsearchVectorStore.java where an incorrect parameter type was passed to the KnnSearch$Builder.k method of the ElasticSearchClient during the execution of similaritySearch. The issue caused the following error:

```
Handler dispatch failed: java.lang.NoSuchMethodError: 'co.elastic.clients.elasticsearch._types.KnnSearch$Builder co.elastic.clients.elasticsearch._types.KnnSearch$Builder.k(java.lang.Long)'
```

Root Cause
The KnnSearch$Builder.k method requires an Integer parameter, but the code passed a long value, leading to the NoSuchMethodError.

## Fix

The fix involves changing the parameter type from long to Integer when calling the KnnSearch$Builder.k method.
@markpollack markpollack added this to the 1.0.0-M5 milestone Dec 20, 2024
@sobychacko sobychacko modified the milestones: 1.0.0-M5, 1.0.0-M6 Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants