Skip to content

[/v2/resolve] Support v2 style typeOf filtering in indicator resolution#1753

Open
clincoln8 wants to merge 8 commits intodatacommonsorg:masterfrom
clincoln8:filter
Open

[/v2/resolve] Support v2 style typeOf filtering in indicator resolution#1753
clincoln8 wants to merge 8 commits intodatacommonsorg:masterfrom
clincoln8:filter

Conversation

@clincoln8
Copy link
Contributor

@clincoln8 clincoln8 commented Jan 30, 2026

Enabled typeOf filtering for the indicator resolver (embeddings-based resolution).
This allows clients to specify which type of entities they want to resolve to (e.g., StatisticalVariable or Topic) using the v2 property filter syntax: <-description{typeOf:StatisticalVariable}->dcid

Changes

internal/server/handler_v2.go

  • Replaced setDefaultsAndValidateResolveInputs with parseResolvePropertyExpression.
  • See docstring of validateAndParseResolveInputs for summary of validation logic.

internal/server/handler_core.go

  • Removed the validation and parsing logic that is now contained in parseResolvePropertyExpression.
  • Accepts the parsed values of inProp, outProp, and typeOfValues and supplies them to the downstream methods.

internal/server/v2/resolve/embeddings.go

  • Updated ResolveUsingEmbeddings, buildResolveResponse, and buildEntityCandidates to accept an optional typeOfValues list.
  • Added logic in buildEntityCandidates to filter out candidates whose inferred dominantType does not match any of the provided types in filterType.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • V2 Indicator Resolution Filtering: The v2 indicator resolution now supports typeOf filtering, allowing clients to specify desired entity types (e.g., StatisticalVariable, Topic) using the property filter syntax: <-description{typeOf:StatisticalVariable}->dcid.
  • Property Validation Updates: Strict property validation for ResolveResolverIndicator in handler_v2.go has been removed to accommodate complex property strings with filters. New validation logic has been added in handler_core.go to specifically parse and validate the <-description{typeOf:[...]}->dcid format for indicator resolution.
  • Embeddings Resolution Logic: The ResolveUsingEmbeddings function and its helpers (buildResolveResponse, buildEntityCandidates) now accept an optional filterType list. Candidates are filtered in buildEntityCandidates based on their inferred dominantType matching the provided filterType.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

@clincoln8
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

@clincoln8 clincoln8 marked this pull request as ready for review February 3, 2026 06:08
@clincoln8 clincoln8 requested a review from keyurva February 3, 2026 06:41
// - output property (string)
// - typeOf filter values ([]string, from the input property filter)
// - error if validation fails
func parseResolvePropertyExpression(prop string) (string, string, []string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@n-h-diaz - is there an existing util function that parses the property expression that can be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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!

@keyurva keyurva requested a review from n-h-diaz February 3, 2026 23:17
Copy link
Contributor

@n-h-diaz n-h-diaz left a comment

Choose a reason for hiding this comment

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

thanks for all the additional validation!

}

// Parse `property` expression into its in arc property, out arc property and typeOf filter values
if in.GetProperty() == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be an error if the property is missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

(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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants