본문 바로가기
WIKI 기술 지식 베이스

ML inference search response processor

원문 보기 위키 갱신

출처: 문서

본문

ML 추론 검색 응답 프로세서

2.16에서 도입됨 {: .label .label-purple }

ml_inference 검색 응답 프로세서는 등록된 머신러닝(ML) 모델을 호출하여 검색 결과 내 문서에 새로운 필드로 출력을 통합하는 데 사용돼요.

전제 조건
ml_inference 검색 응답 프로세서를 사용하기 전에 OpenSearch 클러스터에 호스팅된 로컬 ML 모델이나 ML Commons 플러그인을 통해 OpenSearch 클러스터에 연결된 외부 호스팅 모델이 있어야 해요. 로컬 모델에 대한 자세한 내용은 OpenSearch 내에서 ML 모델 사용하기를 참조하세요. 외부 호스팅 모델에 대한 자세한 내용은 외부 호스팅 모델에 연결하기를 참조하세요. {: .note}

구문

다음은 ml-inference 검색 응답 프로세서의 구문이에요.

{
  "ml_inference": {
    "model_id": "<model_id>",
    "function_name": "<function_name>",
    "full_response_path": "<full_response_path>",
    "model_config":{
      "<model_config_field>": "<config_value>"
    },
    "model_input": "<model_input>",
    "input_map": [
      {
        "<model_input_field>": "<document_field>"
      }
    ],
    "output_map": [
      {
        "<new_document_field>": "<model_output_field>"
      }
    ],
    "override": "<override>",
    "one_to_one": false
  }
}

{% include copy-curl.html %}

요청 본문 필드

다음 표는 ml-inference 검색 응답 프로세서의 필수 및 선택적 매개변수를 나열해요.

매개변수 데이터 타입 필수/선택 설명
model_id String 필수 프로세서에서 사용하는 ML 모델의 ID예요.
function_name String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
프로세서에 구성된 ML 모델의 함수 이름이에요. 로컬 모델의 경우 유효한 값은 sparse_encoding, sparse_tokenize, text_embedding, text_similarity예요. 외부 호스팅 모델의 경우 유효한 값은 remote예요. 기본값은 remote예요.
model_config Object 선택 ML 모델에 대한 사용자 정의 구성 옵션이에요. 외부 호스팅 모델의 경우 설정하면 이 구성이 기본 커넥터 매개변수를 재정의해요. 로컬 모델의 경우 model_config를 model_input에 추가하여 등록 중에 설정된 모델 구성을 재정의할 수 있어요. 자세한 내용은 model_config 객체를 참조하세요.
model_input String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
모델이 예상하는 입력 필드 형식을 정의하는 템플릿이에요. 각 로컬 모델 유형은 다른 입력 세트를 사용할 수 있어요. 외부 호스팅 모델의 경우 기본값은 "{ \"parameters\": ${ml_inference.parameters} }예요.
input_map Array 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
검색 응답의 문서 필드를 모델 입력 필드에 매핑하는 방법을 지정하는 배열이에요. 배열의 각 요소는 "<model_input_field>": "<document_field>" 형식의 맵이며 문서 필드의 한 모델 호출에 해당해요. 외부 호스팅 모델에 대해 입력 매핑이 지정되지 않으면 모든 문서 필드가 입력으로 모델에 직접 전달돼요. input_map 크기는 모델이 호출되는 횟수(Predict API 요청 수)를 나타내요.
<model_input_field> String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
모델 입력 필드 이름이에요.
<document_field> String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
모델 입력으로 사용되는 검색 응답의 문서 필드 이름 또는 JSON 경로예요.
output_map Array 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
모델 출력 필드를 검색 응답 문서의 새 필드에 매핑하는 방법을 지정하는 배열이에요. 배열의 각 요소는 "<new_document_field>": "<model_output_field>" 형식의 맵이에요.
<new_document_field> String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
모델의 출력(model_output으로 지정)이 저장되는 문서의 새 필드 이름이에요. 외부 호스팅 모델에 대해 출력 매핑이 지정되지 않으면 모델 출력의 모든 필드가 새 문서 필드에 추가돼요.
<model_output_field> String 외부 호스팅 모델의 경우 선택

