Skip to content

feat(nl): add dynamic graph fallback for un-cached topic and peer group members - #6590

Open
clincoln8 wants to merge 2 commits into
datacommonsorg:masterfrom
clincoln8:fix-dynamic-topic-fallback
Open

feat(nl): add dynamic graph fallback for un-cached topic and peer group members#6590
clincoln8 wants to merge 2 commits into
datacommonsorg:masterfrom
clincoln8:fix-dynamic-topic-fallback

Conversation

@clincoln8

Copy link
Copy Markdown
Contributor

Summary

In Data Commons Platform (DCP), custom datasets and UN topics are loaded dynamically into Spanner without generating static topic_cache.json files.

Previously, _members() in server/lib/nl/common/topic.py only checked TOPIC_CACHE. When a dynamic custom or UN topic (e.g. undata/topic/theme/S73) was queried, get_members() returned empty, causing dynamic topic traversal in Explore to terminate prematurely without charts.

Changes

  1. Fallback in _members(): When a topic is missing from TOPIC_CACHE (or returns empty), fall back to calling _prop_val_ordered(node, prop + 'List').
  2. Fallback in _members_raw() and _parents_raw(): Batch-fetch missing nodes from the graph via fetch.raw_property_values().
  3. Multi-string Parsing in _prop_val_ordered(): Iterate over all list strings in sv_list across provenances with set deduplication.
  4. Unit Tests: Added comprehensive test coverage in server/tests/lib/nl/topic_test.py.

Tested with pytest server/tests/lib/nl/topic_test.py (5 passed) and full pytest server/tests/lib/nl/ (342 passed).

@gemini-code-assist

Copy link
Copy Markdown
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 a dynamic fallback mechanism for the Data Commons Platform to handle custom and UN topics that are not present in the static TOPIC_CACHE. By enabling direct graph queries when cache lookups fail, the system ensures that dynamic topic traversal in Explore functions correctly without missing charts. Additionally, the parsing logic for ordered property values has been improved to better handle multi-string inputs.

Highlights

  • Dynamic Topic Fallback: Implemented a fallback mechanism in _members, _members_raw, and _parents_raw to fetch data directly from the graph when topics are missing from the TOPIC_CACHE.
  • Enhanced Multi-string Parsing: Updated _prop_val_ordered to handle multiple list strings across provenances with set deduplication for more robust data retrieval.
  • Comprehensive Testing: Added a new test suite in server/tests/lib/nl/topic_test.py to verify the fallback logic and parsing improvements.
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 the 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 counterproductive. 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.

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.

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

Copy link
Copy Markdown
Contributor

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 fallback mechanisms in topic.py to dynamically fetch member and parent properties when they are missing from the TOPIC_CACHE. It also updates _prop_val_ordered to properly split and deduplicate ordered property values, and adds comprehensive unit tests to verify these fallback behaviors. The review feedback suggests deduplicating the list of missing nodes before making API calls in _members_raw and _parents_raw to prevent redundant network requests.

Comment on lines +520 to +523
if missing_nodes:
raw_res = fetch.raw_property_values(nodes=missing_nodes, prop=prop)
for n in missing_nodes:
val_map[n] = raw_res.get(n, [])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To avoid redundant API calls and save network bandwidth, we should deduplicate missing_nodes before passing it to fetch.raw_property_values.

Suggested change
if missing_nodes:
raw_res = fetch.raw_property_values(nodes=missing_nodes, prop=prop)
for n in missing_nodes:
val_map[n] = raw_res.get(n, [])
if missing_nodes:
raw_res = fetch.raw_property_values(nodes=list(dict.fromkeys(missing_nodes)), prop=prop)
for n in missing_nodes:
val_map[n] = raw_res.get(n, [])

Comment on lines +541 to +544
if missing_nodes:
parents = fetch.raw_property_values(nodes=missing_nodes,
prop=prop,
out=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similarly, we should deduplicate missing_nodes here to prevent redundant API requests when fetching parent properties.

Suggested change
if missing_nodes:
parents = fetch.raw_property_values(nodes=missing_nodes,
prop=prop,
out=False)
if missing_nodes:
parents = fetch.raw_property_values(nodes=list(dict.fromkeys(missing_nodes)),
prop=prop,
out=False)

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.

1 participant