Skip to content

Commit

Permalink
Removing project. Adding javadocs. Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Nov 21, 2024
1 parent 0d31d44 commit 051d673
Show file tree
Hide file tree
Showing 46 changed files with 383 additions and 1,651 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

#QUERY_SET=`curl -s -X POST "http://localhost:9200/_plugins/search_quality_eval/queryset?name=test&description=fake&sampling=pptss" | jq .query_set | tr -d '"'`
curl -s -X POST "http://localhost:9200/_plugins/search_quality_eval/queryset?name=test&description=fake&sampling=none&max_queries=500"
curl -s -X POST "http://localhost:9200/_plugins/search_quality_eval/queryset?name=test&description=fake&sampling=pptss&max_queries=500"

#echo ${QUERY_SET}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,39 @@

public class SearchQualityEvaluationJobParameter implements ScheduledJobParameter {

/**
* The name of the parameter for providing a name for the scheduled job.
*/
public static final String NAME_FIELD = "name";

/**
* The name of the parameter for creating a job as enabled or disabled.
*/
public static final String ENABLED_FILED = "enabled";

/**
* The name of the parameter for specifying when the job was last updated.
*/
public static final String LAST_UPDATE_TIME_FIELD = "last_update_time";

/**
* The name of the parameter for specifying a readable time for when the job was last updated.
*/
public static final String LAST_UPDATE_TIME_FIELD_READABLE = "last_update_time_field";
public static final String SCHEDULE_FIELD = "schedule";
public static final String ENABLED_TIME_FILED = "enabled_time";
public static final String ENABLED_TIME_FILED_READABLE = "enabled_time_field";
public static final String LOCK_DURATION_SECONDS = "lock_duration_seconds";
public static final String JITTER = "jitter";

// Custom properties.
/**
* The name of the parameter that allows for specifying the type of click model to use.
*/
public static final String CLICK_MODEL = "click_model";

/**
* The name of the parameter that allows for setting a max rank value to use during judgment generation.
*/
public static final String MAX_RANK = "max_rank";

// Properties from ScheduledJobParameter.
Expand Down Expand Up @@ -136,46 +157,90 @@ public Double getJitter() {
return jitter;
}

/**
* Sets the name of the job.
* @param jobName The name of the job.
*/
public void setJobName(String jobName) {
this.jobName = jobName;
}

/**
* Sets when the job was last updated.
* @param lastUpdateTime An {@link Instant} of when the job was last updated.
*/
public void setLastUpdateTime(Instant lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}

/**
* Sets when the job was enabled.
* @param enabledTime An {@link Instant} of when the job was enabled.
*/
public void setEnabledTime(Instant enabledTime) {
this.enabledTime = enabledTime;
}

/**
* Sets whether the job is enabled.
* @param enabled A boolean representing whether the job is enabled.
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

/**
* Sets the schedule for the job.
* @param schedule A {@link Schedule} for the job.
*/
public void setSchedule(Schedule schedule) {
this.schedule = schedule;
}

/**
* Sets the lock duration for the cluster when running the job.
* @param lockDurationSeconds The lock duration in seconds.
*/
public void setLockDurationSeconds(Long lockDurationSeconds) {
this.lockDurationSeconds = lockDurationSeconds;
}

/**
* Sets the jitter for the job.
* @param jitter The jitter for the job.
*/
public void setJitter(Double jitter) {
this.jitter = jitter;
}

/**
* Gets the type of click model to use for implicit judgment generation.
* @return The type of click model to use for implicit judgment generation.
*/
public String getClickModel() {
return clickModel;
}

/**
* Sets the click model type to use for implicit judgment generation.
* @param clickModel The click model type to use for implicit judgment generation.
*/
public void setClickModel(String clickModel) {
this.clickModel = clickModel;
}

/**
* Gets the max rank to use when generating implicit judgments.
* @return The max rank to use when generating implicit judgments.
*/
public int getMaxRank() {
return maxRank;
}

/**
* Sets the max rank to use when generating implicit judgments.
* @param maxRank The max rank to use when generating implicit judgments.
*/
public void setMaxRank(int maxRank) {
this.maxRank = maxRank;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@
import java.util.Map;
import java.util.UUID;

/**
* Job runner for scheduled implicit judgments jobs.
*/
public class SearchQualityEvaluationJobRunner implements ScheduledJobRunner {

private static final Logger LOGGER = LogManager.getLogger(SearchQualityEvaluationJobRunner.class);

private static SearchQualityEvaluationJobRunner INSTANCE;

/**
* Gets a singleton instance of this class.
* @return A {@link SearchQualityEvaluationJobRunner}.
*/
public static SearchQualityEvaluationJobRunner getJobRunnerInstance() {

LOGGER.info("Getting job runner instance");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,36 @@
import java.util.List;
import java.util.function.Supplier;

/**
* Main class for the Search Quality Evaluation plugin.
*/
public class SearchQualityEvaluationPlugin extends Plugin implements ActionPlugin, JobSchedulerExtension {

private static final Logger LOGGER = LogManager.getLogger(SearchQualityEvaluationPlugin.class);

/**
* The name of the UBI index containing the queries. This should not be changed.
*/
public static final String UBI_QUERIES_INDEX_NAME = "ubi_queries";

/**
* The name of the UBI index containing the events. This should not be changed.
*/
public static final String UBI_EVENTS_INDEX_NAME = "ubi_events";

/**
* The name of the index to store the scheduled jobs to create implicit judgments.
*/
public static final String SCHEDULED_JOBS_INDEX_NAME = "search_quality_eval_scheduled_jobs";

/**
* The name of the index to store the completed jobs to create implicit judgments.
*/
public static final String COMPLETED_JOBS_INDEX_NAME = "search_quality_eval_completed_jobs";

/**
* The name of the index that stores the query sets.
*/
public static final String QUERY_SETS_INDEX_NAME = "search_quality_eval_query_sets";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ public void onFailure(Exception e) {
}

} else {

return restChannel -> restChannel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, "{\"error\": \"" + request.path() + " was not found.\"}"));

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
*/
package org.opensearch.eval.judgments.clickmodel;

public abstract class ClickModel<T extends ClickModelParameters> {

public static final String INDEX_UBI_EVENTS = "ubi_events";
public static final String INDEX_UBI_QUERIES = "ubi_queries";
/**
* Base class for creating click models.
*/
public abstract class ClickModel {

/**
* Calculate implicit judgments.
* @return The number of implicit judgments created.
* @throws Exception Thrown if the judgments cannot be created.
*/
public abstract long calculateJudgments() throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import org.opensearch.client.Client;
import org.opensearch.client.Requests;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.eval.SearchQualityEvaluationPlugin;
import org.opensearch.eval.judgments.clickmodel.ClickModel;
import org.opensearch.eval.judgments.model.ClickthroughRate;
import org.opensearch.eval.judgments.model.Judgment;
import org.opensearch.eval.judgments.model.ubi.event.UbiEvent;
import org.opensearch.eval.judgments.opensearch.OpenSearchHelper;
import org.opensearch.eval.judgments.util.MathUtils;
import org.opensearch.eval.judgments.util.UserQueryHash;
import org.opensearch.eval.judgments.util.IncrementalUserQueryHash;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders;
Expand All @@ -46,7 +47,7 @@
import java.util.Map;
import java.util.Set;

public class CoecClickModel extends ClickModel<CoecClickModelParameters> {
public class CoecClickModel extends ClickModel {

// OpenSearch indexes.
public static final String INDEX_RANK_AGGREGATED_CTR = "rank_aggregated_ctr";
Expand All @@ -61,7 +62,7 @@ public class CoecClickModel extends ClickModel<CoecClickModelParameters> {

private final OpenSearchHelper openSearchHelper;

private final UserQueryHash userQueryHash = new UserQueryHash();
private final IncrementalUserQueryHash incrementalUserQueryHash = new IncrementalUserQueryHash();
private final Gson gson = new Gson();
private final Client client;

Expand Down Expand Up @@ -144,7 +145,7 @@ public long calculateCoec(final Map<Integer, Double> rankAggregatedClickThrough,
final double judgment = totalNumberClicksForQueryResult / denominatorSum;

// Hash the user query to get a query ID.
final int queryId = userQueryHash.getHash(userQuery);
final int queryId = incrementalUserQueryHash.getHash(userQuery);

// Add the judgment to the list.
// TODO: What to do for query ID when the values are per user_query instead?
Expand Down Expand Up @@ -238,7 +239,7 @@ private Map<String, Set<ClickthroughRate>> getClickthroughRate(final int maxRank
final Scroll scroll = new Scroll(TimeValue.timeValueMinutes(10L));

final SearchRequest searchRequest = Requests
.searchRequest(INDEX_UBI_EVENTS)
.searchRequest(SearchQualityEvaluationPlugin.UBI_EVENTS_INDEX_NAME)
.source(searchSourceBuilder)
.scroll(scroll);

Expand Down Expand Up @@ -329,7 +330,7 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception {
searchSourceBuilder.from(0);
searchSourceBuilder.size(100);

final SearchRequest searchRequest = new SearchRequest(INDEX_UBI_EVENTS).source(searchSourceBuilder);
final SearchRequest searchRequest = new SearchRequest(SearchQualityEvaluationPlugin.UBI_EVENTS_INDEX_NAME).source(searchSourceBuilder);
final SearchResponse searchResponse = client.search(searchRequest).get();

final Map<Integer, Double> clickCounts = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,57 @@

import org.opensearch.eval.judgments.clickmodel.ClickModelParameters;

/**
* The parameters for the {@link CoecClickModel}.
*/
public class CoecClickModelParameters extends ClickModelParameters {

private final boolean persist;
private final int maxRank;
private int roundingDigits = 3;

/**
* Creates new parameters.
* @param persist Whether to persist the calculated judgments.
* @param maxRank The max rank to use when calculating the judgments.
*/
public CoecClickModelParameters(boolean persist, final int maxRank) {
this.persist = persist;
this.maxRank = maxRank;
}

/**
* Creates new parameters.
* @param persist Whether to persist the calculated judgments.
* @param maxRank The max rank to use when calculating the judgments.
* @param roundingDigits The number of decimal places to round calculated values to.
*/
public CoecClickModelParameters(boolean persist, final int maxRank, final int roundingDigits) {
this.persist = persist;
this.maxRank = maxRank;
this.roundingDigits = roundingDigits;
}

/**
* Gets whether to persist the calculated judgments.
* @return Whether to persist the calculated judgments.
*/
public boolean isPersist() {
return persist;
}

/**
* Gets the max rank for the implicit judgments calculation.
* @return The max rank for the implicit judgments calculation.
*/
public int getMaxRank() {
return maxRank;
}

/**
* Gets the number of rounding digits to use for judgments.
* @return The number of rounding digits to use for judgments.
*/
public int getRoundingDigits() {
return roundingDigits;
}
Expand Down
Loading

0 comments on commit 051d673

Please sign in to comment.