로컬 모델의 경우 필수
new_document_field에 저장될 모델 출력의 필드 이름 또는 JSON 경로예요.
full_response_path Boolean 선택 model_output_field에 필드 이름 대신 필드의 전체 JSON 경로가 포함된 경우 이 매개변수를 true로 설정하세요. 그러면 모델 출력이 완전히 구문 분석되어 필드 값을 가져와요. 기본값은 로컬 모델의 경우 true이고 외부 호스팅 모델의 경우 false예요.
ignore_missing Boolean 선택 true이고 input_map 또는 output_map에 정의된 입력 필드 중 하나라도 누락된 경우 이 프로세서는 무시돼요. 그렇지 않으면 누락된 필드로 인해 실패해요. 기본값은 false예요.
ignore_failure Boolean 선택 프로세서가 오류가 발생해도 계속 실행할지 여부를 지정해요. true이면 이 프로세서가 무시되고 검색이 계속돼요. false이면 실패 시 검색이 취소돼요. 기본값은 false예요.
override Boolean 선택 응답의 문서에 <new_document_field>에 지정된 이름의 필드가 이미 있는 경우 관련돼요. override가 false이면 입력 필드가 건너뛰어져요. true이면 기존 필드 값이 새 모델 출력으로 재정의돼요. 기본값은 false예요.
max_prediction_tasks Integer 선택 문서 검색 중에 실행될 수 있는 최대 동시 모델 호출 수예요. 기본값은 10이에요.
one_to_one Boolean 선택 각 문서에 대해 모델을 한 번 호출(Predict API 요청 한 번)하려면 이 매개변수를 true로 설정하세요. 기본값(false)은 검색 응답의 모든 문서로 모델을 호출하여 Predict API 요청을 한 번 만드는 것을 지정해요.
description String 선택 프로세서에 대한 간단한 설명이에요.
tag String 선택 프로세서의 식별 태그예요. 동일한 유형의 프로세서를 구분하는 디버깅에 유용해요.

input_map 및 output_map 매핑은 복잡한 데이터 구조를 지정하기 위해 표준 JSON path 표기법을 지원해요. {: .note}

설정

my_index라는 인덱스를 생성하고 매핑을 설명하기 위해 하나의 문서를 인덱싱하세요.

POST /my_index/_doc/1
{
  "passage_text": "hello world"
}

{% include copy-curl.html %}

프로세서 사용하기

프로세서를 파이프라인에서 사용하려면 다음 단계를 따라 해요. 프로세서를 만들 때 모델 ID를 제공해야 해요. 프로세서를 사용하는 파이프라인을 테스트하기 전에 모델이 성공적으로 배포되었는지 확인하세요. Get Model API를 사용하여 모델 상태를 확인할 수 있어요.

로컬 모델의 경우 모델 입력 형식을 지정하는 model_input 필드를 제공해야 해요. model_config의 모든 입력 필드를 model_input에 추가하세요.

원격 모델의 경우 model_input 필드는 선택 사항이며 기본값은 "{ \"parameters\": ${ml_inference.parameters} }예요.

예: 로컬 모델

다음 예는 로컬 모델로 ml_inference 검색 응답 프로세서를 구성하는 방법을 보여줘요.

1단계: 파이프라인 만들기

다음 예는 huggingface/sentence-transformers/all-distilroberta-v1 로컬 모델용 검색 파이프라인을 만드는 방법을 보여줘요. 이 모델은 OpenSearch 클러스터에 호스팅된 사전 학습된 문장 변환 모델이에요.

Predict API를 사용하여 모델을 호출하면 요청은 다음과 같이 나타나요:

POST /_plugins/_ml/_predict/text_embedding/cleMb4kBJ1eYAeTMFFg4
{
  "text_docs":[ "today is sunny"],
  "return_number": true,
  "target_response": ["sentence_embedding"]
}

이 스키마를 사용하여 model_input을 다음과 같이 지정하세요:

 "model_input": "{ \"text_docs\": ${input_map.text_docs}, \"return_number\": ${model_config.return_number}, \"target_response\": ${model_config.target_response} }"

input_map에서 문서 필드 passage_text를 모델이 기대하는 text_docs 필드에 매핑하세요:

"input_map": [
  {
    "text_docs": "passage_text"
  }
]

임베딩으로 변환할 필드를 JSON 경로로 지정했기 때문에 full_response_path를 true로 설정해야 해요. 그러면 입력 필드를 얻기 위해 전체 JSON 문서가 파싱돼요:

