Skip to content

Using the ChatVertexAI class, even when informing the thinking_budget attribute, the thoughts are not being received with the response #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
luisfelippe opened this issue May 9, 2025 · 7 comments

Comments

@luisfelippe
Copy link

Using the ChatVertexAI class, even when informing the thinking_budget attribute, the thoughts are not being received with the response. Perhaps the include_thoughts attribute is missing in ThinkingConfig, or even considered in the response parse.

@windkit
Copy link
Contributor

windkit commented May 9, 2025

@luisfelippe note that currently thoughts are not returned in the response even when include_thoughts = True

related discussion at https://discuss.ai.google.dev/t/thoughts-are-missing-cot-not-included-anymore/63653/14

@luisfelippe
Copy link
Author

@windkit I understand, but if you look at the link you sent, it is about Gemini 2.0, but the Gemini 2.5 flash model returns.

I am using the code below and I am receiving the thinking block.

client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION
)

responses = client.models.generate_content_stream(
model=MODEL_ID,
contents="How might quantum sensors improve the precision of measurements in fields like materials science or navigation?",
config=GenerateContentConfig(
thinking_config=ThinkingConfig(
thinking_budget=THINKING_BUDGET,
include_thoughts=INCLUDE_THOUGHTS,
)
),
)

first_thought = True
first_answer = True

for response in responses:
for part in response.candidates[0].content.parts:
if part.thought and first_thought:
first_thought = False
print("\n--- Raciocínio ---\n")
elif not part.thought and first_answer:
first_answer = False
print("\n--- Resposta ---\n")
print(part.text, end="")

@windkit
Copy link
Contributor

windkit commented May 9, 2025

which model are you testing with? I have just tried both gemini-2.5-flash-preview-04-17 and gemini-2.5-pro-preview-05-06 but thoughts were not returned with the code

@luisfelippe
Copy link
Author

luisfelippe commented May 9, 2025

@windkit I'm testting using gemini-2.5-flash-preview-04-17 model. It is extremely important to declare include_thoughts as true, because if you do not include it, the thoughts will not be returned.

This is the print generated with the code I provided:

--- Raciocínio ---

Assessing the Question's Scope

I need to understand the "how" of quantum sensors impacting "materials science" and "navigation", as per the query. So, I'm breaking down the prompt. This means outlining what quantum sensors are, the principles behind their accuracy, and the use of examples.

Dissecting the Inquiry's Core

I'm taking the query apart. It's materials science and navigation, precision improvement, and quantum sensors. The plan: definitions, principles, applications, examples, and benefits. I'll need to quickly define what the quantum sensors are, and touch on their super sensitivity.

Examining the Core Concepts

Right, I need to define quantum sensors, explain the principles of high precision (quantum effects like superposition), then how that applies to the query's fields: materials science and navigation. That means examples are key. I'll have to touch on what quantum sensors can measure.

Revisiting the Approach

Alright, I need to refine the plan. The prompt wants to focus on the application of quantum sensors. I'm going back to the key question, and then listing the benefits and concrete examples. The use cases are key.

Outlining the Quantum Approach

Right, I need to break down the specifics of how quantum sensors benefit both materials science and navigation, like the query specifies. The core idea is to explore why quantum sensors are precise: principles, examples, and applications. I'll look at each domain to outline the sensors and benefits.

Confirming Key Aspects

I'm reviewing the requirements, and ensuring I touch on all the specifics requested: quantum sensor principles, materials science and navigation applications with examples, and the benefits as outlined in the query. Time to focus on the core definitions.

Mapping the Plan of Action

Right, I need to break down the query. I must define quantum sensors and their principles, then illustrate how materials science and navigation benefit, with examples. It's all about precision: defining the quantum sensors and the underlying principles.

Clarifying Precision Focus

The core query is how quantum sensors make materials science and navigation more precise. Considering the prompt, I'm breaking down each area, and then addressing quantum principles. I need to focus on explaining why these sensors are better.

--- Resposta ---

Okay, let's break down how quantum sensors achieve enhanced precision and how this translates into improvements in materials science and navigation.

The fundamental advantage of quantum sensors lies in their ability to leverage quantum mechanical properties – such as superposition, entanglement, and interference – to achieve levels of sensitivity and stability far beyond their classical counterparts. They are often designed to probe and measure physical quantities (like magnetic fields, electric fields, temperature, rotation, acceleration, gravity, or time) with exquisite detail by observing how these quantities affect the quantum state of a system (like a single atom, trapped ion, or defect in a crystal).

Here's how this leads to improved precision and its impact:

The Source of Enhanced Precision in Quantum Sensors:

  1. Intrinsic Sensitivity to Perturbations: Quantum states, particularly energy levels in atoms or spins in defects, are incredibly stable and well-defined. Tiny external influences (like a weak magnetic field or a slight change in temperature) can cause measurable shifts in these energy levels or changes in quantum coherence. The sensor is designed to detect these minute shifts with high fidelity.
  2. Interferometry: Many quantum sensors (especially for rotation, acceleration, and gravity) use atom interferometry. This leverages the wave nature of matter. Quantum waves are split, travel along different paths (where they are affected by the quantity being measured, e.g., rotation affects their path length difference), and then recombined. The interference pattern created is extremely sensitive to phase shifts induced by the external field, amplifying tiny effects into easily measurable signals.
  3. Reduced Noise: Quantum measurement techniques can often operate close to the fundamental limits imposed by quantum mechanics (like the standard quantum limit). Techniques involving entanglement can potentially even surpass these limits (reaching the Heisenberg limit), effectively reducing measurement noise below what is possible with classical methods.
  4. Coherence Time: The ability to maintain a quantum system in a superposition or entangled state for longer periods (long coherence times) allows for longer measurement times, which in turn improves the signal-to-noise ratio and thus precision.
  5. Quantum Readout: The methods used to read out the state of the quantum system (often involving fluorescence or electron spin resonance) can be highly efficient and precise.

Impact on Precision in Materials Science:

In materials science, precision often means measuring properties with high spatial resolution, high sensitivity to weak signals, or under specific conditions. Quantum sensors excel here:

  1. High-Resolution Magnetic & Electric Field Mapping:

    • How: Sensors like Nitrogen-Vacancy (NV) centers in diamond can measure magnetic and electric fields with nanometer-scale resolution. The spin state of the NV center is sensitive to local fields and can be read out optically. Atomic magnetometers can measure incredibly weak magnetic fields over larger areas.
    • Improvement: Classical magnetic field sensors (like Hall sensors) have limitations in sensitivity and spatial resolution. Quantum sensors allow researchers to:
      • Image magnetic domain walls and study spin dynamics at the nanoscale.
      • Detect tiny magnetic anomalies caused by defects, dislocations, or strain in materials.
      • Study superconductivity and the behavior of flux lines with unprecedented detail.
      • Map current flow in complex microcircuits or novel electronic materials non-invasively.
    • Precision Aspect: Higher spatial resolution, ability to detect weaker fields, ability to measure under various conditions (temperature, pressure).
  2. Precise Temperature Sensing at the Nanoscale:

    • How: The energy levels of quantum systems like NV centers or trapped ions can be sensitive to temperature. By measuring changes in their optical or spin properties, the local temperature can be determined.
    • Improvement: Provides thermal mapping with nanoscale spatial resolution, which is challenging with classical thermometers.
    • Precision Aspect: High spatial resolution, potentially higher temperature sensitivity in specific ranges.
  3. Strain and Stress Measurement:

    • How: Strain can alter the local electric or magnetic fields within a material, which can then be detected by sensitive quantum sensors embedded in or placed near the material.
    • Improvement: Allows for mapping strain fields at small scales, crucial for understanding mechanical properties, failure mechanisms, and material reliability.
    • Precision Aspect: High spatial resolution mapping of strain.

Impact on Precision in Navigation:

