Skip to content

Commit c9a67fc

Browse files
committed
Implement new syntax for RERANK and COMPLETION
1 parent 34ccaba commit c9a67fc

File tree

21 files changed

+2226
-2187
lines changed

21 files changed

+2226
-2187
lines changed

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestRerankTestCase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void testRerankWithSingleField() throws IOException {
8888
String query = """
8989
FROM rerank-test-index
9090
| WHERE match(title, "exploration")
91-
| RERANK "exploration" ON title WITH test_reranker
91+
| RERANK "exploration" ON title OPTIONS inferenceId=test_reranker
9292
| EVAL _score = ROUND(_score, 5)
9393
""";
9494

@@ -107,7 +107,7 @@ public void testRerankWithMultipleFields() throws IOException {
107107
String query = """
108108
FROM rerank-test-index
109109
| WHERE match(title, "exploration")
110-
| RERANK "exploration" ON title, author WITH test_reranker
110+
| RERANK "exploration" ON title, author OPTIONS inferenceId=test_reranker
111111
| EVAL _score = ROUND(_score, 5)
112112
""";
113113

@@ -126,7 +126,7 @@ public void testRerankWithPositionalParams() throws IOException {
126126
String query = """
127127
FROM rerank-test-index
128128
| WHERE match(title, "exploration")
129-
| RERANK ? ON title WITH ?
129+
| RERANK ? ON title OPTIONS inferenceId=?
130130
| EVAL _score = ROUND(_score, 5)
131131
""";
132132

@@ -145,7 +145,7 @@ public void testRerankWithNamedParams() throws IOException {
145145
String query = """
146146
FROM rerank-test-index
147147
| WHERE match(title, ?queryText)
148-
| RERANK ?queryText ON title WITH ?inferenceId
148+
| RERANK ?queryText ON title OPTIONS inferenceId=?inferenceId
149149
| EVAL _score = ROUND(_score, 5)
150150
""";
151151

@@ -164,7 +164,7 @@ public void testRerankWithMissingInferenceId() {
164164
String query = """
165165
FROM rerank-test-index
166166
| WHERE match(title, "exploration")
167-
| RERANK "exploration" ON title WITH test_missing
167+
| RERANK "exploration" ON title OPTIONS inferenceId=test_missing
168168
| EVAL _score = ROUND(_score, 5)
169169
""";
170170

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ completion using a ROW source operator
66
required_capability: completion
77

88
ROW prompt="Who is Victor Hugo?"
9-
| COMPLETION completion_output = prompt WITH test_completion
9+
| COMPLETION prompt INTO completion_output OPTIONS inferenceId=test_completion
1010
;
1111

1212
prompt:keyword | completion_output:keyword
@@ -18,7 +18,7 @@ completion using a ROW source operator and prompt is a multi-valued field
1818
required_capability: completion
1919

2020
ROW prompt=["Answer the following question:", "Who is Victor Hugo?"]
21-
| COMPLETION completion_output = prompt WITH test_completion
21+
| COMPLETION prompt INTO completion_output OPTIONS inferenceId=test_completion
2222
;
2323

2424
prompt:keyword | completion_output:keyword
@@ -34,7 +34,7 @@ FROM books METADATA _score
3434
| WHERE title:"war and peace" AND author:"Tolstoy"
3535
| SORT _score DESC
3636
| LIMIT 2
37-
| COMPLETION title WITH test_completion
37+
| COMPLETION title OPTIONS inferenceId=test_completion
3838
| KEEP title, completion
3939
;
4040

@@ -51,7 +51,7 @@ FROM books METADATA _score
5151
| WHERE title:"war and peace" AND author:"Tolstoy"
5252
| SORT _score DESC
5353
| LIMIT 2
54-
| COMPLETION CONCAT("This is a prompt: ", title) WITH test_completion
54+
| COMPLETION CONCAT("This is a prompt: ", title) OPTIONS inferenceId=test_completion
5555
| KEEP title, completion
5656
;
5757

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ FROM employees
781781
| KEEP emp_no, first_name, last_name
782782
| FORK (WHERE emp_no == 10048 OR emp_no == 10081)
783783
(WHERE emp_no == 10081 OR emp_no == 10087)
784-
| COMPLETION x = CONCAT(first_name, " ", last_name) WITH test_completion
784+
| COMPLETION CONCAT(first_name, " ", last_name) INTO x OPTIONS inferenceId=test_completion
785785
| SORT _fork, emp_no
786786
;
787787

@@ -799,7 +799,7 @@ required_capability: completion
799799
FROM employees
800800
| KEEP emp_no, first_name, last_name
801801
| FORK (WHERE emp_no == 10048 OR emp_no == 10081
802-
| COMPLETION x = CONCAT(first_name, " ", last_name) WITH test_completion)
802+
| COMPLETION CONCAT(first_name, " ", last_name) INTO x OPTIONS inferenceId=test_completion)
803803
(WHERE emp_no == 10081 OR emp_no == 10087)
804804
| SORT _fork, emp_no
805805
;
@@ -817,7 +817,7 @@ required_capability: completion
817817

818818
FROM employees
819819
| KEEP emp_no, first_name, last_name
820-
| COMPLETION x = CONCAT(first_name, " ", last_name) WITH test_completion
820+
| COMPLETION CONCAT(first_name, " ", last_name) INTO x OPTIONS inferenceId=test_completion
821821
| FORK (WHERE emp_no == 10048 OR emp_no == 10081)
822822
(WHERE emp_no == 10081 OR emp_no == 10087)
823823
| SORT _fork, emp_no

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ required_capability: match_operator_colon
1010
FROM books METADATA _score
1111
| WHERE title:"war and peace" AND author:"Tolstoy"
1212
| SORT _score DESC, book_no ASC
13-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker
13+
| RERANK "war and peace" ON title OPTIONS inferenceId=test_reranker
1414
| EVAL _score=ROUND(_score, 2)
1515
| KEEP book_no, title, author, _score
1616
;
@@ -29,7 +29,7 @@ required_capability: match_operator_colon
2929
FROM books METADATA _score
3030
| WHERE title:"war and peace" AND author:"Tolstoy"
3131
| SORT _score DESC, book_no ASC
32-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker, scoreColumn=rerank_score
32+
| RERANK "war and peace" ON title INTO rerank_score OPTIONS inferenceId=test_reranker
3333
| EVAL _score=ROUND(_score, 2), rerank_score=ROUND(rerank_score, 2)
3434
| KEEP book_no, title, author, rerank_score
3535
;
@@ -48,7 +48,7 @@ required_capability: match_operator_colon
4848
FROM books METADATA _score
4949
| WHERE title:"war and peace" AND author:"Tolstoy"
5050
| SORT _score DESC
51-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker, scoreColumn=rerank_score
51+
| RERANK "war and peace" ON title INTO rerank_score OPTIONS inferenceId=test_reranker
5252
| EVAL _score=ROUND(_score, 2), rerank_score=ROUND(rerank_score, 2)
5353
| SORT rerank_score, _score ASC, book_no ASC
5454
| KEEP book_no, title, author, rerank_score
@@ -68,7 +68,7 @@ required_capability: match_operator_colon
6868

6969
FROM books METADATA _score
7070
| WHERE title:"war and peace" AND author:"Tolstoy"
71-
| RERANK "war and peace" ON title, author WITH inferenceId=test_reranker
71+
| RERANK "war and peace" ON title, author OPTIONS inferenceId=test_reranker
7272
| EVAL _score=ROUND(_score, 2)
7373
| SORT _score DESC, book_no ASC
7474
| KEEP book_no, title, author, _score
@@ -90,7 +90,7 @@ FROM books METADATA _score
9090
| WHERE title:"war and peace" AND author:"Tolstoy"
9191
| SORT _score DESC, book_no ASC
9292
| LIMIT 3
93-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker
93+
| RERANK "war and peace" ON title OPTIONS inferenceId=test_reranker
9494
| EVAL _score=ROUND(_score, 2)
9595
| SORT _score DESC, book_no ASC
9696
| KEEP book_no, title, author, _score
@@ -109,7 +109,7 @@ required_capability: match_operator_colon
109109

110110
FROM books METADATA _score
111111
| WHERE title:"war and peace" AND author:"Tolstoy"
112-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker
112+
| RERANK "war and peace" ON title OPTIONS inferenceId=test_reranker
113113
| EVAL _score=ROUND(_score, 2)
114114
| SORT _score DESC, book_no ASC
115115
| KEEP book_no, title, author, _score
@@ -129,7 +129,7 @@ required_capability: match_operator_colon
129129

130130
FROM books
131131
| WHERE title:"war and peace" AND author:"Tolstoy"
132-
| RERANK "war and peace" ON title WITH inferenceId=test_reranker
132+
| RERANK "war and peace" ON title OPTIONS inferenceId=test_reranker
133133
| EVAL _score=ROUND(_score, 2)
134134
| KEEP book_no, title, author, _score
135135
| SORT author, title
@@ -153,7 +153,7 @@ FROM books METADATA _id, _index, _score
153153
| FORK ( WHERE title:"Tolkien" | SORT _score, _id DESC | LIMIT 3 )
154154
( WHERE author:"Tolkien" | SORT _score, _id DESC | LIMIT 3 )
155155
| RRF
156-
| RERANK "Tolkien" ON title WITH inferenceId=test_reranker
156+
| RERANK "Tolkien" ON title OPTIONS inferenceId=test_reranker
157157
| EVAL _score=ROUND(_score, 2)
158158
| SORT _score DESC, book_no ASC
159159
| LIMIT 2

0 commit comments

Comments
 (0)