"full_response_path": true

passage_text 필드의 텍스트가 임베딩을 생성하는 데 사용돼요:

{
  "passage_text": "hello world"
}

Predict API 요청은 다음 응답을 반환해요:

{
  "inference_results" : [
    {
      "output" : [
        {
          "name" : "sentence_embedding",
          "data_type" : "FLOAT32",
          "shape" : [
            768
          ],
          "data" : [
            0.25517133,
            -0.28009856,
            0.48519906,
            ...
          ]
        }
      ]
    }
  ]
}

모델은 $.inference_results.*.output.*.data 필드에 임베딩을 생성해요. output_map은 이 필드를 검색 응답 문서의 새로 생성된 passage_embedding 필드에 매핑해요:

"output_map": [
  {
    "passage_embedding": "$.inference_results.*.output.*.data"
  }
]

로컬 모델로 ml_inference 검색 응답 프로세서를 구성하려면 function_name을 명시적으로 지정하세요. 이 예에서 function_name은 text_embedding이에요. 유효한 function_name 값에 대한 자세한 내용은 요청 필드를 참조하세요.

다음은 로컬 모델을 사용한 ml_inference 검색 응답 프로세서의 최종 구성이에요:

PUT /_search/pipeline/ml_inference_pipeline_local
{
  "description": "search passage and generates embeddings",
  "response_processors": [
    {
      "ml_inference": {
        "function_name": "text_embedding",
        "full_response_path": true,
        "model_id": "<your model id>",
        "model_config": {
          "return_number": true,
          "target_response": ["sentence_embedding"]
        },
        "model_input": "{ \"text_docs\": ${input_map.text_docs}, \"return_number\": ${model_config.return_number}, \"target_response\": ${model_config.target_response} }",
        "input_map": [
          {
            "text_docs": "passage_text"
          }
        ],
        "output_map": [
          {
            "passage_embedding": "$.inference_results.*.output.*.data"
          }
        ],
        "ignore_missing": true,
        "ignore_failure": true
      }
    }
  ]
}

{% include copy-curl.html %}

2단계: 파이프라인 실행하기

요청에 파이프라인 이름을 제공하여 다음 쿼리를 실행하세요:

GET /my_index/_search?search_pipeline=ml_inference_pipeline_local
{
"query": {
  "term": {
    "passage_text": {
      "value": "hello"
      }
    }
  }
}

{% include copy-curl.html %}

응답

응답은 프로세서가 passage_embedding 필드에 텍스트 임베딩을 생성했음을 확인해요:

{
  "took": 288,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.00009405752,
    "hits": [
      {
        "_index": "my_index",
        "_id": "1",
        "_score": 0.00009405752,
        "_source": {
          "passage_text": "hello world",
          "passage_embedding": [
            0.017304314,
            -0.021530833,
            0.050184276,
            0.08962978,
            ...]
        }
      }
    ]
  }
}

예: 외부 호스팅 텍스트 임베딩 모델

다음 예는 외부 호스팅 모델로 ml_inference 검색 응답 프로세서를 구성하는 방법을 보여줘요.

1단계: 파이프라인 만들기

다음 예는 외부 호스팅 텍스트 임베딩 모델용 검색 파이프라인을 만드는 방법을 보여줘요. 이 모델은 input 필드가 필요하고 data 필드에 결과를 생성해요. passage_text 필드의 텍스트를 텍스트 임베딩으로 변환하고 임베딩을 passage_embedding 필드에 저장해요. 프로세서 구성에서 function_name이 명시적으로 지정되지 않았으므로 기본값은 remote이며, 이는 외부 호스팅 모델임을 나타내요:

PUT /_search/pipeline/ml_inference_pipeline
{
  "description": "Generate passage_embedding when search documents",
  "response_processors": [
    {
      "ml_inference": {
        "model_id": "<your model id>",
        "input_map": [
          {
            "input": "passage_text"
          }
        ],
        "output_map": [
          {
            "passage_embedding": "data"
          }
        ]
      }
    }
  ]
}

{% include copy-curl.html %}

외부 호스팅 모델에 Predict API 요청을 할 때 필요한 모든 필드와 매개변수는 일반적으로 parameters 객체 안에 포함돼요:

