Skip to content

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

Merged
clincoln8 merged 20 commits into
datacommonsorg:masterfrom
clincoln8:fix-dynamic-topic-fallback
Aug 20, 2026
Merged

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

Conversation

@clincoln8

@clincoln8 clincoln8 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

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

Previously:

  1. _members() in server/lib/nl/common/topic.py only checked TOPIC_CACHE. When a dynamic custom topic was queried, get_members() returned empty, terminating topic traversal.
  2. Helper functions (is_topic, is_svg, is_svpg, is_sv) relied on hardcoded dc/topic/ or c/topic/ string prefixes. Custom topic DCIDs (e.g. custom/topic/DisplacedPersons or UN topics) were misclassified as raw Statistical Variables, bypassing _topic_chart_vars() and failing observation existence checks.

Changes

  1. Dynamic Graph Fallback in topic.py:
    • When a node is missing from TOPIC_CACHE (or returns empty), falls back to calling _prop_val_ordered(node, prop + 'List') to retrieve relevantVariableList / memberList from Cloud Spanner / Mixer.
    • Batch-fetches missing nodes in _members_raw() and _parents_raw() via fetch.raw_property_values().
    • Iterates over all list strings in sv_list across provenances with set deduplication in _prop_val_ordered().
  2. Schema-Driven Candidate Type Capture:
    • Extended VarCandidates in shared/lib/detected_variables.py with sv2types to capture typeOf and types metadata returned from /v2/resolve.
    • Propagated sv2types through Utterance to explore fulfillment.
  3. Schema-Driven Classification & Feature Flag Safety:
    • Added enable_schema_driven_topic_resolution feature flag (defaults to false in production.json for Base DC safety; auto-enabled on DCP container startup via update_dcp_flags.py).
    • Updated is_topic, is_svg, is_svpg, and is_sv to check sv2types and generalized /topic/, /svg/, and /svpg/ namespace patterns when the flag is enabled.
    • Updated explore/topic.py to route custom topics to _topic_chart_vars().
  4. Display Name Fallback:
    • Updated get_sv_name() to strip namespace prefixes (re.sub(r'^[^/]+/(topic|svpg|g)/', '', sv)) for uncurated custom topics.
  5. Unit Tests:
    • Added unit tests in server/tests/lib/nl/topic_test.py covering fallback traversal, schema-driven classification, flag toggling, and serialization roundtrips.

Testing

  • uv run --project server --group test python3 -m pytest server/tests/lib/nl/ (all 349 passed).
  • Verified live end-to-end on calinc-dev with image calinc-topics-03.

@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 thread server/lib/nl/common/topic.py Outdated
Comment thread server/lib/nl/common/topic.py Outdated
@clincoln8
clincoln8 force-pushed the fix-dynamic-topic-fallback branch from ac43e29 to bc990f5 Compare August 18, 2026 19:14
shixiao-coder and others added 4 commits August 18, 2026 19:59
…od following the flag for other env setup (datacommonsorg#6548)

This PR add the feature flag in prod environment and default to false

When false, we will read default value 0.7 from the code,
When true, we will set config value to be 0.6 based on test result
https://docs.google.com/spreadsheets/d/12d9BPJagWS5z2WA8En9JY71TyGrCYpIBQ4LqI0JJ2v4/edit?gid=1132426848#gid=1132426848
The gemini 3 feature flag was use when we roll up from 2.5 to 3, it's no
longer needed, all non prod env has removed this feature flag
…6593)

## Description

The README.md in `server/routes/redirects/README.md` that describes how
to update redirect mapping is incorrect/out-of-date.

While the description of how to update the mapping (via the `gcloud
storage cp`) is correct, the description of when those changes are
picked up by production is not.

The file states that production reads this redirect mapping on each
redirection call, resulting in the immediate pickup of these changes.
This is incorrect. The bucket is read when the Flask server starts (in
`__init__.py`).

This PR updates the README.md to correct the description.
@clincoln8
clincoln8 requested a review from a team as a code owner August 19, 2026 03:00
@datacommonsorg datacommonsorg deleted a comment from github-actions Bot Aug 19, 2026
@clincoln8
clincoln8 removed the request for review from a team August 19, 2026 18:23
@clincoln8
clincoln8 requested a review from gmechali August 19, 2026 22:18

@gmechali gmechali 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.

Thanks Christie for threading this needle, can't imagine how delicate and annoying this must have been, and to do it on such a short timeline 👏

Adding this code now will bring in some more urgency on cleaning this up for Base DC website longer term. Hopefully post dcp public preview we can take this back to attention because it looks really really brittle throughout. :(

Comment thread build/cdc_services/update_dcp_flags.py Outdated
@clincoln8
clincoln8 enabled auto-merge (squash) August 20, 2026 17:44
@clincoln8
clincoln8 merged commit 6fa4ed3 into datacommonsorg:master Aug 20, 2026
16 of 18 checks passed
@clincoln8
clincoln8 deleted the fix-dynamic-topic-fallback branch August 20, 2026 18:20
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.

4 participants