Skip to content

Commit 7e4ca40

Browse files
authored
ESQL: Fix docs for RERANK (#132534)
They were based on an older syntax and copied from a test so we didn't notice they were out of date. This links them into a test that we run on every build.
1 parent f0f6410 commit 7e4ca40

File tree

5 files changed

+131
-50
lines changed

5 files changed

+131
-50
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it.
2+
3+
```esql
4+
FROM books METADATA _score
5+
| WHERE MATCH(description, "hobbit") OR MATCH(author, "Tolkien")
6+
| SORT _score DESC
7+
| LIMIT 100
8+
| RERANK rerank_score = "hobbit" ON description, author WITH { "inference_id" : "test_reranker" }
9+
| EVAL original_score = _score, _score = rerank_score + original_score
10+
| SORT _score
11+
| LIMIT 3
12+
| KEEP title, original_score, rerank_score, _score
13+
```
14+
15+
| title:text | _score:double | rerank_score:double | rerank_score:double |
16+
| --- | --- | --- | --- |
17+
| Poems from the Hobbit | 4.012462615966797 | 0.001396648003719747 | 0.001396648003719747 |
18+
| The Lord of the Rings - Boxed Set | 3.768855094909668 | 0.0010020040208473802 | 0.001396648003719747 |
19+
| Return of the King Being the Third Part of The Lord of the Rings | 3.6248698234558105 | 9.000900317914784E-4 | 0.001396648003719747 |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it.
2+
3+
```esql
4+
FROM books METADATA _score
5+
| WHERE MATCH(description, "hobbit")
6+
| SORT _score DESC
7+
| LIMIT 100
8+
| RERANK "hobbit" ON description WITH { "inference_id" : "test_reranker" }
9+
| LIMIT 3
10+
| KEEP title, _score
11+
```
12+
13+
| title:text | _score:double |
14+
| --- | --- |
15+
| Poems from the Hobbit | 0.0015673980815336108 |
16+
| A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings | 0.007936508394777775 |
17+
| Return of the King Being the Third Part of The Lord of the Rings | 9.960159659385681E-4 |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it.
2+
3+
```esql
4+
FROM books METADATA _score
5+
| WHERE MATCH(description, "hobbit") OR MATCH(author, "Tolkien")
6+
| SORT _score DESC
7+
| LIMIT 100
8+
| RERANK rerank_score = "hobbit" ON description, author WITH { "inference_id" : "test_reranker" }
9+
| SORT rerank_score
10+
| LIMIT 3
11+
| KEEP title, _score, rerank_score
12+
```
13+
14+
| title:text | _score:double | rerank_score:double |
15+
| --- | --- | --- |
16+
| Return of the Shadow | 2.8181066513061523 | 5.740527994930744E-4 |
17+
| Return of the King Being the Third Part of The Lord of the Rings | 3.6248698234558105 | 9.000900317914784E-4 |
18+
| The Lays of Beleriand | 1.3002015352249146 | 9.36329597607255E-4 |

docs/reference/query-languages/esql/_snippets/commands/layout/rerank.md

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -100,61 +100,17 @@ If you don't want to increase the timeout limit, try the following:
100100

101101
Rerank search results using a simple query and a single field:
102102

103-
```esql
104-
FROM books
105-
| WHERE MATCH(title, "science fiction")
106-
| SORT _score DESC
107-
| LIMIT 100
108-
| RERANK "science fiction" ON (title) WITH { "inference_id" : "my_reranker" }
109-
| LIMIT 3
110-
| KEEP title, _score
111-
```
112103

113-
| title:keyword | _score:double |
114-
|---------------|---------------|
115-
| Neuromancer | 0.98 |
116-
| Dune | 0.95 |
117-
| Foundation | 0.92 |
104+
:::{include} ../examples/rerank.csv-spec/simple-query.md
105+
:::
118106

119107
Rerank search results using a query and multiple fields, and store the new score
120108
in a column named `rerank_score`:
121109

122-
```esql
123-
FROM movies
124-
| WHERE MATCH(title, "dystopian future") OR MATCH(synopsis, "dystopian future")
125-
| SORT _score DESC
126-
| LIMIT 100
127-
| RERANK rerank_score = "dystopian future" ON (title, synopsis) WITH { "inference_id" : "my_reranker" }
128-
| SORT rerank_score DESC
129-
| LIMIT 5
130-
| KEEP title, _score, rerank_score
131-
```
132-
133-
| title:keyword | _score:double | rerank_score:double |
134-
|-----------------|---------------|---------------------|
135-
| Blade Runner | 8.75 | 0.99 |
136-
| The Matrix | 9.12 | 0.97 |
137-
| Children of Men | 8.50 | 0.96 |
138-
| Akira | 8.99 | 0.94 |
139-
| Gattaca | 8.65 | 0.91 |
110+
:::{include} ../examples/rerank.csv-spec/two-queries.md
111+
:::
140112

141113
Combine the original score with the reranked score:
142114

143-
```esql
144-
FROM movies
145-
| WHERE MATCH(title, "dystopian future") OR MATCH(synopsis, "dystopian future")
146-
| SORT _score DESC
147-
| LIMIT 100
148-
| RERANK rerank_score = "dystopian future" ON (title, synopsis) WITH { "inference_id" : "my_reranker" }
149-
| EVAL original_score = _score, _score = rerank_score + original_score
150-
| SORT _score DESC
151-
| LIMIT 2
152-
| KEEP title, original_score, rerank_score, _score
153-
```
154-
155-
| title:keyword | original_score:double | rerank_score:double | _score:double |
156-
|---------------|-----------------------|---------------------|---------------|
157-
| The Matrix | 9.12 | 0.97 | 10.09 |
158-
| Akira | 8.99 | 0.94 | 9.93 |
159-
160-
115+
:::{include} ../examples/rerank.csv-spec/combine.md
116+
:::

x-pack/plugin/esql/qa/testFixtures/src/main/resources/rerank.csv-spec

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,74 @@ book_no:keyword | title:keyword | author:keyword
223223
5335 | Letters of J R R Tolkien | J.R.R. Tolkien | 0.04
224224
2130 | The J. R. R. Tolkien Audio Collection | [Christopher Tolkien, John Ronald Reuel Tolkien] | 0.03
225225
;
226+
227+
228+
simple
229+
required_capability: rerank
230+
231+
// tag::simple-query[]
232+
FROM books METADATA _score
233+
| WHERE MATCH(description, "hobbit")
234+
| SORT _score DESC
235+
| LIMIT 100
236+
| RERANK "hobbit" ON description WITH { "inference_id" : "test_reranker" }
237+
| LIMIT 3
238+
| KEEP title, _score
239+
// end::simple-query[]
240+
;
241+
242+
// tag::simple-query-result[]
243+
title:text | _score:double
244+
Poems from the Hobbit | 0.0015673980815336108
245+
A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings | 0.007936508394777775
246+
Return of the King Being the Third Part of The Lord of the Rings | 9.960159659385681E-4
247+
// end::simple-query-result[]
248+
;
249+
250+
two_queries
251+
required_capability: rerank
252+
253+
// tag::two-queries[]
254+
FROM books METADATA _score
255+
| WHERE MATCH(description, "hobbit") OR MATCH(author, "Tolkien")
256+
| SORT _score DESC
257+
| LIMIT 100
258+
| RERANK rerank_score = "hobbit" ON description, author WITH { "inference_id" : "test_reranker" }
259+
| SORT rerank_score
260+
| LIMIT 3
261+
| KEEP title, _score, rerank_score
262+
// end::two-queries[]
263+
;
264+
265+
// tag::two-queries-result[]
266+
title:text | _score:double | rerank_score:double
267+
Return of the Shadow | 2.8181066513061523 | 5.740527994930744E-4
268+
Return of the King Being the Third Part of The Lord of the Rings | 3.6248698234558105 | 9.000900317914784E-4
269+
The Lays of Beleriand | 1.3002015352249146 | 9.36329597607255E-4
270+
// end::two-queries-result[]
271+
;
272+
273+
combine
274+
required_capability: rerank
275+
required_capability: rerank_combine
276+
277+
// tag::combine[]
278+
FROM books METADATA _score
279+
| WHERE MATCH(description, "hobbit") OR MATCH(author, "Tolkien")
280+
| SORT _score DESC
281+
| LIMIT 100
282+
| RERANK rerank_score = "hobbit" ON description, author WITH { "inference_id" : "test_reranker" }
283+
| EVAL original_score = _score, _score = rerank_score + original_score
284+
| SORT _score
285+
| LIMIT 3
286+
| KEEP title, original_score, rerank_score, _score
287+
// end::combine[]
288+
;
289+
290+
// tag::combine-result[]
291+
title:text | _score:double | rerank_score:double | rerank_score:double
292+
Poems from the Hobbit | 4.012462615966797 | 0.001396648003719747 | 0.001396648003719747
293+
The Lord of the Rings - Boxed Set | 3.768855094909668 | 0.0010020040208473802 | 0.001396648003719747
294+
Return of the King Being the Third Part of The Lord of the Rings | 3.6248698234558105 | 9.000900317914784E-4 | 0.001396648003719747
295+
// end::combine-result[]
296+
;

0 commit comments

Comments
 (0)