POST /_plugins/_ml/models/cleMb4kBJ1eYAeTMFFg4/_predict
{
  "parameters": {
    "input": [
      {
        ...
      }
    ]
  }
}

외부 호스팅 모델의 input_map을 지정할 때 점 경로 parameters.input 대신 input 필드를 직접 참조할 수 있어요:

"input_map": [
  {
    "input": "passage_text"
  }
]

2단계: 파이프라인 실행하기

요청에 파이프라인 이름을 제공하여 다음 쿼리를 실행하세요:

GET /my_index/_search?search_pipeline=ml_inference_pipeline_local
{
  "query": {
    "match_all": {
    }
  }
}

{% include copy-curl.html %}

응답은 프로세서가 passage_embedding 필드에 텍스트 임베딩을 생성했음을 확인해요. _source 내의 문서에는 이제 passage_text와 passage_embedding 필드가 모두 포함돼요:

{
  "took": 288,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.00009405752,
    "hits": [
      {
        "_index": "my_index",
        "_id": "1",
        "_score": 0.00009405752,
        "_source": {
          "passage_text": "hello world",
          "passage_embedding": [
            0.017304314,
            -0.021530833,
            0.050184276,
            0.08962978,
            ...]
        }
      }
      }
    ]
  }
}

예: 외부 호스팅 대규모 언어 모델

이 예는 외부 호스팅 대규모 언어 모델(LLM)과 함께 작동하도록 ml_inference 검색 응답 프로세서를 구성하고 모델의 응답을 검색 확장 객체에 매핑하는 방법을 보여줘요. ml_inference 프로세서를 사용하면 LLM이 응답 내에서 직접 검색 결과를 요약할 수 있어요. 요약은 검색 응답의 ext 필드에 포함되어 원래 검색 결과와 함께 AI 생성 인사이트에 원활하게 접근할 수 있게 해줘요.

전제 조건

이 사용 사례를 위해 외부 호스팅 LLM을 구성해야 해요. 외부 호스팅 모델에 대한 자세한 내용은 외부 호스팅 모델에 연결을 참조하세요. LLM을 등록한 후 다음 요청을 사용하여 테스트할 수 있어요. 이 요청은 prompt와 context 필드를 제공해야 해요:

POST /_plugins/_ml/models/KKne6JIBAs32TwoK-FFR/_predict
{
  "parameters": {
    "prompt":"\n\nHuman: You are a professional data analysist. You will always answer question: Which month had the lowest customer acquisition cost per new customer? 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 Assistant:",
    "context":"Customer acquisition cost: January: $50, February: $45, March: $40. New customers: January: 500, February: 600, March: 750"
  }
}

{% include copy-curl.html %}

응답에는 inference_results 필드에 모델 출력이 포함돼요:

{
  "inference_results": [
    {
      "output": [
        {
          "name": "response",
          "dataAsMap": {
            "response": """ Based on the data provided:

                        - Customer acquisition cost in January was $50 and new customers were 500. So cost per new customer was $50/500 = $0.10
                        - Customer acquisition cost in February was $45 and new customers were 600. So cost per new customer was $45/600 = $0.075
                        - Customer acquisition cost in March was $40 and new customers were 750. So cost per new customer was $40/750 = $0.053
            
                        Therefore, the month with the lowest customer acquisition cost per new customer was March, at $0.053."""
          }
        }
      ],
      "status_code": 200
    }
  ]
}

1단계: 파이프라인 만들기

등록된 모델에 대한 검색 파이프라인을 만드세요. 모델은 입력으로 context 필드가 필요해요. 모델 응답은 review 필드의 텍스트를 요약하고 요약을 검색 응답의 ext.ml_inference.llm_response 필드에 저장해요:

PUT /_search/pipeline/my_pipeline_request_review_llm
{
  "response_processors": [
    {
      "ml_inference": {
        "tag": "ml_inference",
        "description": "This processor is going to run llm",
        "model_id": "EOF6wJIBtDGAJRTD4kNg",
        "function_name": "REMOTE",
        "input_map": [
          {
            "context": "review"
          }
        ],
        "output_map": [
          {
            "ext.ml_inference.llm_response": "response"
          }
        ],
        "model_config": {
          "prompt": "\n\nHuman: You are a professional data analysist. You will always answer question: Which month had the lowest customer acquisition cost per new customer? 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 Assistant:"
        },
        "ignore_missing": false,
        "ignore_failure": false
      }
    }
  ]
}

