Skip to content

feat: Support description-to-DCID resolution for Spanner backend#1799

Merged
SandeepTuniki merged 10 commits intomasterfrom
feature/v3-resolve-description
Mar 13, 2026
Merged

feat: Support description-to-DCID resolution for Spanner backend#1799
SandeepTuniki merged 10 commits intomasterfrom
feature/v3-resolve-description

Conversation

@SandeepTuniki
Copy link
Contributor

@SandeepTuniki SandeepTuniki commented Mar 10, 2026

This PR implements description-based entity resolution for the V3 Spanner data source (see b/477664860).

Changes:

  • V3 Implementation: Updated SpannerDataSource to support the <-description->dcid arc.
  • Decoupled the entity recognition logic in the recon package from the Bigtable backend, so that the shared resolution process (In-memory -> Maps API -> Storage) can be used by both V2 and V3 paths.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 introduces the capability for description-based entity resolution within the V3 Spanner data source. It integrates existing place recognition logic with the Spanner data source, allowing entities to be resolved by their textual descriptions, optionally filtered by type. This significantly enhances the flexibility and power of the V3 API by enabling more natural language-like queries for entities. The changes involve refactoring dependency injection for Spanner components and adapting resolution functions to work seamlessly with the new data source structure.

Highlights

  • V3 Description-Based Entity Resolution: Implemented description-based entity resolution for V3 Spanner data sources, allowing entities to be resolved by their textual descriptions, optionally filtered by type.
  • Spanner Data Source Refactoring: Refactored Spanner client and data source initialization to correctly pass RecogPlaceStore and MapsClient dependencies, ensuring proper integration of recognition logic.
  • Recon Package Updates: Updated recon package functions (resolveDCIDs, resolveWithRecognizePlaces, resolveWithMapsAPI) to use a dedicated RecogPlaceStore and introduced new function types for flexible DCID resolution, enhancing modularity and testability.
  • Dependency Injection Improvements: Modified SpannerDataSource to incorporate RecogPlaceStore and MapsClient for handling description-based resolution requests, and adjusted the RecognizePlaces handler to directly use the RecogPlaceStore.
Changelog
  • cmd/main.go
    • Declared spannerClient outside the if block to extend its scope.
    • Removed immediate SpannerDataSource creation and appending to sources.
    • Added initialization of SpannerDataSource after other dependencies are ready, passing RecogPlaceStore and mapsClient.
  • internal/server/handler_v1.go
    • Updated RecognizePlaces to use s.store.RecogPlaceStore instead of s.store.
  • internal/server/recon/find_entities.go
    • Imported github.com/datacommonsorg/mixer/internal/store/files.
    • Renamed entityInfo struct to EntityInfo and capitalized its fields (description to Description, typeOf to TypeOf).
    • Introduced PlaceIdToDcidFunc and GetPlaceTypesFunc type definitions.
    • Modified BulkFindEntities to use the new EntityInfo struct and adapted calls to ResolveDCIDs and getPlaceTypes with new function parameters.
    • Renamed resolveDCIDs to ResolveDCIDs and updated its signature to accept recogPlaceStore and placeIdToDcidFunc.
    • Updated resolveWithRecognizePlaces to accept recogPlaceStore directly.
    • Updated resolveWithMapsAPI to accept placeIdToDcidFunc directly.
    • Adjusted various function parameters and return types to use EntityInfo instead of entityInfo.
  • internal/server/recon/recognize.go
    • Updated RecognizePlaces function signature to accept *files.RecogPlaceStore directly instead of *store.Store.
    • Modified the placeRecognition struct initialization to use the directly passed recogPlaceStore.
  • internal/server/spanner/datasource.go
    • Imported sort, internalmaps, recon, files, and util packages.
    • Added recogPlaceStore and mapsClient fields to SpannerDataSource struct.
    • Updated NewSpannerDataSource constructor to accept recogPlaceStore and mapsClient.
    • Implemented description-based resolution logic in the Resolve method for <-description->dcid arcs, utilizing recon.ResolveDCIDs and Spanner's ResolveByID and GetNodeEdgesByID for type filtering.
  • internal/server/spanner/golden/datasource_test.go
    • Updated NewSpannerDataSource calls in tests to pass nil for the newly added recogPlaceStore and mapsClient parameters.
  • test/setup.go
    • Declared spannerClient outside the if block.
    • Removed SpannerDataSource creation and appending from the initial Spanner client setup.
    • Moved SpannerDataSource creation to after the store is initialized, allowing st.RecogPlaceStore to be passed as a dependency.
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

The pull request refactors the Spanner data source integration and entity recognition logic. Key changes include moving the initialization of SpannerDataSource to a later stage in cmd/main.go and test/setup.go to ensure dependencies like RecogPlaceStore and MapsClient are ready. The SpannerDataSource now directly accepts RecogPlaceStore and MapsClient as dependencies, and its Resolve method has been implemented to handle text-based entity resolution using these new dependencies, including type filtering. The entity recognition (recon) package was updated to use a new EntityInfo struct with exported fields, and its resolveDCIDs function was renamed to ResolveDCIDs and refactored to accept RecogPlaceStore and a PlaceIdToDcidFunc for better modularity. Review comments highlight a potential panic in test/setup.go due to passing nil for mapsClient where it's later used, suggesting mapsClient should be initialized earlier. Additionally, there are suggestions to improve efficiency by refactoring resolveDCIDsFromPlaceIDs to avoid unnecessary data conversions, to enhance readability by removing an unnecessary wrapper function getPlaceTypesFunc, and to simplify redundant filtering logic in internal/server/spanner/datasource.go.

@SandeepTuniki
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 implements description-to-DCID resolution for the v3 API using the Spanner data source, featuring a significant refactoring of the entity resolution logic for improved testability and extensibility. However, a potential Denial of Service (DoS) vulnerability was identified due to a missing nil check on the Maps client, which should be handled gracefully by returning an error rather than panicking, aligning with repository guidelines. Furthermore, a significant logic bug related to Go loop variable pointers was found in the reconnaissance logic, which could lead to incorrect data in bulk requests.

@SandeepTuniki
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 implements description resolution for the v3 API using Spanner. It includes a significant refactoring of the entity resolution logic in internal/server/recon/find_entities.go to make it more generic and reusable by decoupling it from the underlying data store. The changes are well-structured and include a fix for a common Go concurrency issue. My feedback includes a suggestion to further improve the API design for better efficiency.

@SandeepTuniki SandeepTuniki changed the title Feature/v3 resolve description feat: Support description-to-DCID resolution for Spanner backend Mar 10, 2026
@SandeepTuniki
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 implements description-based entity resolution for the Spanner backend and refactors the entity recognition logic to be backend-agnostic. The changes look good overall. The decoupling of the recon package by introducing function types for backend-specific operations is a solid approach. I've left one comment regarding potential code duplication in the type-filtering logic, which could be further abstracted to improve maintainability.

@SandeepTuniki SandeepTuniki marked this pull request as ready for review March 10, 2026 11:03
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! :)

Can be follow up (especially since spanner is currently down T_T) but could you also an e2e test https://github.com/datacommonsorg/mixer/blob/81b8f27652b1450c1dc7d65f5de84e5e6b1fdec0/internal/server/v3/resolve/golden/resolve_test.go

@SandeepTuniki SandeepTuniki added this pull request to the merge queue Mar 13, 2026
Merged via the queue into master with commit 2c9ad2a Mar 13, 2026
9 checks passed
@SandeepTuniki SandeepTuniki deleted the feature/v3-resolve-description branch March 13, 2026 04:14
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.

2 participants