-
Notifications
You must be signed in to change notification settings - Fork 6
Expose GraphQL tuning parameters #981
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,31 +106,19 @@ def record_id(id:, index:) | |
| description: 'Filter by subject terms. Use the `contentType` aggregation ' \ | ||
| 'for a list of possible values. Multiple values are ANDed.' | ||
|
|
||
| # Internal semantic query tuning parameters (not documented publicly). Must start with `INTERNAL USE ONLY` to be | ||
| # excluded from public documentation. | ||
| argument :semantic_must_boost_threshold, Float, required: false, default_value: nil, | ||
| description: 'INTERNAL USE ONLY: Semantic query must boost ' \ | ||
| 'threshold (0.0-1.0)' | ||
| argument :semantic_drop_boost_threshold, Float, required: false, default_value: nil, | ||
| description: 'INTERNAL USE ONLY: Semantic query drop boost ' \ | ||
| 'threshold (0.0-1.0)' | ||
| argument :semantic_short_query_max_tokens, Integer, required: false, default_value: nil, | ||
| description: 'INTERNAL USE ONLY: Semantic query short ' \ | ||
| 'query max tokens' | ||
| argument :tuning_parameters_input, TuningParametersInputType, required: false, default_value: nil, | ||
| description: 'Experimental tuning parameters ' \ | ||
| 'for semantic search. Not ' \ | ||
| 'recommended for use.' | ||
| end | ||
|
|
||
| def search(searchterm:, citation:, contributors:, funding_information:, geodistance:, geobox:, identifiers:, | ||
| locations:, subjects:, title:, index:, source:, from:, boolean_type:, fulltext:, per_page: 20, | ||
| query_mode: 'keyword', use_global_scoring: false, semantic_must_boost_threshold: nil, | ||
| semantic_drop_boost_threshold: nil, semantic_short_query_max_tokens: nil, **filters) | ||
| query_mode: 'keyword', use_global_scoring: false, tuning_parameters_input: nil, **filters) | ||
| query = construct_query(searchterm, citation, contributors, funding_information, geodistance, geobox, identifiers, | ||
| locations, subjects, title, source, boolean_type, filters, per_page, query_mode) | ||
|
|
||
| semantic_options = { | ||
| must_boost_threshold: semantic_must_boost_threshold, | ||
| drop_boost_threshold: semantic_drop_boost_threshold, | ||
| short_query_max_tokens: semantic_short_query_max_tokens | ||
| } | ||
| semantic_options = validate_and_build_semantic_options(tuning_parameters_input) | ||
|
|
||
| results = Opensearch.new.search(from, query, Timdex::OSClient, highlight: highlight_requested?, index: index, | ||
| fulltext: fulltext, query_mode: query_mode, | ||
|
|
@@ -216,6 +204,44 @@ def source_deprecation_handler(query, new_source, old_source) | |
| query | ||
| end | ||
|
|
||
| def validate_and_build_semantic_options(tuning_parameters) | ||
| return {} if tuning_parameters.blank? | ||
|
|
||
| semantic_options = {} | ||
|
|
||
| if tuning_parameters[:must_boost_threshold].present? | ||
| threshold = tuning_parameters[:must_boost_threshold] | ||
| unless threshold.between?(0.0, 1.0) | ||
| raise GraphQL::ExecutionError, | ||
| "tuningParametersInput.mustBoostThreshold must be between 0.0 and 1.0, got #{threshold}" | ||
| end | ||
|
qltysh[bot] marked this conversation as resolved.
Copilot marked this conversation as resolved.
|
||
|
|
||
| semantic_options[:must_boost_threshold] = threshold | ||
| end | ||
|
|
||
| if tuning_parameters[:drop_boost_threshold].present? | ||
| threshold = tuning_parameters[:drop_boost_threshold] | ||
| unless threshold.between?(0.0, 1.0) | ||
| raise GraphQL::ExecutionError, | ||
| "tuningParametersInput.dropBoostThreshold must be between 0.0 and 1.0, got #{threshold}" | ||
| end | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
|
|
||
| semantic_options[:drop_boost_threshold] = threshold | ||
| end | ||
|
|
||
| if tuning_parameters[:short_query_max_tokens].present? | ||
| tokens = tuning_parameters[:short_query_max_tokens] | ||
| unless tokens.positive? | ||
| raise GraphQL::ExecutionError, | ||
| "tuningParametersInput.shortQueryMaxTokens must be greater than 0, got #{tokens}" | ||
| end | ||
|
|
||
| semantic_options[:short_query_max_tokens] = tokens | ||
| end | ||
|
|
||
| semantic_options | ||
|
qltysh[bot] marked this conversation as resolved.
qltysh[bot] marked this conversation as resolved.
qltysh[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 3 issues: |
||
| end | ||
|
|
||
| def collapse_buckets(es_aggs) | ||
| return nil if es_aggs.nil? || es_aggs.empty? | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| module Types | ||
| class TuningParametersInputType < Types::BaseInputObject | ||
| description 'Experimental tuning parameters for semantic search. Not recommended for use.' | ||
|
|
||
| argument :must_boost_threshold, Float, required: false, default_value: nil, | ||
| description: 'Not recommended for use. Range: 0.0 to 1.0' | ||
| argument :drop_boost_threshold, Float, required: false, default_value: nil, | ||
| description: 'Not recommended for use. Range: 0.0 to 1.0' | ||
| argument :short_query_max_tokens, Integer, required: false, default_value: nil, | ||
| description: 'Not recommended for use. Must be greater than 0' | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 2 issues:
1. Function with many parameters (count = 20): search [qlty:function-parameters]
2. Avoid parameter lists longer than 5 parameters. [20/5] [rubocop:Metrics/ParameterLists]