# Pre\_process\_function not working

**URL:** <https://forum.opensearch.org/t/pre-process-function-not-working/24554>\
**Category:** Machine Learning\
**Created:** [May 27, 2025, 8:55pm UTC](https://forum.opensearch.org/t/pre-process-function-not-working/24554 "2025-05-27T20:55:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaun.monera](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@shaun.monera](https://forum.opensearch.org/u/shaun.monera)\
**Post date:** [May 27, 2025, 8:55pm UTC](https://forum.opensearch.org/t/pre-process-function-not-working/24554/1 "2025-05-27T20:55:10Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser): 2.19  
0

**Describe the issue** : I’m trying to create a custom pre\_process\_function for a self hosted vllm based cross-encoder. I followed the exampled provided by the documentation but it doesn’t look like the pre\_process\_function is being called. I tried to put an invalid syntax in the painless script but opensearch didn’t flag it. When i put the same invalid code in the post\_process\_function, opensearch flagged it.

**Configuration** :

**Relevant Logs or Screenshots** : Here’s the connector definition:  
{  
“name”: “connector-multifield”,  
“version”: “1”,  
“description”: “Connector to externally hosted cross-encoder model”,  
“protocol”: “http”,  
“parameters”: {  
“endpoint”: “vllm-rerank:7777”,  
“model”: “/models/custom-rerank-model”  
},  
“actions”: [  
{  
“action\_type”: “PREDICT”,  
“method”: “POST”,  
“url”: “http://${parameters.endpoint}/v2/rerank”,  
“headers”: {  
“content-type”: “application/json”  
},  
“request\_body”: “”“{  
“model”:”${parameters.model}“,  
“truncate\_prompt\_tokens”:1,  
“priority”:0,  
“query”:”${parameters.query}“,  
“documents”: ${parameters.chunks}  
}  
“””,  
“pre\_process\_function”: “”"  
def chunks = new ArrayList();  
if( params.topic\_chunks != null){  
chunks.addAll(params.topic\_chunks);  
}  
if( params.discussion\_chunks != null){  
chunks.addAll(discussion\_chunks);  
}  
if( params.recommendation\_chunks != null ){  
chunks.addAll(recommendation\_chunks);  
}  
return ‘{“parameters”:{“chunks”:’+ chunks +‘}}’;  
“”“,  
“post\_process\_function”: “””  
double maxScore = Double.NEGATIVE\_INFINITY;

```
    if (params.containsKey('results') && params.results != null){
      for (def item : params.results) {
        double s = ((Number)item.relevance_score).doubleValue();
        if (s > maxScore) {
          maxScore = s;
        }
      }
    }
    
    if (maxScore == Double.NEGATIVE_INFINITY) {
      maxScore = 0.0;
    }
    return ""+ maxScore + "";
  """
}

```

]  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [July 26, 2025, 8:55pm UTC](https://forum.opensearch.org/t/pre-process-function-not-working/24554/2 "2025-07-26T20:55:19Z")

</div>

Closed on July 26, 2025, 8:55pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
