[/v2/resolve] Support v2 style typeOf filtering in indicator resolution#1753
[/v2/resolve] Support v2 style typeOf filtering in indicator resolution#1753clincoln8 wants to merge 8 commits intodatacommonsorg:masterfrom
Conversation
Summary of ChangesHello @clincoln8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the v2 indicator resolution endpoint by introducing the capability to filter results based on entity types. This provides clients with more granular control over the resolution process, enabling them to retrieve only the relevant types of entities, such as statistical variables or topics, directly through the API request. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for typeOf filtering to the indicator resolver, allowing clients to specify the desired entity types in resolution queries. The changes are well-implemented across the handler, core logic, and embeddings resolution parts. I've provided a few suggestions to improve code clarity, performance, and test maintainability. Specifically, I've pointed out a duplicate comment, a performance optimization for the new filtering logic, and a refactoring of the new test to use a table-driven approach.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for typeOf filtering in indicator resolution, enhancing the flexibility of the resolver. The changes involve a significant refactoring of input validation and property expression parsing into dedicated functions (parseResolvePropertyExpression and validateAndParseResolveInputs) within handler_v2.go. This improves modularity and separation of concerns. The core filtering logic is correctly implemented in embeddings.go, and the test suite has been updated to cover these new functionalities. Overall, this is a well-structured and beneficial update.
| // - output property (string) | ||
| // - typeOf filter values ([]string, from the input property filter) | ||
| // - error if validation fails | ||
| func parseResolvePropertyExpression(prop string) (string, string, []string, error) { |
There was a problem hiding this comment.
@n-h-diaz - is there an existing util function that parses the property expression that can be used here?
There was a problem hiding this comment.
Some context for @n-h-diaz:
This uses the v2.ParseProperty method for the parsing and then adds custom validation logic on top of it that's specific to what /v2/resolve currently supports.
Let me know if I should make this more generic / re-usable!
n-h-diaz
left a comment
There was a problem hiding this comment.
thanks for all the additional validation!
| } | ||
|
|
||
| // Parse `property` expression into its in arc property, out arc property and typeOf filter values | ||
| if in.GetProperty() == "" { |
There was a problem hiding this comment.
should this be an error if the property is missing?
There was a problem hiding this comment.
no, we're updating the requirement so that property is now optional and defaults to resolving by description if not specified
| // Filter by type if provided | ||
| if len(typeOfValues) > 0 { | ||
| match := false | ||
| for _, t := range typeOfValues { |
There was a problem hiding this comment.
optional: use slices.Index
| // - output property (string) | ||
| // - typeOf filter values ([]string, from the input property filter) | ||
| // - error if validation fails | ||
| func parseResolvePropertyExpression(prop string) (string, string, []string, error) { |
There was a problem hiding this comment.
optional: add these helpers to a package for resolve (or shared util package if intended to be shared)
|
|
||
| // Parse and validate `resolver` | ||
| switch in.GetResolver() { | ||
| case ResolveResolverPlace, ResolveResolverIndicator: |
There was a problem hiding this comment.
(just curious - is the goal to eventually support resolve beyond only places? if so, maybe can make this more generic, but not needed for this pr)
There was a problem hiding this comment.
Yes, eventually we should be able to resolve anything and not need to specify the resolution type. But until then, the resolver param will support place and indicator, using place as the default for backwards compatibility.
Enabled
typeOffiltering for the indicator resolver (embeddings-based resolution).This allows clients to specify which type of entities they want to resolve to (e.g.,
StatisticalVariableorTopic) using the v2propertyfilter syntax:<-description{typeOf:StatisticalVariable}->dcidChanges
internal/server/handler_v2.gosetDefaultsAndValidateResolveInputswithparseResolvePropertyExpression.validateAndParseResolveInputsfor summary of validation logic.internal/server/handler_core.goparseResolvePropertyExpression.typeOfValuesand supplies them to the downstream methods.internal/server/v2/resolve/embeddings.goResolveUsingEmbeddings,buildResolveResponse, andbuildEntityCandidatesto accept an optionaltypeOfValueslist.buildEntityCandidatesto filter out candidates whose inferreddominantTypedoes not match any of the provided types infilterType.