Skip to content

Commit ec62ed1

Browse files
Update Gemini From 2.5 Flash to 3.0 Flash preview for website (#6145)
This PR updates the Gemini model used as 2.5 Flash will be deprecated on June 17th. We will update it to 3.0 Flash and run related NL eval test to validate the upgrade of model NL Eval result increases a slightly where a few samples are able to discover SVs compared to not able to find SVs before. No quality decrease in observed: https://docs.google.com/spreadsheets/d/1vQPAQ423MEKHpr3LCoMa_CIs7QTKEeeDjadZ3PagUHk/edit?gid=37321998#gid=37321998
1 parent 5728042 commit ec62ed1

7 files changed

Lines changed: 43 additions & 11 deletions

File tree

server/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from server.lib.disaster_dashboard import get_disaster_dashboard_data
3434
from server.lib.feature_flags import BIOMED_NL_FEATURE_FLAG
3535
from server.lib.feature_flags import DATA_OVERVIEW_FEATURE_FLAG
36+
from server.lib.feature_flags import ENABLE_GEMINI_3_FLASH
3637
from server.lib.feature_flags import ENABLE_NL_AGENT_DETECTOR
3738
from server.lib.feature_flags import is_feature_enabled
3839
import server.lib.i18n as i18n
@@ -432,8 +433,12 @@ def create_app(nl_root=DEFAULT_NL_ROOT):
432433
'palm-api-key')
433434
if is_feature_enabled(ENABLE_NL_AGENT_DETECTOR, app):
434435
os.environ['GEMINI_API_KEY'] = app.config['LLM_API_KEY']
436+
if is_feature_enabled(ENABLE_GEMINI_3_FLASH, app):
437+
default_model = "gemini-3-flash-preview"
438+
else:
439+
default_model = "gemini-2.5-flash"
435440
app.config['NL_DETECTION_AGENT'] = create_detection_agent(
436-
os.environ.get("AGENT_MODEL", "gemini-2.5-flash"),
441+
os.environ.get("AGENT_MODEL", default_model),
437442
os.environ.get("DC_MCP_URL"))
438443

