You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _query-dsl/specialized/script-score.md
+90Lines changed: 90 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -373,5 +373,95 @@ GET /demo_index_v1/_search
373
373
```
374
374
{% include copy-curl.html %}
375
375
376
+
### Late interaction score
377
+
378
+
The `lateInteractionScore` function is a Painless script scoring function that calculates document relevance using token-level vector matching. It compares each query vector against all document vectors, finds the maximum similarity for each query vector, and sums these maximum scores to produce the final document score.
- Query vector 1 → finds best match among document vectors → score A
384
+
- Query vector 2 → finds best match among document vectors → score B
385
+
- Final score = A + B
386
+
387
+
This approach enables fine-grained semantic matching between queries and documents, making it particularly effective for reranking search results.
388
+
389
+
#### Index mapping requirements
390
+
391
+
The vector field must be mapped as either an `object` (recommended) or `float` type.
392
+
393
+
We recommend mapping the vector field as an `object` with `"enabled": false` because it stores raw vectors without parsing, improving performance:
394
+
395
+
```json
396
+
{
397
+
"mappings": {
398
+
"properties": {
399
+
"my_vector": {
400
+
"type": "object",
401
+
"enabled": false
402
+
}
403
+
}
404
+
}
405
+
}
406
+
```
407
+
408
+
Alternatively, you can map the vector field as a `float`:
409
+
410
+
```json
411
+
{
412
+
"mappings": {
413
+
"properties": {
414
+
"my_vector": {
415
+
"type": "float"
416
+
}
417
+
}
418
+
}
419
+
}
420
+
```
421
+
422
+
#### Example
423
+
424
+
The following example demonstrates using the `lateInteractionScore` function with cosine similarity to measure vector similarity based on direction rather than distance:
For a complete example, see [Reranking by a field using an externally hosted late interaction model]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/rerank-by-field-late-interaction/).
465
+
376
466
If [`search.allow_expensive_queries`]({{site.url}}{{site.baseurl}}/query-dsl/index/#expensive-queries) is set to `false`, `script_score` queries are not executed.
0 commit comments