-
Notifications
You must be signed in to change notification settings - Fork 6
Adds semantic query tuning parameters #971
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 |
|---|---|---|
|
|
@@ -3,4 +3,26 @@ class TimdexSchema < GraphQL::Schema | |
| trace_class(GraphQL::Tracing::LegacyTrace) | ||
|
|
||
| query(Types::QueryType) | ||
|
|
||
| use GraphQL::Schema::Visibility | ||
|
|
||
| # Hide arguments marked as "INTERNAL USE ONLY" from introspection queries | ||
| def self.visible?(member, context) | ||
| # 1. Detect if the member is one of your internal arguments | ||
| if member.respond_to?(:description) && member.description&.include?('INTERNAL USE ONLY') | ||
|
|
||
| # 2. Extract the root operation fields being requested | ||
| selected_fields = context.query&.selected_operation&.selections || [] | ||
|
|
||
| # 3. Check if any root field is an introspection entrypoint (__schema or __type) | ||
| is_introspection = selected_fields.any? do |selection| | ||
| selection.respond_to?(:name) && %w[__schema __type].include?(selection.name) | ||
| end | ||
|
|
||
| # 4. Hide the arguments if GraphiQL/Introspection is sniffing the schema | ||
| return false if is_introspection | ||
| end | ||
|
JPrevost marked this conversation as resolved.
|
||
|
|
||
| super | ||
|
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. |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,18 +105,38 @@ def record_id(id:, index:) | |
| argument :subjects_filter, [String], required: false, default_value: nil, | ||
| 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' | ||
| 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, **filters) | ||
| query_mode: 'keyword', use_global_scoring: false, semantic_must_boost_threshold: nil, | ||
|
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. |
||
| semantic_drop_boost_threshold: nil, semantic_short_query_max_tokens: 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 | ||
| } | ||
|
JPrevost marked this conversation as resolved.
|
||
|
|
||
| results = Opensearch.new.search(from, query, Timdex::OSClient, highlight: highlight_requested?, index: index, | ||
| fulltext: fulltext, query_mode: query_mode, | ||
| requested_aggregations: requested_aggregations, | ||
| use_global_scoring: use_global_scoring) | ||
| use_global_scoring: use_global_scoring, | ||
| semantic_options: semantic_options) | ||
|
|
||
| response = {} | ||
| response[:hits] = results['hits']['total']['value'] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,13 @@ class Opensearch | |
| MAX_SIZE = 200 | ||
|
|
||
| def search(from, params, client, highlight: false, index: nil, fulltext: false, query_mode: 'keyword', | ||
|
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. |
||
| requested_aggregations: [], use_global_scoring: false) | ||
| requested_aggregations: [], use_global_scoring: false, semantic_options: {}) | ||
| @params = params | ||
| @highlight = highlight | ||
| @fulltext = fulltext?(fulltext) | ||
| @query_mode = query_mode | ||
| @requested_aggregations = requested_aggregations | ||
| @semantic_options = semantic_options | ||
| index = default_index unless index.present? | ||
| search_params = { index:, body: build_query(from) } | ||
| search_params[:search_type] = 'dfs_query_then_fetch' if use_global_scoring | ||
|
|
@@ -69,7 +70,12 @@ def query | |
| LexicalQueryBuilder.new | ||
| end | ||
|
|
||
| builder.build(@params, fulltext: @fulltext) | ||
| # Only pass semantic_options to builders that support it (semantic and hybrid) | ||
| if @query_mode.in?(%w[semantic hybrid]) | ||
| builder.build(@params, fulltext: @fulltext, semantic_options: @semantic_options || {}) | ||
| else | ||
| builder.build(@params, fulltext: @fulltext) | ||
| end | ||
|
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. |
||
| end | ||
|
|
||
| def sort_builder | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.