Google Search के आधार पर जानकारी देना

Google Search के साथ ग्राउंडिंग करने की सुविधा, Gemini मॉडल को रीयल-टाइम में उपलब्ध, सार्वजनिक तौर पर उपलब्ध वेब कॉन्टेंट से कनेक्ट करती है. इससे मॉडल को ज़्यादा सटीक और अप-टू-डेट जवाब देने में मदद मिलती है. साथ ही, यह पुष्टि किए जा सकने वाले ऐसे सोर्स के उद्धरण दे सकता है जिनके बारे में उसे जानकारी नहीं है.

Google Search से मिली जानकारी का इस्तेमाल करने से ये फ़ायदे मिलते हैं:

  • तथ्यों के सही होने की संभावना बढ़ाना: मॉडल के भ्रम को कम करने के लिए, जवाबों को असल दुनिया की जानकारी पर आधारित करें.
  • रीयल-टाइम में जानकारी ऐक्सेस करना: हाल ही के इवेंट और विषयों के बारे में सवालों के जवाब पाना.
  • उद्धरण दें: मॉडल के दावों के सोर्स दिखाकर, उपयोगकर्ताओं का भरोसा जीतें या उन्हें काम की साइटें ब्राउज़ करने की अनुमति दें.
  • ज़्यादा मुश्किल टास्क पूरे करना: आर्टफ़ैक्ट और काम की इमेज, वीडियो या अन्य मीडिया को वापस पाना, ताकि तर्क से जुड़े टास्क पूरे करने में मदद मिल सके.
  • किसी क्षेत्र या भाषा के हिसाब से जवाबों को बेहतर बनाना: किसी क्षेत्र के हिसाब से जानकारी ढूंढना या कॉन्टेंट का सटीक अनुवाद करने में मदद करना.

ध्यान दें कि Google Search के लिए, भरोसेमंद स्रोतों से जानकारी पाने की सुविधा iOS+, Android, और वेब पर उपलब्ध है. यह सुविधा, Flutter और Unity के आने वाले वर्शन में उपलब्ध होगी.

इन मॉडल के साथ काम करता है

  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.5-flash-lite-preview-06-17
  • gemini-2.0-flash-001 (और इसका अपने-आप अपडेट होने वाला उपनाम gemini-2.0-flash)
  • gemini-2.0-flash-live-preview-04-09

यह सुविधा इन भाषाओं में काम करती है

Gemini मॉडल के लिए, इस्तेमाल की जा सकने वाली भाषाएं देखें.

Google Search की मदद से मॉडल को जानकारी देना

इस पेज पर, Gemini API उपलब्ध कराने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, उस कंपनी पर क्लिक करें.

GenerativeModel इंस्टेंस बनाते समय, GoogleSearch को tool के तौर पर उपलब्ध कराएं, ताकि मॉडल इसका इस्तेमाल करके जवाब जनरेट कर सके.

Swift


import FirebaseAI

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(
    modelName: "GEMINI_MODEL_NAME",
    // Provide Google Search as a tool that the model can use to generate its response
    tools: [Tool.googleSearch()]
)

let response = try await model.generateContent("Who won the euro 2024?")
print(response.text ?? "No text in response.")

// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result

Kotlin


// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
    modelName = "GEMINI_MODEL_NAME",
    // Provide Google Search as a tool that the model can use to generate its response
    tools = listOf(Tool.GoogleSearch())
)

val response = model.generateContent("Who won the euro 2024?")
print(response.text)

// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result

Java


// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel("GEMINI_MODEL_NAME",
                        null,
                        null,
                        // Provide Google Search as a tool that the model can use to generate its response
                        List.of(Tool.GoogleSearch()));

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

ListenableFuture response = model.generateContent("Who won the euro 2024?");
  Futures.addCallback(response, new FutureCallback() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
          String resultText = result.getText();
          System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
          t.printStackTrace();
      }
  }, executor);

// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(
  ai,
  {
    model: "GEMINI_MODEL_NAME",
    // Provide Google Search as a tool that the model can use to generate its response
    tools: [{ googleSearch: {} }]
  }
);

const result = await model.generateContent("Who won the euro 2024?");

console.log(result.response.text());

// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result

Dart

Flutter के लिए सहायता, इसकी अगली रिलीज़ में उपलब्ध होगी.

Unity

Unity के साथ काम करने की सुविधा, इसके अगले वर्शन में उपलब्ध होगी.

