opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
120 stars 182 forks source link

Adding support for Radial Search in Neural Query #1226

Open manabendrapaul opened 5 days ago

manabendrapaul commented 5 days ago

What/Why

What are you proposing?

Adding support for Radial Search in Neural Query

What users have asked for this feature?

Users connecting to Opensearch using Java Client

What problems are you trying to solve?

Currently the Java SDK only takes 'k' as part of Neural Query, whereas from Opensearch 2.15, we can pass min_score / max_distance as part of neural query. But I dont see these options with Java Client.

What is the developer experience going to be?

Devlopers can directly use that feature instead of moving to GenericClient.

Are there any security considerations?

No

Are there any breaking changes to the API

No

What is the user experience going to be?

Developers can build queries with ease.

Are there breaking changes to the User Experience?

No Breaking changes

Why should it be built? Any reason not to?

To make it in sync with latest Radial search features in Opensearch 2.15 features.

What will it take to execute?

Some enhancements to NeuralSearch query builders.

Any remaining open questions?

No

dblock commented 4 days ago

I would start by checking whether this is supported in https://github.com/opensearch-project/opensearch-api-specification (might need changes, and a test). We are working on code generation from spec #366 so this will get covered this way.

manabendrapaul commented 2 days ago

Thanks for your reply.

But, Won't NeuralQuery also support this features? Currently, we can set the value of 'k' while forming a neural query.

e.g. For the below query:

"query": {
        "hybrid": {
          "queries": [
            {
              "match": {
                "distilled_content": {
                  "query": "what is the plants game"
                }
              }
            },
            {
              "neural": {
                "article_embedding": {
                  "query_text": "what is the plants game",
                  "model_id": "9KvnbZABfxmyMZwietnR",
                  "k": 5
                }
              }
            }
          ]
        }
      }

We can write using Java client like this:

Query.of(h -> h
                .hybrid(q -> q
                .queries(Arrays.asList(
                        new MatchQuery.Builder().field(DISTILLED_CONTENT).query(FieldValue.of(request.getQuery())).build().toQuery(),
                        new NeuralQuery.Builder().field(ARTICLE_EMBEDDING).queryText(request.getQuery()).modelId("9KvnbZABfxmyMZwietnR").k(5).build().toQuery()))));

But, if I try to use radial search options of min_score or max_distance, I cant find similar options with Java Client. e.g.

"query": {
    "neural": {
      "article_embedding": {
        "query_text": "plants vs. zombies",
        "model_id": "9KvnbZABfxmyMZwietnR",
        "min_score": "0.50"
      }
    }
  }