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

[RFC] ML Inference Search Request Extension #3286

Open
mingshl opened this issue Dec 17, 2024 · 0 comments
Open

[RFC] ML Inference Search Request Extension #3286

mingshl opened this issue Dec 17, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request v2.19.0 Issues targeting release v2.19.0

Comments

@mingshl
Copy link
Collaborator

mingshl commented Dec 17, 2024

Problem Statement:

Currently, when applying machine learning model predictions during search, users are limited in their ability to pass additional input fields that are not part of the search queries. This limitation hinders the flexibility and effectiveness of model predictions in certain scenarios.

Proposed Solution

Propose introducing an ml_inference search extension that can be used alongside any search query. This extension would allow users to pass a flexible, large object containing various model input formats, making it adaptable to different models.

Key Features

  • Flexible input format to accommodate various model requirements
  • Integration with existing search queries
  • Compatibility with search pipelines and request processors

Sample Usage

Basic usage with match queries and use the search content to feed to a claude model in prompt to answer questions:

{
  "query": { "match_all": {} },
  "ext": {
    "ml_inference": {
      "question": "what is opensearch"
    }
  },
  "search_pipeline": {
    "request_processors": [
      {
        "ml_inference": {
          "model_id": "<model_id>",
          "input_map": [
            {
              "inputs": "ext.ml_inference.question",
              "context": "text_docs"
            }
          ],
          "output_map": [
            {
              "ext.ml_inference.llm_response": "response"
            }
          ],
          "model_config": {
            "prompt": ""\n\nHuman: You are a professional data analysist. You will always answer question based on the given context first. If the answer is not directly shown in the context, you will analyze the data and find the answer. If you don't know the answer, just say I don't know. Context: ${parameters.context.toString()}. \n\n Human: please answer the question:${parameters.inputs} \n\n Assistant:""
          },
          "ignore_missing": false,
          "ignore_failure": false
        }
      }
    ]
  }
}

Combined with template query and search pipelines:

GET my-knn-index-1/_search
{
  "query": {
    "template": {
      "knn": {
        "my_vector": {
          "vector": "${ext.ml_inference.params.vector}",
          "k": 2
        }
      }
    }
  },
  "ext": {
    "ml_inference": {
      "params": {
        "text": "sunny"
      }
    }
  },
  "search_pipeline": {
    "request_processors": [
      {
        "ml_inference": {
          "model_id": "<model_id>",
          "input_map": [
            {
              "inputs": "ext.ml_inference.params.text"
            }
          ],
          "output_map": [
            {
              "ext.ml_inference.params.vector": "response"
            }
          ],
          "ignore_missing": false,
          "ignore_failure": false
        }
      }
    ]
  }
}

Related issue:
opensearch-project/OpenSearch#16823
#3054

@mingshl mingshl added enhancement New feature or request untriaged labels Dec 17, 2024
@mingshl mingshl added the v2.19.0 Issues targeting release v2.19.0 label Dec 17, 2024
@mingshl mingshl changed the title [FEATURE] ML Inference Search Request Extension [RFC] ML Inference Search Request Extension Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2.19.0 Issues targeting release v2.19.0
Projects
None yet
Development

No branches or pull requests

2 participants