अपने इस्तेमाल के उदाहरण और ऐप्लिकेशन के लिए, सही मॉडल चुनने का तरीका जानें.

बेहतर नतीजों के लिए, 1.0 का इस्तेमाल करें. यह सभी 2.5 मॉडल के लिए डिफ़ॉल्ट रूप से सेट होता है. मॉडल के कॉन्फ़िगरेशन में जाकर, टेंपरेचर सेट करने का तरीका जानें.

Google Search की मदद से जवाब पाने की सुविधा कैसे काम करती है

GoogleSearch टूल का इस्तेमाल करने पर, मॉडल अपने-आप जानकारी खोजता है, उसे प्रोसेस करता है, और उसका हवाला देता है.

मॉडल का वर्कफ़्लो यहां दिया गया है:

  1. प्रॉम्प्ट पाना: आपका ऐप्लिकेशन, GoogleSearch टूल चालू करके Gemini मॉडल को प्रॉम्प्ट भेजता है.
  2. प्रॉम्प्ट का विश्लेषण करना: मॉडल, प्रॉम्प्ट का विश्लेषण करता है और यह तय करता है कि क्या Google Search अपने जवाब को बेहतर बना सकता है.
  3. Google Search को क्वेरी भेजना: अगर ज़रूरत होती है, तो मॉडल अपने-आप एक या उससे ज़्यादा सर्च क्वेरी जनरेट करता है और उन्हें पूरा करता है.
  4. खोज के नतीजों को प्रोसेस करना: मॉडल, Google Search के नतीजों को प्रोसेस करता है और ओरिजनल प्रॉम्प्ट के लिए जवाब तैयार करता है.
  5. "भरोसेमंद जवाब" देना: मॉडल, Google Search के नतीजों के आधार पर, उपयोगकर्ता के लिए फ़ायदेमंद और सटीक जवाब देता है. इस जवाब में, मॉडल का टेक्स्ट वाला जवाब और groundingMetadata शामिल है. इसमें खोज क्वेरी, वेब नतीजे, और उद्धरण शामिल हैं.

ध्यान दें कि मॉडल को Google Search का ऐक्सेस देने का मतलब यह नहीं है कि मॉडल को जवाब जनरेट करने के लिए हमेशा Google Search का इस्तेमाल करना होगा. इन मामलों में, जवाब में groundingMetadata ऑब्जेक्ट शामिल नहीं होगा. इसलिए, यह "भरोसेमंद जवाब" नहीं है.

इस डायग्राम में दिखाया गया है कि Google Search के साथ ग्राउंडिंग करने के लिए, मॉडल Google Search के साथ कैसे इंटरैक्ट करता है

भरोसेमंद स्रोतों से मिली जानकारी के आधार पर तैयार किए गए जवाब को समझना

अगर मॉडल, Google Search के नतीजों के आधार पर जवाब देता है, तो जवाब में groundingMetadata ऑब्जेक्ट शामिल होता है. इसमें स्ट्रक्चर्ड डेटा होता है. यह डेटा, दावों की पुष्टि करने और आपके ऐप्लिकेशन में उद्धरणों को बेहतर तरीके से दिखाने के लिए ज़रूरी होता है.

"भरोसेमंद सोर्स से मिले जवाब" में मौजूद groundingMetadata ऑब्जेक्ट में यह जानकारी शामिल होती है:

यहां जवाब का एक उदाहरण दिया गया है, जिसमें groundingMetadata ऑब्जेक्ट शामिल है:

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Spain won Euro 2024, defeating England 2-1 in the final. This victory marks Spain's record fourth European Championship title."
          }
        ],
        "role": "model"
      },
      "groundingMetadata": {
        "webSearchQueries": [
          "UEFA Euro 2024 winner",
          "who won euro 2024"
        ],
        "searchEntryPoint": {
          "renderedContent": "<!-- HTML and CSS for the search widget -->"
        },
        "groundingChunks": [
          {"web": {"uri": "https://vertexaisearch.cloud.google.com.....", "title": "aljazeera.com"}},
          {"web": {"uri": "https://vertexaisearch.cloud.google.com.....", "title": "uefa.com"}}
        ],
        "groundingSupports": [
          {
            "segment": {"startIndex": 0, "endIndex": 85, "text": "Spain won Euro 2024, defeatin..."},
            "groundingChunkIndices": [0]
          },
          {
            "segment": {"startIndex": 86, "endIndex": 210, "text": "This victory marks Spain's..."},
            "groundingChunkIndices": [0, 1]
          }
        ]
      }
    }
  ]
}

