Skip to content

Commit

Permalink
Wiring up metrics calculation for the query set and individual queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Dec 3, 2024
1 parent 443d031 commit 1d5f773
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onFailure(Exception ex) {
}

// TODO: Calculate the search metrics given the results and the judgments.
final SearchMetrics searchMetrics = new SearchMetrics(k);
final SearchMetrics searchMetrics = new SearchMetrics(queryResults, k);

return new QuerySetRunResult(queryResults, searchMetrics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import java.util.List;

/**
* Contains the search results for a query.
* Contains the search results for a single query.
*/
public class QueryResult {

private final String query;
private final List<String> orderedDocumentIds;

// TODO: Calculate these metrics.
private final SearchMetrics searchMetrics;

/**
Expand All @@ -31,7 +29,7 @@ public class QueryResult {
public QueryResult(final String query, final List<String> orderedDocumentIds, final int k) {
this.query = query;
this.orderedDocumentIds = orderedDocumentIds;
this.searchMetrics = new SearchMetrics(k);
this.searchMetrics = new SearchMetrics(query, orderedDocumentIds, k);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.eval.runners;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -22,8 +23,26 @@ public class SearchMetrics {
private double ndcg = 0.0;
private double precision = 0.0;

public SearchMetrics(final int k) {
/**
* Create the search metrics for an entire query set.
* @param queryResults A list of {@link QueryResult}.
* @param k The k used for metrics calculation, i.e. DCG@k.
*/
public SearchMetrics(final List<QueryResult> queryResults, final int k) {
this.k = k;

// TODO: Calculate the metrics for the whole query set.
}

/**
* Create the search metrics for a single query.
* @param k The k used for metrics calculation, i.e. DCG@k.
*/
public SearchMetrics(final String query, final List<String> orderedDocumentIds, final int k) {
this.k = k;

// TODO: Calculate the metrics for the single query.
}

/**
Expand Down

0 comments on commit 1d5f773

Please sign in to comment.