439444
app.config[

server/lib/feature_flags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ENABLE_STAT_VAR_AUTOCOMPLETE = 'enable_stat_var_autocomplete'
3535
ENABLE_NL_AGENT_DETECTOR = 'enable_nl_agent_detector'
3636
NEW_RANKING_PAGE = 'new_ranking_page'
37+
ENABLE_GEMINI_3_FLASH = 'enable_gemini_3_flash'
3738
USE_V2_API = 'use_v2_api'
3839

3940

server/lib/nl/detection/llm_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
from google.genai import types
2525
import json5
2626

27+
from server.lib.feature_flags import ENABLE_GEMINI_3_FLASH
2728
from server.lib.feature_flags import is_feature_enabled
2829
from server.lib.nl.common import counters
2930

31+
_GEMINI_3_0_FLASH = 'gemini-3-flash-preview'
3032
_GEMINI_2_5_FLASH = 'gemini-2.5-flash'
31-
_API_VERSION = 'v1'
33+
_API_VERSION_3 = 'v1beta'
34+
_API_VERSION_2 = 'v1'
3235

3336
# TODO: Consider tweaking this. And maybe consider passing as url param.
3437
_TEMPERATURE = 0.1
@@ -80,14 +83,18 @@ def detect_with_gemini(query: str, history: List[List[str]],
8083
# NOTE: llm_detector.detect() caller checks this.
8184
api_key = current_app.config['LLM_API_KEY']
8285

86+
if is_feature_enabled(ENABLE_GEMINI_3_FLASH):
87+
api_version = _API_VERSION_3
88+
else:
89+
api_version = _API_VERSION_2
8390
gemini_client = genai.Client(
8491
api_key=api_key,
85-
http_options=genai.types.HttpOptions(api_version=_API_VERSION))
92+
http_options=genai.types.HttpOptions(api_version=api_version))
8693
model_name = detect_model_name()
8794
logging.info(f'Gemini model used for LLM API: {model_name}')
8895
ctr.info(
8996
'gemini_model',
90-
f'{_API_VERSION}/{model_name}',
97+
f'{api_version}/{model_name}',
9198
)
9299
gemini_response = gemini_client.models.generate_content(model=model_name,
93100
contents=text,
@@ -186,4 +193,6 @@ def _extract_answer(resp: str) -> str:
186193

187194

188195
def detect_model_name() -> str:
196+
if is_feature_enabled(ENABLE_GEMINI_3_FLASH):
197+
return _GEMINI_3_0_FLASH
189198
return _GEMINI_2_5_FLASH

server/lib/nl/explore/overview.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from pydantic import ConfigDict
2121
from pydantic.alias_generators import to_camel
2222

23+
from server.lib.feature_flags import ENABLE_GEMINI_3_FLASH
24+
from server.lib.feature_flags import is_feature_enabled
2325
from server.lib.nl.explore.gemini_prompts import PAGE_OVERVIEW_PROMPT
2426
from server.lib.utils.gemini_utils import call_gemini
2527

@@ -51,7 +53,8 @@ class PageOverview(BaseModel):
5153

5254
_OVERVIEW_GEMINI_CALL_RETRIES = 3
5355

54-
_OVERVIEW_GEMINI_MODEL = "gemini-2.5-flash-lite"
56+
_OVERVIEW_GEMINI_3_1_LITE = "gemini-3.1-flash-lite-preview"
57+
_OVERVIEW_GEMINI_2_5_LITE = "gemini-2.5-flash-lite"
5558

5659

5760
def generate_page_overview(
@@ -78,10 +81,15 @@ def generate_page_overview(
7881
formatted_page_overview_prompt = PAGE_OVERVIEW_PROMPT.format(
7982
initial_query=query, stat_var_titles=stat_var_titles)
8083

84+
if is_feature_enabled(ENABLE_GEMINI_3_FLASH):
85+
overview_gemini_model = _OVERVIEW_GEMINI_3_1_LITE
86+
else:
87+
overview_gemini_model = _OVERVIEW_GEMINI_2_5_LITE
88+
8189
page_overview = call_gemini(api_key=gemini_api_key,
8290
formatted_prompt=formatted_page_overview_prompt,
8391
schema=PageOverview,
84-
gemini_model=_OVERVIEW_GEMINI_MODEL)
92+
gemini_model=overview_gemini_model)
8593
if not page_overview:
8694
return None, None
8795

server/lib/nl/explore/related.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from flask import current_app
2222
from pydantic import BaseModel
2323

24+
from server.lib.feature_flags import ENABLE_GEMINI_3_FLASH
25+
from server.lib.feature_flags import is_feature_enabled
2426
import server.lib.nl.common.topic as topic
2527
import server.lib.nl.common.utils as utils
2628
import server.lib.nl.detection.types as dtypes
@@ -55,7 +57,9 @@ class FollowUpQuestions(BaseModel):
5557

5658

5759
_QUESTIONS_GEMINI_CALL_RETRIES = 3
58-
_QUESTIONS_GEMINI_MODEL = "gemini-2.5-flash"
60+
61+
_QUESTIONS_GEMINI_3 = "gemini-3-flash-preview"
62+
_QUESTIONS_GEMINI_2 = "gemini-2.5-flash"
5963

6064

6165
def compute_related_things(
@@ -312,11 +316,16 @@ def generate_follow_up_questions(query: str,
312316
formatted_follow_up_questions_prompt = FOLLOW_UP_QUESTIONS_PROMPT.format(
313317
initial_query=query, related_topics=related_topics)
314318

319+
if is_feature_enabled(ENABLE_GEMINI_3_FLASH):
320+
gemini_model = _QUESTIONS_GEMINI_3
321+
else:
322+
gemini_model = _QUESTIONS_GEMINI_2
323+
315324
follow_up_questions = call_gemini(
316325
api_key=gemini_api_key,
317326
formatted_prompt=formatted_follow_up_questions_prompt,
318327
schema=FollowUpQuestions,
319-
gemini_model=_QUESTIONS_GEMINI_MODEL)
328+
gemini_model=gemini_model)
320329
if not follow_up_questions:
321330
return []
322331

server/lib/utils/gemini_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
def call_gemini(
2323
api_key: str,
2424
formatted_prompt: str,
25-
schema: Optional[BaseModel] = None,
26-
gemini_model: str = "gemini-2.5-flash") -> Optional[Union[BaseModel, str]]:
25+
gemini_model: str,
26+
schema: Optional[BaseModel] = None) -> Optional[Union[BaseModel, str]]:
2727
"""A helper for all Gemini generations through the Python Gen AI client.
2828
Args:
2929
api_key: A string representing the API key required for authentication with the Gemini service.

tools/nl/nl_metadata/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
BIGQUERY_QUERY_BASE = "SELECT * FROM `datcom-store.dc_kg_latest.StatisticalVariable` WHERE name IS NOT NULL AND prov_id != \"dc/base/ExperimentalStatVars\""
3333

3434
# --- Gemini API Config ---
35-
GEMINI_MODEL = "gemini-2.5-flash"
35+
GEMINI_MODEL = "gemini-3-flash-preview"
3636
GEMINI_TEMPERATURE = 1
3737
GEMINI_TOP_P = 1
3838
GEMINI_SEED = 0

0 commit comments

Comments
 (0)