भरोसेमंद सोर्स से मिली जानकारी का इस्तेमाल करना और उसे दिखाना

अगर मॉडल, जवाब जनरेट करने के लिए Google Search टूल का इस्तेमाल करता है, तो वह जवाब में groundingMetadata ऑब्जेक्ट देगा.

Google Search के सुझाव दिखाने के लिए, इस प्रॉपर्टी को शामिल करना ज़रूरी है. साथ ही, उद्धरण दिखाने के लिए, इसे शामिल करने का सुझाव दिया जाता है.

Google Search टूल का इस्तेमाल करने की ज़रूरी शर्तों का पालन करने के अलावा, इस जानकारी को दिखाने से आपको और आपके उपयोगकर्ताओं को जवाबों की पुष्टि करने में मदद मिलती है. साथ ही, इससे आगे और सीखने के अवसर मिलते हैं.

(ज़रूरी है) Google Search के सुझाव दिखाएं

अगर किसी जवाब में "Google Search के सुझाव" शामिल हैं, तो आपको "Google Search से मिली जानकारी का इस्तेमाल करना" से जुड़ी ज़रूरी शर्तों का पालन करना होगा. इनमें यह भी शामिल है कि आपको Google Search के सुझाव किस तरह दिखाने हैं.

groundingMetadata ऑब्जेक्ट में "Google Search के सुझाव" शामिल होते हैं. खास तौर पर, searchEntryPoint फ़ील्ड में renderedContent फ़ील्ड होता है. इसमें नीति के मुताबिक एचटीएमएल और सीएसएस स्टाइलिंग होती है. आपको इसे लागू करना होगा, ताकि आपके ऐप्लिकेशन में Search के सुझाव दिख सकें.

Google Cloud दस्तावेज़ में, Google Search पर सुझाव दिखाने और उनके काम करने से जुड़ी ज़रूरी शर्तों के बारे में ज़्यादा जानकारी देखें. ध्यान दें कि इस बारे में पूरी जानकारी Vertex AI Gemini API के दस्तावेज़ में दी गई है. हालांकि, यह जानकारी Gemini Developer API की सेवा देने वाली कंपनी पर भी लागू होती है.

इस सेक्शन में बाद में, कोड सैंपल के उदाहरण देखें.

(सुझाया गया) उद्धरण दिखाएं

groundingMetadata ऑब्जेक्ट में, उद्धरण का स्ट्रक्चर्ड डेटा होता है. खास तौर पर, groundingSupports और groundingChunks फ़ील्ड. इस जानकारी का इस्तेमाल करके, मॉडल के जवाबों को सीधे तौर पर अपने यूज़र इंटरफ़ेस (यूआई) में मौजूद सोर्स से लिंक करें. ऐसा इनलाइन और एग्रीगेट किए गए फ़ॉर्म में किया जा सकता है.

इस सेक्शन में बाद में, कोड सैंपल के उदाहरण देखें.

कोड सैंपल के उदाहरण

इन कोड सैंपल में, भरोसेमंद स्रोतों से मिली जानकारी के आधार पर जवाब जनरेट करने की सुविधा का इस्तेमाल करने और जवाब दिखाने के लिए, सामान्य पैटर्न दिए गए हैं. हालांकि, यह पक्का करना आपकी ज़िम्मेदारी है कि आपकी खास ज़रूरत के हिसाब से लागू किया गया तरीका, कानूनी समझौते की शर्तों के मुताबिक हो.

Swift

// ...

// Get the model's response
let text = response.text

// Get the grounding metadata
if let candidate = response.candidates.first,
   let groundingMetadata = candidate.groundingMetadata {
  // REQUIRED - display Google Search suggestions
  // (renderedContent contains HTML and CSS for the search widget)
  if let renderedContent = groundingMetadata.searchEntryPoint?.renderedContent {
    // TODO(developer): Display Google Search suggestions using a WebView
  }

  // RECOMMENDED - display citations
  let groundingChunks = groundingMetadata.groundingChunks
  for chunk in groundingMetadata.groundingChunks {
    if let web = chunk.web {
      let title = web.title  // for example, "uefa.com"
      let uri = web.uri  // for example, "https://vertexaisearch.cloud.google.com..."
      // TODO(developer): show citation in the UI
    }
  }
}

Kotlin

// ...

// Get the model's response
val text = response.text

// Get the grounding metadata
val groundingMetadata = response.candidates.firstOrNull()?.groundingMetadata

