opensearch-project / opensearch-project/opensearch-java

[BUG] KNNQuery serialize precision error

Open
#883 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

What is the bug?

There is a knn query like

KnnQuery origin = new KnnQuery.Builder().field("field").vector(new float[] { 0.1f, 0.4f }).k(1).build();

When it serialize to json string, the result would be:

{"field":{"vector":[0.10000000149011612,0.4000000059604645],"k":1}}

like the test code shows:

https://github.com/opensearch-project/opensearch-java/blob/4436e89a0f48d54e47c2c33689e0b828cbb31149/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQueryTest.java#L16-L20

Do you have any additional context?

PR #882

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQueryTest.java at lines 16–20 and reproduce the serialized output shown in the issue. Trace the serialization path exercised by that test and resolve the reported float precision discrepancy, with the test demonstrating the corrected JSON; PR #882 provides additional context.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.