-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add telemetry for retrievers #114109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pmpailis
merged 26 commits into
elastic:main
from
pmpailis:add_telemetry_for_retrievers
Oct 10, 2024
Merged
Add telemetry for retrievers #114109
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6dae9bc
iter
pmpailis a964602
iter
pmpailis aa7dc0c
Update docs/changelog/114109.yaml
pmpailis d82fbb9
iter
pmpailis 2f62c3c
iter
pmpailis f97e5c1
Merge branch 'add_telemetry_for_retrievers' of github.com:pmpailis/el…
pmpailis 88b9384
iter
pmpailis f7e4802
iter
pmpailis 23e9d6b
iter
pmpailis fb4a5cd
Merge branch 'main' into add_telemetry_for_retrievers
pmpailis e7013bc
Merge branch 'main' into add_telemetry_for_retrievers
pmpailis 9c91463
iter
pmpailis ef79526
iter
pmpailis edb4256
iter
pmpailis 67cf2ab
fixing test
pmpailis c245fe6
Merge branch 'main' into add_telemetry_for_retrievers
elasticmachine a988946
Update docs/changelog/114109.yaml
pmpailis 1a15135
addressing PR comments - refactoring tests
pmpailis 2e78d81
restoring visibility
pmpailis 215f120
updating bwc serialization test
pmpailis 32202c8
Merge branch 'main' into add_telemetry_for_retrievers
elasticmachine f369477
Merge branch 'main' into add_telemetry_for_retrievers
elasticmachine 84b24b4
Merge branch 'main' into add_telemetry_for_retrievers
elasticmachine d68fd63
Merge branch 'main' into add_telemetry_for_retrievers
pmpailis 75eddec
Merge branch 'main' into add_telemetry_for_retrievers
elasticmachine b04f23e
Merge branch 'main' into add_telemetry_for_retrievers
pmpailis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 114109 | ||
summary: Add telemetry for retrievers | ||
area: Search | ||
type: enhancement | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...src/internalClusterTest/java/org/elasticsearch/search/retriever/RetrieverTelemetryIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.search.retriever; | ||
|
||
import org.elasticsearch.action.admin.cluster.node.capabilities.NodesCapabilitiesRequest; | ||
import org.elasticsearch.action.admin.cluster.node.capabilities.NodesCapabilitiesResponse; | ||
import org.elasticsearch.action.admin.cluster.stats.SearchUsageStats; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.index.query.QueryBuilders; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.search.vectors.KnnSearchBuilder; | ||
import org.elasticsearch.search.vectors.KnnVectorQueryBuilder; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentFactory; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class RetrieverTelemetryIT extends ESIntegTestCase { | ||
|
||
private static final String INDEX_NAME = "test_index"; | ||
|
||
@Override | ||
protected boolean addMockHttpTransport() { | ||
return false; // enable http | ||
} | ||
|
||
@Before | ||
public void setup() throws IOException { | ||
XContentBuilder builder = XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("properties") | ||
.startObject("vector") | ||
.field("type", "dense_vector") | ||
.field("dims", 1) | ||
.field("index", true) | ||
.field("similarity", "l2_norm") | ||
.startObject("index_options") | ||
.field("type", "hnsw") | ||
.endObject() | ||
.endObject() | ||
.startObject("text") | ||
.field("type", "text") | ||
.endObject() | ||
.startObject("integer") | ||
.field("type", "integer") | ||
.endObject() | ||
.startObject("topic") | ||
.field("type", "keyword") | ||
.endObject() | ||
.endObject() | ||
.endObject(); | ||
|
||
assertAcked(prepareCreate(INDEX_NAME).setMapping(builder)); | ||
ensureGreen(INDEX_NAME); | ||
} | ||
|
||
public void testTelemetryForRetrievers() throws IOException { | ||
|
||
if (false == isRetrieverTelemetryEnabled()) { | ||
return; | ||
} | ||
|
||
// search#1 - this will record 1 entry for "retriever" in `sections`, and 1 for "knn" under `retrievers` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
pmpailis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.retriever(new KnnRetrieverBuilder("vector", new float[] { 1.0f }, null, 10, 15, null)); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// search#2 - this will record 1 entry for "retriever" in `sections`, 1 for "standard" under `retrievers`, and 1 for "range" under | ||
// `queries` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.retriever(new StandardRetrieverBuilder(QueryBuilders.rangeQuery("integer").gte(2))); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// search#3 - this will record 1 entry for "retriever" in `sections`, and 1 for "standard" under `retrievers`, and 1 for "knn" under | ||
// `queries` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.retriever(new StandardRetrieverBuilder(new KnnVectorQueryBuilder("vector", new float[] { 1.0f }, 10, 15, null))); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// search#4 - this will record 1 entry for "retriever" in `sections`, and 1 for "standard" under `retrievers`, and 1 for "term" | ||
// under `queries` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.retriever(new StandardRetrieverBuilder(QueryBuilders.termQuery("topic", "foo"))); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// search#5 - this will record 1 entry for "knn" in `sections` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.knnSearch(List.of(new KnnSearchBuilder("vector", new float[] { 1.0f }, 10, 15, null))); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// search#6 - this will record 1 entry for "query" in `sections`, and 1 for "match_all" under `queries` | ||
{ | ||
Request request = new Request("GET", INDEX_NAME + "/_search"); | ||
SearchSourceBuilder source = new SearchSourceBuilder(); | ||
source.query(QueryBuilders.matchAllQuery()); | ||
request.setJsonEntity(Strings.toString(source)); | ||
getRestClient().performRequest(request); | ||
} | ||
|
||
// cluster stats | ||
{ | ||
SearchUsageStats stats = clusterAdmin().prepareClusterStats().get().getIndicesStats().getSearchUsageStats(); | ||
assertEquals(6, stats.getTotalSearchCount()); | ||
|
||
assertThat(stats.getSectionsUsage().size(), equalTo(3)); | ||
assertThat(stats.getSectionsUsage().get("retriever"), equalTo(4L)); | ||
assertThat(stats.getSectionsUsage().get("query"), equalTo(1L)); | ||
assertThat(stats.getSectionsUsage().get("knn"), equalTo(1L)); | ||
|
||
assertThat(stats.getRetrieversUsage().size(), equalTo(2)); | ||
assertThat(stats.getRetrieversUsage().get("standard"), equalTo(3L)); | ||
assertThat(stats.getRetrieversUsage().get("knn"), equalTo(1L)); | ||
|
||
assertThat(stats.getQueryUsage().size(), equalTo(4)); | ||
assertThat(stats.getQueryUsage().get("range"), equalTo(1L)); | ||
assertThat(stats.getQueryUsage().get("term"), equalTo(1L)); | ||
assertThat(stats.getQueryUsage().get("match_all"), equalTo(1L)); | ||
assertThat(stats.getQueryUsage().get("knn"), equalTo(1L)); | ||
} | ||
} | ||
|
||
private boolean isRetrieverTelemetryEnabled() throws IOException { | ||
NodesCapabilitiesResponse res = clusterAdmin().nodesCapabilities( | ||
new NodesCapabilitiesRequest().method(RestRequest.Method.GET).path("_cluster/stats").capabilities("retrievers-usage-stats") | ||
).actionGet(); | ||
return res != null && res.isSupported().orElse(false); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.