Skip to content

Commit 097f2fa

Browse files
authored
[8.19] Pinned retriever (elastic#126401) (elastic#127639)
* Pinned retriever (elastic#126401) * Created PinnedQueryRetriever Builder * Added retriever build test file * Changed the test to accept all the retrievers as its not licensed * [CI] Auto commit changes from spotless * Added integration test and fixed the code style issues * Fixed merge issues * Added cluster test feature to the integration tests * Update docs/changelog/126401.yaml * Registered retriever plugin * Enhanced changelog description * Added validation to the constructor creation * Introduced validations in the code and incorporated in tests - compiling version * Included PinnedRankDoc to enhance the explain query, validations for inputs anfd sorting. Fixed the tests after these changes * Working on improving integration test and introducing cluster features * Removed cluster test temporarily * Got pinnedretriever yaml to working state without cluster * [CI] Auto commit changes from spotless * Resolved no source yaml error * Cluster loaded successfully * [CI] Auto commit changes from spotless * Fixed integration test * Made validate sort less strict * Included shareddoc sorting in the validate sort * All yaml issues resolved * Explanation yaml files added * Trying to add clustering to the test * [CI] Auto commit changes from spotless * Removed explicit feature specification * Deleted the empty file * Put the node feature in the proper place * Added additional validation in ids and docs * Cleaned the create pinned query validation * made unit tests robust * Remove query.es from version control * Remove result.json from version control * [CI] Auto commit changes from spotless * Everything except explanation is fixed * added duplicate doc test * Applied checkstyle fix, spotless and a failing yaml * Improvements based on PR comments * [CI] Auto commit changes from spotless * Modified the unit test to accomodate the change in createPinnedQuery * Split the yaml to test for basic and trial, cleanedup and acted on all the comments * Remove result.json and query.es from version control * Removed unnecessary comments * Removed redundant file * Fixing CI build error * [CI] Auto commit changes from spotless * Removed pinnedBy as it wasnt necessary * Removed unnecessary ToXContent Information * Fixed transport version charges and cleaned up null checks: " * [CI] Auto commit changes from spotless * Retriever status changed to 9.1 version * cleaned up 2 yamltestsuite for different licenses * Trying to get the clustering works * Cleaned up the yaml clustering and also reorganised the yaml tests * Unnecessary file introduction removed * Reverted the plugins to the previous state as the changes werent necessary * Removed unnecessary transport versioning from pinnedrankdoc * reverted * [CI] Auto commit changes from spotless * Edited the SearchBusinessRules to remove the class from getFeatures * [CI] Auto commit changes from spotless * Cleaned up Pinned retriever to allow only id or docs * Added more test to the pinned retriever * did spotless * Introduced new transport versioning * Cleaning it up * Resolved validate module error * BWT issues * [CI] Auto commit changes from spotless * fix NPE occuring in ci * trying to fix duplicate feature issue * [CI] Auto commit changes from spotless * modified the tests * Playing with pinned retriever CI (elastic#127530) * Fix compilation error * Remove SearchPlugin from META-INF * Remove duplicate FeatureSpecification * Add service as test resource * Move to test * More file moving * Remove from module-info, remove file * Make search business rules plugin extensible * fix ent search plugin * Delete dup files * [CI] Auto commit changes from spotless * Add module info back in --------- Co-authored-by: elasticsearchmachine <[email protected]> * top document no pinned * Removing this to see if it works without this transport version check, as i had made changes related to the cluster error * Fixed the retriever builder comments and error message * removed the unnencessary explain * Fixed all the tests in the yaml file * added extra test case * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Kathleen DeRusso <[email protected]> (cherry picked from commit b742b02) # Conflicts: # server/src/main/java/org/elasticsearch/TransportVersions.java * Fixed the compile issue * changed pinned retriever name
1 parent fd19e89 commit 097f2fa

File tree

17 files changed

+1295
-7
lines changed

17 files changed

+1295
-7
lines changed

docs/changelog/126401.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126401
2+
summary: Add pinned retriever
3+
area: Relevance
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static TransportVersion def(int id) {
209209
public static final TransportVersion SEARCH_INCREMENTAL_TOP_DOCS_NULL_BACKPORT_8_19 = def(8_841_0_20);
210210
public static final TransportVersion ML_INFERENCE_SAGEMAKER_8_19 = def(8_841_0_21);
211211
public static final TransportVersion ESQL_REPORT_ORIGINAL_TYPES_BACKPORT_8_19 = def(8_841_0_22);
212+
public static final TransportVersion PINNED_RETRIEVER_8_19 = def(8_841_0_23);
212213

213214
/*
214215
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/ent-search/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ esplugin {
88
name = 'x-pack-ent-search'
99
description = 'Elasticsearch Expanded Pack Plugin - Enterprise Search'
1010
classname = 'org.elasticsearch.xpack.application.EnterpriseSearch'
11-
extendedPlugins = ['x-pack-core']
11+
extendedPlugins = ['x-pack-core', 'search-business-rules']
1212
}
1313

1414
base {
@@ -17,7 +17,7 @@ base {
1717

1818
dependencies {
1919
compileOnly project(path: xpackModule('core'))
20-
implementation project(xpackModule('search-business-rules'))
20+
compileOnly project(xpackModule('search-business-rules'))
2121
api project(':modules:lang-mustache')
2222

2323
// JSON Schema dependencies

x-pack/plugin/rank-rrf/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
clusterModules project(xpackModule('rank-rrf'))
2727
clusterModules project(xpackModule('inference'))
2828
clusterModules project(':modules:lang-painless')
29+
clusterModules project(xpackModule('search-business-rules'))
2930

3031
clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
3132
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
setup:
2+
- requires:
3+
cluster_features: 'pinned_retriever_supported'
4+
reason: 'test requires pinned retriever implementation'
5+
- do:
6+
indices.create:
7+
index: test-index1
8+
9+
- do:
10+
bulk:
11+
refresh: true
12+
index: test-index1
13+
body:
14+
- index:
15+
_id: doc1
16+
- { "text": "document one" }
17+
- index:
18+
_id: doc2
19+
- { "text": "document two" }
20+
- index:
21+
_id: doc3
22+
- { "text": "document three" }
23+
- index:
24+
_id: doc4
25+
- { "text": "document four" }
26+
- index:
27+
_id: doc5
28+
- { "text": "document five" }
29+
30+
---
31+
"rrf combined with pinned retriever":
32+
- skip: { features: headers }
33+
- do:
34+
headers:
35+
Content-Type: application/json
36+
search:
37+
index: test-index1
38+
body:
39+
retriever:
40+
pinned:
41+
ids: ["doc1"]
42+
retriever:
43+
rrf:
44+
retrievers: [
45+
{
46+
standard: {
47+
query: {
48+
term: { text: "document" }
49+
}
50+
}
51+
},
52+
{
53+
standard: {
54+
query: {
55+
term: { text: "three" }
56+
}
57+
}
58+
}
59+
]
60+
rank_window_size: 10
61+
62+
- match: { hits.total.value: 5 }
63+
- match: { hits.hits.0._id: doc1 }
64+
- match: { hits.hits.0._score: 1.7014122E38 }
65+
- match: { hits.hits.1._id: doc3 }
66+
- match: { hits.hits.1._score < 100.0 }
67+
- match: { hits.hits.2._id: doc2 }
68+
69+
---
70+
"rrf with pinned retriever as a sub-retriever":
71+
- skip: { features: headers }
72+
- do:
73+
headers: { Content-Type: application/json }
74+
search:
75+
index: test-index1
76+
body:
77+
retriever:
78+
rrf:
79+
retrievers:
80+
-
81+
standard:
82+
query:
83+
match: { text: "document" }
84+
-
85+
pinned:
86+
ids: ["doc4", "doc5"]
87+
retriever:
88+
standard:
89+
query:
90+
match: { text: "document" }
91+
92+
- match: { hits.total.value: 5 }
93+
- match: { hits.hits.0._id: doc1 }
94+
- lt: { hits.hits.0._score: 100.0 }
95+
- match: { hits.hits.1._id: doc4 }
96+
- match: { hits.hits.2._id: doc5 }
97+
98+

x-pack/plugin/search-business-rules/build.gradle

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apply plugin: 'elasticsearch.internal-es-plugin'
22
apply plugin: 'elasticsearch.internal-cluster-test'
3+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
34

45
esplugin {
56
name = 'search-business-rules'
@@ -13,6 +14,19 @@ base {
1314

1415
dependencies {
1516
compileOnly project(path: xpackModule('core'))
17+
compileOnly project(':server')
1618
testImplementation(testArtifact(project(xpackModule('core'))))
17-
testImplementation project(":test:framework")
19+
testImplementation(testArtifact(project(':server')))
20+
clusterModules project(xpackModule('search-business-rules'))
21+
clusterModules project(':modules:mapper-extras')
22+
clusterModules project(':modules:lang-painless')
23+
clusterModules project(xpackModule('inference'))
1824
}
25+
26+
tasks.named("yamlRestTest") {
27+
usesDefaultDistribution("uses search business rules plugin")
28+
}
29+
artifacts {
30+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
31+
}
32+

x-pack/plugin/search-business-rules/src/main/java/module-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
requires org.elasticsearch.xcore;
1717

1818
exports org.elasticsearch.xpack.searchbusinessrules;
19+
20+
provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRulesFeatures;
21+
provides org.elasticsearch.plugins.SearchPlugin with org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRules;
1922
}

x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class PinnedQueryBuilder extends AbstractQueryBuilder<PinnedQueryBuilder>
5959

6060
// Organic queries will have their scores capped to this number range,
6161
// We reserve the highest float exponent for scores of pinned queries
62-
private static final float MAX_ORGANIC_SCORE = Float.intBitsToFloat((0xfe << 23)) - 1;
62+
public static final float MAX_ORGANIC_SCORE = Float.intBitsToFloat((0xfe << 23)) - 1;
6363

6464
public PinnedQueryBuilder(QueryBuilder organicQuery, String... ids) {
6565
this(organicQuery, Arrays.asList(ids), null);

x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRules.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@
77

88
package org.elasticsearch.xpack.searchbusinessrules;
99

10+
import org.elasticsearch.plugins.ExtensiblePlugin;
1011
import org.elasticsearch.plugins.Plugin;
1112
import org.elasticsearch.plugins.SearchPlugin;
13+
import org.elasticsearch.plugins.SearchPlugin.QuerySpec;
14+
import org.elasticsearch.plugins.SearchPlugin.RetrieverSpec;
15+
import org.elasticsearch.xcontent.ParseField;
16+
import org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder;
1217

1318
import java.util.List;
1419

1520
import static java.util.Collections.singletonList;
1621

17-
public class SearchBusinessRules extends Plugin implements SearchPlugin {
22+
public class SearchBusinessRules extends Plugin implements SearchPlugin, ExtensiblePlugin {
1823

1924
@Override
2025
public List<QuerySpec<?>> getQueries() {
21-
return singletonList(new QuerySpec<>(PinnedQueryBuilder.NAME, PinnedQueryBuilder::new, PinnedQueryBuilder::fromXContent));
26+
return List.of(new QuerySpec<>(PinnedQueryBuilder.NAME, PinnedQueryBuilder::new, PinnedQueryBuilder::fromXContent));
27+
}
28+
29+
@Override
30+
public List<RetrieverSpec<?>> getRetrievers() {
31+
return singletonList(new RetrieverSpec<>(new ParseField(PinnedRetrieverBuilder.NAME), PinnedRetrieverBuilder::fromXContent));
2232
}
2333

2434
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.searchbusinessrules;
9+
10+
import org.elasticsearch.features.FeatureSpecification;
11+
import org.elasticsearch.features.NodeFeature;
12+
13+
import java.util.Set;
14+
15+
import static org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder.PINNED_RETRIEVER_FEATURE;
16+
17+
public class SearchBusinessRulesFeatures implements FeatureSpecification {
18+
19+
@Override
20+
public Set<NodeFeature> getFeatures() {
21+
return Set.of();
22+
}
23+
24+
@Override
25+
public Set<NodeFeature> getTestFeatures() {
26+
return Set.of(PINNED_RETRIEVER_FEATURE);
27+
}
28+
}

0 commit comments

Comments
 (0)