// REQUIRED - display Google Search suggestions
// (renderedContent contains HTML and CSS for the search widget)
val renderedContent = groundingMetadata?.searchEntryPoint?.renderedContent
if (renderedContent != null) {
    // TODO(developer): Display Google Search suggestions using a WebView
}

// RECOMMENDED - display citations
val groundingChunks = groundingMetadata?.groundingChunks
groundingChunks?.let { chunks ->
  for (chunk in chunks) {
  	val title = chunk.web?.title  // for example, "uefa.com"
	val uri = chunk.web?.uri  // for example, "https://vertexaisearch.cloud.google.com..."
// TODO(developer): show citation in the UI
  }
}

Java

// ...

Futures.addCallback(response, new FutureCallback() {
  @Override
  public void onSuccess(GenerateContentResponse result) {
  // Get the model's response
  String text = result.getText();

  // Get the grounding metadata
  GroundingMetadata groundingMetadata =
  result.getCandidates()[0].getGroundingMetadata();

  if (groundingMetadata != null) {
    // REQUIRED - display Google Search suggestions
  // (renderedContent contains HTML and CSS for the search widget)
    String renderedContent =
  groundingMetadata.getSearchEntryPoint().getRenderedContent();
    if (renderedContent != null) {
      // TODO(developer): Display Google Search suggestions using a WebView
    }

    // RECOMMENDED - display citations
    List chunks = groundingMetadata.getGroundingChunks();
    if (chunks != null) {
      for(GroundingChunk chunk : chunks) {
        WebGroundingChunk web = chunk.getWeb();
        if (web != null) {
          String title = web.getTitle();  // for example, "uefa.com"
          String uri = web.getUri();  // for example, "https://vertexaisearch.cloud.google.com..."
          // TODO(developer): show citation in the UI
        }
      }
    }
  }
  }

  @Override
  public void onFailure(Throwable t) {
  t.printStackTrace();
  }
  }, executor);

Web

// ...

// Get the model's text response
const text = result.response.text();

// Get the grounding metadata
const groundingMetadata = result.response.candidates?.[0]?.groundingMetadata;

// REQUIRED - display Google Search suggestions
// (renderedContent contains HTML and CSS for the search widget)
const renderedContent = groundingMetadata?.searchEntryPoint?.renderedContent;
if (renderedContent) {
  // TODO(developer): render this HTML and CSS in the UI
}

// RECOMMENDED - display citations
const groundingChunks = groundingMetadata?.groundingChunks;
if (groundingChunks) {
  for (const chunk of groundingChunks) {
    const title = chunk.web?.title;  // for example, "uefa.com"
    const uri = chunk.web?.uri;  // for example, "https://vertexaisearch.cloud.google.com..."
    // TODO(developer): show citation in the UI
  }
}

Dart

Flutter के लिए सहायता, इसकी अगली रिलीज़ में उपलब्ध होगी.

Unity

Unity के साथ काम करने की सुविधा, इसके अगले वर्शन में उपलब्ध होगी.

Firebase कंसोल में, भरोसेमंद स्रोतों से मिली जानकारी वाले नतीजे और एआई की परफ़ॉर्मेंस को मॉनिटर करने की सुविधा

अगर आपने Firebase कंसोल में एआई मॉनिटरिंग की सुविधा चालू की है, तो जवाब Cloud Logging में सेव किए जाते हैं. डिफ़ॉल्ट रूप से, इस डेटा को 30 दिनों तक सेव रखा जाता है.

यह आपकी ज़िम्मेदारी है कि डेटा बनाए रखने की यह अवधि या आपकी तय की गई कोई भी कस्टम अवधि, आपके इस्तेमाल के खास उदाहरण और Gemini APIप्रदाता के लिए, अनुपालन से जुड़ी किसी भी अतिरिक्त ज़रूरी शर्त के मुताबिक हो: Gemini Developer API या Vertex AI Gemini API (सेवा की खास शर्तों में सेवा की शर्तें सेक्शन देखें). इन ज़रूरी शर्तों को पूरा करने के लिए, आपको Cloud Logging में डेटा बनाए रखने की अवधि में बदलाव करना पड़ सकता है.

कीमत और सीमाएं

पक्का करें कि आपने Gemini API सेवा देने वाली कंपनी के दस्तावेज़ में, Google Search के साथ काम करने की सुविधा के लिए, कीमत, मॉडल की उपलब्धता, और सीमाओं की समीक्षा कर ली हो: Gemini Developer API | Vertex AI Gemini API.