Conversation
Why are these changes being introduced: * We want to be able to tune the semantic query parameters for better results. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/USE-619 How does this address that need: * Introduces new semantic query tuning parameters to the GraphQL API. * Ensures those parameters are not documented publicly by prefixing them with `INTERNAL USE ONLY` in the description and skipping them in introspection queries.
❌ 9 blocking issues (14 total)
|
| 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.
I choose to quietly ignore this until it's at least 5x the recommended maximum.
| @@ -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.
Pull request overview
This PR adds internal semantic query tuning knobs to the GraphQL search API and threads them through to the semantic-query Lambda payload, while attempting to hide these knobs from public schema introspection.
Changes:
- Add
semantic_*tuning arguments to GraphQLsearchand pass them through to OpenSearch query building. - Extend
Opensearch,HybridQueryBuilder, andSemanticQueryBuilderto accept and forwardsemantic_options. - Add schema-level visibility logic intended to hide “INTERNAL USE ONLY” arguments from introspection.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| app/models/semantic_query_builder.rb | Accepts semantic tuning options and conditionally adds them to the Lambda invocation payload. |
| app/models/opensearch.rb | Stores semantic options and passes them only for semantic/hybrid query modes. |
| app/models/hybrid_query_builder.rb | Forwards semantic options into SemanticQueryBuilder. |
| app/graphql/types/query_type.rb | Adds internal GraphQL arguments and constructs the semantic_options hash passed to Opensearch. |
| app/graphql/timdex_schema.rb | Adds visibility hook intended to hide INTERNAL USE ONLY members during introspection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return false if is_introspection | ||
| end | ||
|
|
||
| super |
There was a problem hiding this comment.
| builder.build(@params, fulltext: @fulltext, semantic_options: @semantic_options || {}) | ||
| else | ||
| builder.build(@params, fulltext: @fulltext) | ||
| end |
jazairi
left a comment
There was a problem hiding this comment.
A few non-blocking comments and questions, mostly to improve my own understanding. The code is ![]()
| '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' |
There was a problem hiding this comment.
Is there a range we should specify for max tokens?
There was a problem hiding this comment.
We don't really know yet, but will hopefully learn over time based on measurements with the NDCG work.
This value works together with semantic_drop_boost_threshold.
Short queries (this value) don't drop any noise. Long queries drop noise based on the value of semantic_drop_boost_threshold.
It all hurts my brain.
| 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 |
There was a problem hiding this comment.
Beyond the scope of this PR: do we have docs on what these parameters are and how to tune them?
There was a problem hiding this comment.
This is the closest to useful docs we have on this.
| 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.
I choose to quietly ignore this until it's at least 5x the recommended maximum.
|
|
||
| test 'includes semantic options in lambda payload' do | ||
| query_text = 'test query' | ||
| mock_response = { |
There was a problem hiding this comment.
Non-blocking: it seems like we reuse this response a lot. It might make sense to refactor it to a helper method for readability.
Why are these changes being introduced:
Relevant ticket(s):
How does this address that need:
INTERNAL USE ONLYin the description and skipping them in introspection queries.Developer
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Code Reviewer
(not just this pull request message)
Requires database migrations?
NO
Includes new or updated dependencies?
NO