Skip to content

[cdc_services] Remove legacy nl_server and PyTorch dependencies from image - #6655

Merged
clincoln8 merged 6 commits into
datacommonsorg:masterfrom
clincoln8:remove-nl-server-cdc-services
Sep 18, 2026
Merged

clincoln8 merged 6 commits into
datacommonsorg:masterfrom
clincoln8:remove-nl-server-cdc-services

Conversation

@clincoln8

@clincoln8 clincoln8 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Overview

Cleans up the datacommons-services container by removing the deprecated nl_server and its dependencies (such as PyTorch, sentence-transformers, Spacy, and local MiniLM models). Natural language query and variable resolution are now fully handled via Cloud Spanner embeddings and Vertex AI served through Mixer's /v2/resolve endpoint.

Performance & Size Impact:

  • Build Time: Reduced container build time from ~11m 20s to ~3m 50s (~66% faster, saving over 7.5 minutes per build).
  • Image Size: Reduced compressed image footprint from ~1.03 GB down to ~458 MB (~55% reduction).

Changes

  1. build/cdc_services/Dockerfile:
  • Removed nl_server and PyTorch requirement installation steps from Stage 2 (py-servers), and added --no-cache-dir to the initial pip upgrade.
  • Removed copying nl_app.py, nl_server/, and deploy/nl/ into Stage 2.
  • Deleted Stage 4, which downloaded the local MiniLM model and embeddings CSV on every build.
  • Removed /datacommons and /tmp/datcom-nl-models copies from the final runtime stage (runner).
  1. build/cdc_services/run.sh:
  • Removed legacy environment variable exports (NL_SERVER_PORT, TOKENIZERS_PARALLELISM, OMP_NUM_THREADS, etc.).
  • Removed legacy nl_server Mixer flag injection (--embeddings_server_url, --resolve_embeddings_indexes).
  • Removed the unused nl_app.py Gunicorn startup block.

Verification & Live Testbed Deployment

  • Image Build: Built and pushed the test image using:
    ./scripts/push_cdc_services_image.sh calinc-no-nl-server datcom-website-dev
    producing gcr.io/datcom-website-dev/datacommons-services:calinc-no-nl-server.
  • Testbed Deployment: Patched this image into DCP testbed testbed-1. You can view the live deployment on the Cloud Run Service Console.
  • Reviewers can run the following commands to verify that Spanner-backed indicator resolution (resolver=indicator) and natural language query fulfillment (/api/explore/detect-and-fulfill) are functioning as intended:
# 1. Verify semantic indicator resolution via Cloud Spanner embeddings (resolver=indicator):
curl -sS -X POST \
  -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
  -H "Content-Type: application/json" \
  -d '{
    "nodes": ["population", "income"],
    "property": "<-description->dcid",
    "resolver": "indicator"
  }' \
  "https://testbed-1-dc-datacommons-service-ac2abfdi6a-uc.a.run.app/core/api/v2/resolve" \
  | jq '.entities[] | {query: .node, top_candidate: .candidates[0].dcid, score: .candidates[0].metadata.score, name: .candidates[0].name}'

# 2. Verify natural language query detection and fulfillment:
curl -sS -X POST \
  -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
  -H "Content-Type: application/json" \
  -d '{}' \
  "https://testbed-1-dc-datacommons-service-ac2abfdi6a-uc.a.run.app/api/explore/detect-and-fulfill?q=population+of+california" \
  | jq '{place: .place.name, chart_title: .config.categories[0].blocks[0].title}'

@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 streamlines the datacommons-services container by removing legacy natural language processing components that are no longer required for runtime operations. By offloading NL query resolution to modern infrastructure, the build process is simplified, unnecessary dependencies are eliminated, and the overall container footprint is reduced.

Highlights

  • Legacy Component Removal: Removed the standalone nl_server, associated Python/ML dependencies (PyTorch, sentence-transformers, Spacy), and the GCS model download stage from the container build.
  • Build Optimization: Cleaned up the Dockerfile by removing unused installation steps and copying operations, reducing the final image size and build complexity.
  • Environment Cleanup: Removed legacy environment variables and startup logic for the NL server from run.sh, as natural language resolution is now handled via Cloud Spanner and Vertex AI.
  • Docker Context Refinement: Improved build performance by adding a dedicated .dockerignore for the cdc_services build and updating the root .dockerignore to exclude unnecessary directories.
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 removes the Natural Language (NL) server, its dependencies (such as PyTorch and nl_server requirements), model downloading steps, and related configurations from the CDC services Dockerfile and startup script. It also introduces a dedicated .dockerignore file for the Docker build context. The review feedback suggests a minor optimization in the Dockerfile to use the --no-cache-dir flag when upgrading pip and setuptools to help minimize the final image size.

Comment thread build/cdc_services/Dockerfile Outdated

@shixiao-coder shixiao-coder 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.

LGTM

@clincoln8
clincoln8 merged commit fd9801d into datacommonsorg:master Sep 18, 2026
18 checks passed
@clincoln8
clincoln8 deleted the remove-nl-server-cdc-services branch September 18, 2026 17:54
@clincoln8 clincoln8 changed the title chore(build): remove legacy nl_server and PyTorch dependencies from cdc_services image [cdc_services] Remove legacy nl_server and PyTorch dependencies from image Sep 18, 2026
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