Skip to content
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

ByFieldRerank Processor (ReRankProcessor enhancement) #932

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
37ec014
Implements initial By Field re rank
brianf-aws Oct 9, 2024
0937419
Merge branch 'opensearch-project:main' into reRankByField-analysis
brianf-aws Oct 10, 2024
620d245
Adds nested TargetField Capability rescoring and deleting
brianf-aws Oct 14, 2024
3e9e279
Merge branch 'opensearch-project:main' into reRankByField-analysis
brianf-aws Oct 14, 2024
7cbcec9
Merge branch 'reRankByField-analysis' of https://github.com/brianf-aw…
brianf-aws Oct 14, 2024
abb0101
Adds Javadocs,renames methods, adds UTs for the remove_target_field f…
brianf-aws Oct 15, 2024
70562ed
Adds IT for ByFieldRerank (Search Pipline workflow)
brianf-aws Oct 16, 2024
8043f08
Adds Rerank Factory UTs for byFieldRerank
brianf-aws Oct 16, 2024
869f152
Adds UTs that involve throwing Exceptions for ByField Rerank
brianf-aws Oct 16, 2024
92e571a
Updates ByFieldRerankProcessor JavaDoc information on what the operat…
brianf-aws Oct 17, 2024
66866a4
Adds keep_previous_score field to ByField processor
brianf-aws Oct 18, 2024
3aa882c
Modifies Factory Test to include Keep_previous_score
brianf-aws Oct 18, 2024
ce9bd7d
Refactors code to be more readable
brianf-aws Oct 18, 2024
58152a3
Extract generic methods in ByFieldRerank to utility class processorSe…
brianf-aws Oct 21, 2024
8d6a2c7
Adds UT for ProcessorUtils and updates CHANGELOG
brianf-aws Oct 21, 2024
ae35ddb
Polishing comments based on javaDoc Task
brianf-aws Oct 21, 2024
5a28b53
adds Final access modifier to public methods, adds logging
brianf-aws Oct 22, 2024
324b37b
Merge branch 'opensearch-project:main' into reRankByField-analysis
brianf-aws Oct 22, 2024
97a19e7
added byField Rerank to feature
brianf-aws Oct 22, 2024
6d282bd
Delete ByField rerank from changelog feature
brianf-aws Oct 22, 2024
ac9766e
delete unneeded text in release notes
brianf-aws Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public SearchResponseProcessor create(
);
return new MLOpenSearchRerankProcessor(description, tag, ignoreFailure, modelId, contextFetchers, clientAccessor);
case BY_FIELD:
boolean DEFAULT_REMOVE_TARGET_FIELD = false;
brianf-aws marked this conversation as resolved.
Show resolved Hide resolved
String targetField = ConfigurationUtils.readStringProperty(
RERANK_PROCESSOR_TYPE,
tag,
Expand All @@ -83,7 +84,7 @@ public SearchResponseProcessor create(
tag,
rerankerConfig,
ByFieldRerankProcessor.REMOVE_TARGET_FIELD,
false
DEFAULT_REMOVE_TARGET_FIELD
);

return new ByFieldRerankProcessor(description, tag, ignoreFailure, targetField, removeTargetField, contextFetchers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Settings;
import org.opensearch.neuralsearch.ml.MLCommonsClientAccessor;
import org.opensearch.neuralsearch.processor.rerank.ByFieldRerankProcessor;
import org.opensearch.neuralsearch.processor.rerank.MLOpenSearchRerankProcessor;
import org.opensearch.neuralsearch.processor.rerank.RerankProcessor;
import org.opensearch.neuralsearch.processor.rerank.RerankType;
Expand Down Expand Up @@ -72,8 +73,18 @@ public void testRerankProcessorFactory_whenNonExistentType_thenFail() {
IllegalArgumentException.class,
() -> factory.create(Map.of(), TAG, DESC, false, config, pipelineContext)
);

Map<String, Object> config2 = new HashMap<>(
Map.of("<Nonsense>", Map.of(ByFieldRerankProcessor.TARGET_FIELD, "path.to.target_field"))
brianf-aws marked this conversation as resolved.
Show resolved Hide resolved
);
assertThrows(
"no rerank type found",
IllegalArgumentException.class,
() -> factory.create(Map.of(), TAG, DESC, false, config2, pipelineContext)
);
}

// Start of MLOpenSearchRerankProcessor Tests
public void testCrossEncoder_whenCorrectParams_thenSuccessful() {
Map<String, Object> config = new HashMap<>(
Map.of(
Expand Down Expand Up @@ -218,5 +229,65 @@ public void testCrossEncoder_whenTooManyDocFields_thenFail() {
() -> factory.create(Map.of(), TAG, DESC, false, config, pipelineContext)
);
}
// End of MLOpenSearchRerankProcessor Tests

// Start of ByFieldRerankProcessor Tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can make this comment part of the test method name

public void testByFieldCreation_whenTargetFieldSpecifiedWithDefaultRemoveTargetField_thenSuccessful() {
Map<String, Object> config = new HashMap<>(
Map.of(RerankType.BY_FIELD.getLabel(), new HashMap<>(Map.of(ByFieldRerankProcessor.TARGET_FIELD, "path.to.target_field")))
);
SearchResponseProcessor processor = factory.create(Map.of(), TAG, DESC, false, config, pipelineContext);
assert (processor instanceof RerankProcessor);
assert (processor instanceof ByFieldRerankProcessor);
assert (processor.getType().equals(RerankProcessor.TYPE));
}

public void testByFieldCreation_whenTargetFieldSpecifiedWithManualRemoveTargetField_thenSuccessful() {
boolean removeTargetField = true;
Map<String, Object> config = new HashMap<>(
Map.of(
RerankType.BY_FIELD.getLabel(),
new HashMap<>(
Map.of(
ByFieldRerankProcessor.TARGET_FIELD,
"path.to.target_field",
ByFieldRerankProcessor.REMOVE_TARGET_FIELD,
removeTargetField
)
)
)
);
SearchResponseProcessor processor = factory.create(Map.of(), TAG, DESC, false, config, pipelineContext);
assert (processor instanceof RerankProcessor);
assert (processor instanceof ByFieldRerankProcessor);
assert (processor.getType().equals(RerankProcessor.TYPE));
}

public void testByFieldCreation_WithContext_thenSucceed() {
// You can pass context but, it won't ever be used by ByFieldRerank
Map<String, Object> config = new HashMap<>(
Map.of(
RerankType.BY_FIELD.getLabel(),
new HashMap<>(Map.of(ByFieldRerankProcessor.TARGET_FIELD, "path.to.target_field")),
RerankProcessorFactory.CONTEXT_CONFIG_FIELD,
new HashMap<>(Map.of(DocumentContextSourceFetcher.NAME, new ArrayList<>(List.of("text_representation"))))
)
);
SearchResponseProcessor processor = factory.create(Map.of(), TAG, DESC, false, config, pipelineContext);

assert (processor instanceof RerankProcessor);
assert (processor instanceof ByFieldRerankProcessor);
assert (processor.getType().equals(RerankProcessor.TYPE));
}

public void testByField_whenEmptySubConfig_thenFail() {
Map<String, Object> config = new HashMap<>(Map.of(RerankType.BY_FIELD.getLabel(), new HashMap<>()));
assertThrows(
String.format(Locale.ROOT, "[%s] required property is missing", ByFieldRerankProcessor.TARGET_FIELD),
OpenSearchParseException.class,
() -> factory.create(Map.of(), TAG, DESC, false, config, pipelineContext)
);
}
// End of ByFieldRerankProcessor Tests

}
Loading