Skip to content

Commit

Permalink
fixup! Merge branch 'opensearch-project:main' into patch.tutorial-rer…
Browse files Browse the repository at this point in the history
…ank-bge-rerank-m3-v2

Signed-off-by: tkykenmt <[email protected]>
  • Loading branch information
tkykenmt committed Dec 15, 2024
1 parent 63aeae0 commit ad747f2
Showing 1 changed file with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,38 @@ result = predictor.predict(data={
]
})

print(json.dumps(sorted(result, key=lambda x: x['index']), indent=2))
print(json.dumps(result, indent=2))
```

The reranking results are as follows:
The reranking result is ordering by the highest score first:
```
[
{
"index": 2,
"score": 0.92879725
},
{
"index": 0,
"score": 0.013636836
},
{
"index": 1,
"score": 0.000593021
},
{
"index": 3,
"score": 0.00012148176
}
]
```

You can sort the result by index number.

```python
print(json.dumps(result, indent=2))
```

The results are as follows:

```
[
Expand Down Expand Up @@ -139,8 +167,8 @@ POST /_plugins/_ml/connectors/_create
""",
"request_body": "{ \"query\": \"${parameters.query}\", \"texts\": ${parameters.texts} }",
"post_process_function": """
if (params.result == null) {
return "no result generated";
if (params.result == null || params.result.length > 0) {
throw new IllegalArgumentException("Post process function input is empty.");
}
def outputs = params.result;
def scores = new Double[outputs.length];
Expand Down Expand Up @@ -207,8 +235,8 @@ POST /_plugins/_ml/connectors/_create
""",
"request_body": "{ \"query\": \"${parameters.query}\", \"texts\": ${parameters.texts} }",
"post_process_function": """
if (params.result == null) {
return "no result generated";
if (params.result == null || params.result.length > 0) {
throw new IllegalArgumentException("Post process function input is empty.");
}
def outputs = params.result;
def scores = new Double[outputs.length];
Expand Down Expand Up @@ -283,6 +311,10 @@ The connector `pre_process_function` transforms the input into the format requir
By default, the SageMaker model output has the following format:
```json
[
{
"index": 2,
"score": 0.92879725
},
{
"index": 0,
"score": 0.013636836
Expand All @@ -291,18 +323,14 @@ By default, the SageMaker model output has the following format:
"index": 1,
"score": 0.000593021
},
{
"index": 2,
"score": 0.92879725
},
{
"index": 3,
"score": 0.00012148176
}
]
```

The connector `post_process_function` transforms the model's output into a format that the [Reranker processor](https://opensearch.org/docs/latest/search-plugins/search-pipelines/rerank-processor/) can interpret. This adapted format is as follows:
The connector `post_process_function` transforms the model's output into a format that the [Reranker processor](https://opensearch.org/docs/latest/search-plugins/search-pipelines/rerank-processor/) can interpretm, and order result by index. This adapted format is as follows:
```json
{
"inference_results": [
Expand Down

0 comments on commit ad747f2

Please sign in to comment.