{% include copy-curl.html %}

이 구성에서는 다음 매개변수를 제공했어요:

  • model_id 매개변수는 생성형 AI 모델의 ID를 지정해요.
  • function_name 매개변수는 REMOTE로 설정되어 모델이 외부 호스팅됨을 나타내요.
  • input_map 매개변수는 문서의 리뷰 필드를 모델이 기대하는 컨텍스트 필드에 매핑해요.
  • output_map 매개변수는 모델의 응답이 검색 응답의 ext.ml_inference.llm_response에 저장되어야 함을 지정해요.
  • model_config 매개변수에는 모델이 입력을 처리하고 요약을 생성하는 방법을 알려주는 프롬프트가 포함돼요.

2단계: 샘플 문서 인덱싱하기

파이프라인을 테스트하기 위해 샘플 문서를 인덱싱하세요:

POST /_bulk
{"index":{"_index":"review_string_index","_id":"1"}}
{"review":"Customer acquisition cost: January: $50, New customers: January: 500."}
{"index":{"_index":"review_string_index","_id":"2"}}
{"review":"Customer acquisition cost: February: $45, New customers: February: 600."}
{"index":{"_index":"review_string_index","_id":"3"}}
{"review":"Customer acquisition cost: March: $40, New customers: March: 750."}

{% include copy-curl.html %}

3단계: 파이프라인 실행하기

파이프라인을 사용하여 검색 쿼리를 실행하세요:

GET /review_string_index/_search?search_pipeline=my_pipeline_request_review_llm
{
  "query": {
    "match_all": {}
  }
}

{% include copy-curl.html %}

응답에는 원본 문서와 ext.ml_inference.llm_response 필드의 생성된 요약이 포함돼요:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "review_string_index",
        "_id": "1",
        "_score": 1,
        "_source": {
          "review": "Customer acquisition cost: January: $50, New customers: January: 500."
        }
      },
      {
        "_index": "review_string_index",
        "_id": "2",
        "_score": 1,
        "_source": {
          "review": "Customer acquisition cost: February: $45, New customers: February: 600."
        }
      },
      {
        "_index": "review_string_index",
        "_id": "3",
        "_score": 1,
        "_source": {
          "review": "Customer acquisition cost: March: $40, New customers: March: 750."
        }
      }
    ]
  },
  "ext": {
    "ml_inference": {
      "llm_response": """ Based on the context provided:

      - Customer acquisition cost in January was $50 and new customers were 500. So the cost per new customer was $50/500 = $0.10

      - Customer acquisition cost in February was $45 and new customers were 600. So the cost per new customer was $45/600 = $0.075

      - Customer acquisition cost in March was $40 and new customers were 750. So the cost per new customer was $40/750 = $0.053

      Therefore, the month with the lowest customer acquisition cost per new customer was March, as it had the lowest cost per customer of $0.053."""
    }
  }
}

예: 텍스트 유사도 모델을 사용한 검색 결과 재순위화

다음 예는 텍스트 유사도 모델로 ml_inference 검색 응답 프로세서를 구성하는 방법을 보여줘요.

전제 조건

이 사용 사례를 위해 외부 호스팅 텍스트 유사도 모델을 구성해야 해요. 외부 호스팅 모델에 대한 자세한 내용은 외부 호스팅 모델에 연결을 참조하세요. 텍스트 유사도 모델을 등록한 후 다음 요청을 사용하여 테스트할 수 있어요. 이 요청은 inputs 필드 내에 text와 text_pair 필드를 제공해야 해요:

POST /_plugins/_ml/models/Ialx65IBAs32TwoK1lXf/_predict
{
  "parameters": {
    "inputs":
    {
      "text": "I like you",
      "text_pair": "I hate you"
    }
  }
}

{% include copy-curl.html %}

모델은 각 입력 문서에 대한 유사도 점수를 반환해요:

{
  "inference_results": [
    {
      "output": [
        {
          "name": "response",
          "dataAsMap": {
            "label": "LABEL_0",
            "score": 0.022704314440488815
          }
        }
      ],
      "status_code": 200
    }
  ]
}

{% include copy-curl.html %}

1단계: 샘플 문서 인덱싱하기

인덱스를 만들고 샘플 문서를 추가하세요:

POST _bulk
{"index":{"_index":"demo-index-0","_id":"1"}}
{"diary":"I hate you"}
{"index":{"_index":"demo-index-0","_id":"2"}}
{"diary":"I love you"}
{"index":{"_index":"demo-index-0","_id":"3"}}
{"diary":"I dislike you"}

{% include copy-curl.html %}

2단계: 검색 파이프라인 만들기

이 예에서는 one-to-one 추론 모드에서 텍스트 유사도 모델을 사용하는 검색 파이프라인을 만들어 각 문서를 개별적으로 처리할 거예요. 이 설정을 통해 모델은 문서당 하나의 예측 요청을 하여 각 검색 결과에 대한 특정 관련성 인사이트를 제공할 수 있어요. input_map을 사용하여 검색 요청을 쿼리 텍스트에 매핑할 때 JSON 경로는 $._request 또는 _request로 시작해야 해요:

PUT /_search/pipeline/my_rerank_pipeline
{
  "response_processors": [
    {
      "ml_inference": {
        "tag": "ml_inference",
        "description": "This processor runs ml inference during search response",
        "model_id": "Ialx65IBAs32TwoK1lXf",
        "model_input":"""{"parameters":{"inputs":{"text":"${input_map.text}","text_pair":"${input_map.text_pair}"}}}""",
        "function_name": "REMOTE",
        "input_map": [
          {
            "text": "diary",
            "text_pair":"$._request.query.term.diary.value"
          }
        ],
        "output_map": [
          {
            "rank_score": "$.score"
          }
        ],
        "full_response_path": false,
        "model_config": {},
        "ignore_missing": false,
        "ignore_failure": false,
        "one_to_one": true
        },
        "rerank": {
          "by_field": {
            "target_field": "rank_score",
            "remove_target_field": true
          }
        }
    }
  ]
}

{% include copy-curl.html %}

이 구성에서는 다음 매개변수를 제공했어요:

  • model_id 매개변수는 텍스트 유사도 모델의 고유 식별자를 지정해요.
  • function_name 매개변수는 REMOTE로 설정되어 모델이 외부 호스팅됨을 나타내요.
  • input_map 매개변수는 각 문서의 diary 필드를 모델의 text 입력에 매핑하고 검색 쿼리 용어를 text_pair 입력에 매핑해요.
  • output_map 매개변수는 모델의 점수를 각 문서의 rank_score 필드에 매핑해요.
  • model_input 매개변수는 모델의 입력 형식을 지정하여 Predict API가 기대하는 구조와 일치하도록 해요.
  • one_to_one 매개변수는 true로 설정되어 모델이 여러 문서를 배치 처리하지 않고 각 문서를 개별적으로 처리하도록 해요.
  • ignore_missing 매개변수는 false로 설정되어 매핑된 필드가 문서에 없으면 프로세서가 실패하게 해요.
  • ignore_failure 매개변수는 false로 설정되어 ML 추론 프로세서에서 오류가 발생하면 전체 파이프라인이 실패하게 해요.

rerank 프로세서는 ML 추론 후에 적용돼요. ML 모델이 생성한 rank_score 필드를 기준으로 문서를 재정렬한 다음 최종 결과에서 이 필드를 제거해요.

3단계: 파이프라인 실행하기

이제 생성된 파이프라인을 사용하여 검색을 수행하세요:

GET /demo-index-0/_search?search_pipeline=my_rerank_pipeline
{
  "query": {
    "term": {
      "dairy": {
        "value": "today"
      }
    }
  }
}

{% include copy-curl.html %}

응답에는 원본 문서와 재순위화된 점수가 포함돼요:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 0.040183373,
    "hits": [
      {
        "_index": "demo-index-0",
        "_id": "1",
        "_score": 0.040183373,
        "_source": {
          "diary": "I hate you"
        }
      },
      {
        "_index": "demo-index-0",
        "_id": "2",
        "_score": 0.022628736,
        "_source": {
          "diary": "I love you"
        }
      },
      {
        "_index": "demo-index-0",
        "_id": "3",
        "_score": 0.0073115323,
        "_source": {
          "diary": "I dislike you"
        }
      }
    ]
  },
  "profile": {
    "shards": []
  }
}

다음 단계

  • 외부 호스팅 크로스 인코더 모델을 사용한 필드별 재순위화의 포괄적인 예를 참조하세요.

더 알아보기 (Learn more)