Navigation traditionally relies on external signals (like GPS) or internal dead reckoning using inertial navigation systems (INS) composed of classical accelerometers and gyroscopes. Quantum sensors offer significant precision improvements, particularly for INS:

  1. Ultra-Precise Accelerometers:

    • How: Quantum accelerometers often use atom interferometry. Cold atoms are dropped or launched, and their acceleration is measured by observing the phase shift in their matter waves due to inertia.
    • Improvement: Classical accelerometers (like MEMS) suffer from drift over time – small errors accumulate into large position errors. Quantum accelerometers have the potential for orders of magnitude lower drift.
    • Precision Aspect: Much lower noise floor, greater stability, leading to significantly reduced long-term drift in integrated velocity and position.
  2. Ultra-Precise Gyroscopes:

    • How: Quantum gyroscopes (often based on atom interferometry or nuclear magnetic resonance) measure rotation by detecting the Sagnac effect – a phase shift in matter waves or spins due to rotation.
    • Improvement: Similar to accelerometers, classical gyros (even high-end fiber optic or ring laser gyros) also suffer from drift. Quantum gyros promise vastly improved stability and lower drift rates.
    • Precision Aspect: Reduced angular rate noise and bias drift, leading to far more accurate determination of orientation and greatly reducing positional errors accumulated from integrating velocity changes over time.
  3. High-Precision Gravimeters:

    • How: Quantum gravimeters measure the local gravitational acceleration by observing the acceleration of cold atoms falling in the gravitational field using atom interferometry.
    • Improvement: These are extremely sensitive to tiny variations in the gravitational field caused by different densities of material underground. While not a direct navigation sensor like accelerometers/gyros, a highly precise gravimeter combined with a detailed gravity map could potentially be used for passive, unjammable navigation (matching the measured gravity profile to the map to determine location).
    • Precision Aspect: Ability to measure minute variations in the local gravity field.

Overall Benefit in Navigation:

  • Reduced Reliance on GPS: Quantum-enhanced INS can maintain high accuracy for much longer periods without needing updates from GPS, making navigation possible and reliable in GPS-denied environments (indoors, underwater, underground, or during jamming/spoofing).
  • Increased Robustness: Internal navigation is inherently more secure and less susceptible to external interference than systems relying solely on external signals.

In summary, quantum sensors harness the fundamental principles of quantum mechanics to create measurement devices with unprecedented sensitivity, resolution, and stability. This enhanced precision allows materials scientists to probe material properties at scales and with sensitivities previously impossible and enables navigation systems that are significantly more accurate, stable, and resilient, especially in challenging environments.

@windkit
Copy link
Contributor

windkit commented May 9, 2025

@luisfelippe thanks for the example, I will check and add the support.

@windkit
Copy link
Contributor

windkit commented May 9, 2025

@luisfelippe
Copy link
Author

@windkit Yes, I even got this error when changing the ChatVertexAI and _VertexAICommon classes. Using the native, according to the code I provided, the ThinkingConfig class used is being imported from google.genai.types. Here is the complete code:

from google import genai
from google.genai.types import (
    FunctionDeclaration,
    GenerateContentConfig,
    GoogleSearch,
    HarmBlockThreshold,
    HarmCategory,
    Part,
    SafetySetting,
    ThinkingConfig,
    Tool,
    ToolCodeExecution,
)

models = {
"Gemini 2.5 Flash": {
        "model_type": "LLM",
        "deployment_name": "gemini-2.5-flash-preview-04-17",
        "version": "",
        "max_tokens": 1048576,
        "max_words": 680000,
        "max_tokens_out": 65535,
        "max_reasoning_tokens": 4096,
        "icon": "icon-ia-gemini",
        "description": "Bom para codificações e prompts complexos",
        "tiktoken_modelo": "",
        "tiktoken_encodding": "",
        "fornecedora": "VERTEXAI",
        "regiao": None,
        "stream_support": True,
        "reasoning": True,
        "disponivel": False,
        "is_beta": False,
        "inputs": {"text": True, "image": True, "audio": True, "video": True},
        "outputs": {"text": True, "image": False, "audio": False, "video": False},
    },
}

model = models["Gemini 2.5 Flash"]

PROJECT_ID = "PROJECT_ID"
LOCATION = "us-central1"

MODEL_ID = model['deployment_name'] # "gemini-2.5-flash-preview-04-17"
THINKING_BUDGET = model["max_reasoning_tokens"]
INCLUDE_THOUGHTS = True

client = genai.Client(
    vertexai=True,
    project=PROJECT_ID,
    location=LOCATION
)

responses = client.models.generate_content_stream(
    model=MODEL_ID,
    contents="How might quantum sensors improve the precision of measurements in fields like materials science or navigation?",
    config=GenerateContentConfig(
        thinking_config=ThinkingConfig(
            thinking_budget=THINKING_BUDGET,
            include_thoughts=INCLUDE_THOUGHTS,
        )
    ),
)

first_thought = True
first_answer = True

for response in responses:
    for part in response.candidates[0].content.parts:
        if part.thought and first_thought:
            first_thought = False
            print("\n--- Raciocínio ---\n")
        elif not part.thought and first_answer:
            first_answer = False
            print("\n--- Resposta ---\n")
        print(part.text, end="")

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

No branches or pull requests

2 participants