Skip to content

Commit

Permalink
Merge branch 'metrics' of github.com:o19s/opensearch-search-quality-e…
Browse files Browse the repository at this point in the history
…valuation into metrics
  • Loading branch information
jzonthemtn committed Dec 9, 2024
2 parents 7587a59 + 99ffc09 commit 465ed68
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 276 deletions.
1 change: 0 additions & 1 deletion opensearch-search-quality-evaluation-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dependencies {
compileOnly "org.apache.httpcomponents:httpcore:${versions.httpcore}"
compileOnly "org.apache.httpcomponents:httpclient:${versions.httpclient}"
compileOnly "commons-logging:commons-logging:${versions.commonslogging}"
implementation "org.apache.commons:commons-lang3:3.17.0"
implementation "com.google.code.gson:gson:2.11.0"
yamlRestTestImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}
Expand Down

This file was deleted.

This file was deleted.

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

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.action.index.IndexRequest;
Expand Down Expand Up @@ -113,7 +112,7 @@ public void runJob(final ScheduledJobParameter jobParameter, final JobExecutionC
final long startTime = System.currentTimeMillis();
final long judgments;

if(StringUtils.equalsIgnoreCase(searchQualityEvaluationJobParameter.getClickModel(), "coec")) {
if("coec".equalsIgnoreCase(searchQualityEvaluationJobParameter.getClickModel())) {

LOGGER.info("Beginning implicit judgment generation using clicks-over-expected-clicks.");
final CoecClickModelParameters coecClickModelParameters = new CoecClickModelParameters(true, searchQualityEvaluationJobParameter.getMaxRank());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.rest.RestResponse;

import java.io.IOException;
import java.nio.charset.Charset;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
Expand Down Expand Up @@ -174,7 +175,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
}

// Get the query JSON from the content.
final String query = new String(BytesReference.toBytes(request.content()));
final String query = new String(BytesReference.toBytes(request.content()), Charset.defaultCharset());

// Validate the query has a QUERY_PLACEHOLDER.
if(!query.contains(QUERY_PLACEHOLDER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
package org.opensearch.eval.judgments.model;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.opensearch.eval.judgments.util.MathUtils;

/**
Expand Down Expand Up @@ -42,18 +41,6 @@ public ClickthroughRate(final String objectId, final int clicks, final int event
this.events = events;
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public int hashCode() {
int result = 17;
result = 29 * result + objectId.hashCode();
return result;
}

@Override
public String toString() {
return "object_id: " + objectId + ", clicks: " + clicks + ", events: " + events + ", ctr: " + MathUtils.round(getClickthroughRate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package org.opensearch.eval.judgments.model;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.eval.judgments.util.MathUtils;
Expand Down Expand Up @@ -106,21 +104,6 @@ public String toString() {
return "query_id: " + queryId + ", query: " + query + ", document: " + document + ", judgment: " + MathUtils.round(judgment);
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).
append(queryId).
append(query).
append(document).
append(judgment).
toHashCode();
}

/**
* Gets the judgment's query ID.
* @return The judgment's query ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
package org.opensearch.eval.judgments.model.ubi.query;

import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Map;

Expand Down Expand Up @@ -47,20 +45,6 @@ public UbiQuery() {

}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).
append(queryId).
append(userQuery).
append(clientId).
toHashCode();
}

/**
* Gets the timestamp for the query.
* @return The timestamp for the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ public String getName() {
@Override
public double calculate() {

// TODO: Implement precision calculation.
return 0.0;
int numberOfRelevantItems = 0;

for(final double relevanceScore : relevanceScores) {
if(relevanceScore >= threshold) {
numberOfRelevantItems++;
}
}

return (double) numberOfRelevantItems / (double) k;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public int getK() {
/**
* Gets the value of the metric. If the metric has not yet been calculated,
* the metric will first be calculated by calling <code>calculate</code>. This
* function should be used in cases where repeated access to the metric's value is
* needed without recalculating the metric's value.
* function should be used in cases where repeated access to the metrics value is
* needed without recalculating the metrics value.
* @return The value of the metric.
*/
public double getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final Collection<Map<String, Long>> getQuerySet(final String querySetId)
// TODO: Don't use .get()
final SearchResponse searchResponse = client.search(searchRequest).get();

if (searchResponse.getHits().getHits().length > 0) {
if(searchResponse.getHits().getHits().length > 0) {

// The queries from the query set that will be run.
return (Collection<Map<String, Long>>) searchResponse.getHits().getAt(0).getSourceAsMap().get("queries");
Expand Down
Loading

0 comments on commit 465ed68

Please sign in to comment.