- तथ्यों के हिसाब से जवाबों को ज़्यादा सटीक बनाना: मॉडल के गलत जवाब देने की समस्या को कम करना. इसके लिए, जवाबों को असल दुनिया की जानकारी के आधार पर तैयार करना.
- रीयल-टाइम में जानकारी ऐक्सेस करना: हाल ही के इवेंट और विषयों के बारे में सवालों के जवाब देना.
- सोर्स की जानकारी दें: मॉडल के दावों के सोर्स दिखाकर, उपयोगकर्ताओं का भरोसा जीतें या उन्हें काम की साइटें ब्राउज़ करने की अनुमति दें.
- ज़्यादा मुश्किल टास्क पूरे करना: आर्टफ़ैक्ट और काम की इमेज, वीडियो या अन्य मीडिया को वापस पाएं, ताकि तर्क से जुड़े टास्क पूरे करने में मदद मिल सके.
- किसी क्षेत्र या भाषा के हिसाब से जवाबों को बेहतर बनाना: किसी क्षेत्र के हिसाब से जानकारी ढूंढना या कॉन्टेंट का सटीक अनुवाद करने में मदद करना.
इन मॉडल के साथ काम करता है
gemini-3.1-pro-previewgemini-3.5-flashgemini-3.1-flash-litegemini-3-pro-image-preview(इसे "Nano Banana Pro" भी कहा जाता है)gemini-3.1-flash-image-preview(इसे "Nano Banana 2" भी कहा जाता है)gemini-2.5-progemini-2.5-flashgemini-2.5-flash-lite
यह सुविधा इन भाषाओं में काम करती है
Gemini मॉडल के लिए, इस्तेमाल की जा सकने वाली भाषाएं देखें.
Google Search की मदद से मॉडल को ग्राउंड करना
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
GenerativeModel इंस्टेंस बनाते समय, GoogleSearch को tool के तौर पर उपलब्ध कराएं, ताकि मॉडल इसका इस्तेमाल करके जवाब जनरेट कर सके.
Swift
import FirebaseAILogic
// 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
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
// Provide Google Search as a tool that the model can use to generate its response.
tools: [
Tool.googleSearch(),
],
);
final response = await model.generateContent([Content.text("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
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports your use case.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
// Provide Google Search as a tool that the model can use to generate its response.
tools: new[] { new Tool(new GoogleSearch()) }
);
var response = await model.GenerateContentAsync("Who won the euro 2024?");
UnityEngine.Debug.Log(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
अपने इस्तेमाल के उदाहरण और ऐप्लिकेशन के लिए, सही मॉडल चुनने का तरीका जानें.
Google Search से जानकारी लेने की सुविधा कैसे काम करती है
GoogleSearch टूल का इस्तेमाल करने पर, मॉडल अपने-आप जानकारी खोजता है, उसे प्रोसेस करता है, और उसके सोर्स का हवाला देता है.
मॉडल का वर्कफ़्लो यहां दिया गया है:
- प्रॉम्प्ट पाना: आपका ऐप्लिकेशन,
GoogleSearchटूल चालू करके Gemini मॉडल को एक प्रॉम्प्ट भेजता है. - प्रॉम्प्ट का विश्लेषण करना: मॉडल, प्रॉम्प्ट का विश्लेषण करता है और यह तय करता है कि क्या
Google Search अपने जवाब को बेहतर बना सकता है. Google Search को क्वेरी भेजें: ज़रूरत पड़ने पर, मॉडल एक या एक से ज़्यादा खोज क्वेरी अपने-आप जनरेट करता है और उन्हें पूरा करता है.- खोज के नतीजों को प्रोसेस करना: मॉडल,
Google Search नतीजों को प्रोसेस करता है और ओरिजनल प्रॉम्प्ट के लिए जवाब तैयार करता है. - "भरोसेमंद नतीजा" दिखाना: मॉडल, उपयोगकर्ता के लिए आसान और सटीक जवाब दिखाता है. यह जवाब,
Google Search के नतीजों पर आधारित होता है. इस जवाब में, मॉडल का टेक्स्ट वाला जवाब औरgroundingMetadataशामिल होता है. इसमें खोज क्वेरी, वेब नतीजे, और सोर्स शामिल होते हैं.
ध्यान दें कि मॉडल को groundingMetadata ऑब्जेक्ट शामिल नहीं होगा. इसलिए, यह "भरोसेमंद जवाब" नहीं है.

भरोसेमंद स्रोतों से मिले जवाब को समझना
अगर मॉडल, groundingMetadata
"भरोसेमंद सोर्स से मिली जानकारी" वाले जवाब में मौजूद groundingMetadata ऑब्जेक्ट में यह जानकारी शामिल होती है:
webSearchQueries:Google Search को भेजी गई खोज क्वेरी का ऐरे. यह जानकारी, डीबग करने और मॉडल के तर्क देने की प्रोसेस को समझने के लिए काम की होती है.searchEntryPoint: इसमें "Google Search सुझाव" दिखाने के लिए ज़रूरी एचटीएमएल और सीएसएस शामिल होती है. आपको एपीआई उपलब्ध कराने वाली कंपनी के लिए, "Google Search से जानकारी लेकर जवाब देने की सुविधा" इस्तेमाल करने की ज़रूरी शर्तों का पालन करना होगा: Gemini Developer API या Vertex AI Gemini API (सेवा की खास शर्तों में सेवा की शर्तें सेक्शन देखें). इस पेज पर बाद में, भरोसेमंद सोर्स से मिली जानकारी का इस्तेमाल करके जवाब जनरेट करने और उसे दिखाने का तरीका जानें.groundingChunks: यह ऑब्जेक्ट का एक कलेक्शन है. इसमें वेब सोर्स (uriऔरtitle) शामिल होते हैं.groundingSupports: यह ऐसे चंक का कलेक्शन होता है जो मॉडल के जवाबtextकोgroundingChunksमें मौजूद सोर्स से कनेक्ट करता है. हर चंक, एक टेक्स्टsegment(startIndexऔरendIndexसे तय किया गया) को एक या उससे ज़्यादाgroundingChunkIndicesसे लिंक करता है. इस फ़ील्ड की मदद से, सोर्स के इनलाइन लिंक बनाए जा सकते हैं. इस पेज पर बाद में, भरोसेमंद सोर्स से मिली जानकारी का इस्तेमाल करके जवाब जनरेट करने और उसे दिखाने का तरीका जानें.
यहां जवाब का एक उदाहरण दिया गया है, जिसमें 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]
}
]
}
}
]
}
भरोसेमंद सोर्स से मिली जानकारी का इस्तेमाल करना और उसे दिखाना
अगर मॉडल, जवाब जनरेट करने के लिए groundingMetadata ऑब्जेक्ट देगा.
(ज़रूरी है) डिसप्ले Google Search सुझाव
अगर किसी जवाब में "
groundingMetadata ऑब्जेक्ट में "searchEntryPoint फ़ील्ड होता है. इस फ़ील्ड में renderedContent फ़ील्ड होता है, जो नीति के मुताबिक एचटीएमएल और सीएसएस स्टाइलिंग उपलब्ध कराता है. आपको अपने ऐप्लिकेशन में खोज के सुझाव दिखाने के लिए, इसे लागू करना होगा.
Google Cloud के दस्तावेज़ में,
इस सेक्शन में बाद में, कोड सैंपल के उदाहरण देखें.
(ज़रूरी है) डिसप्ले सोर्स
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
}
// REQUIRED - display sources
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 source 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
}
// REQUIRED - display sources
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 source 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
}
// REQUIRED - display sources
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 sources 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
}
// REQUIRED - display sources
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 sources in the UI
}
}
Dart
// ...
// Get the model's response
final text = response.text;
// Get the grounding metadata
final groundingMetadata = response.candidates.first.groundingMetadata;
// REQUIRED - display Google Search suggestions
// (renderedContent contains HTML and CSS for the search widget)
final renderedContent = groundingMetadata?.searchEntryPoint?.renderedContent;
if (renderedContent != null) {
// TODO(developer): Display Google Search suggestions using a WebView
}
// REQUIRED - display sources
final groundingChunks = groundingMetadata?.groundingChunks;
if (groundingChunks != null) {
for (var chunk in groundingChunks) {
final title = chunk.web?.title; // for example, "uefa.com"
final uri = chunk.web?.uri; // for example, "https://vertexaisearch.cloud.google.com..."
// TODO(developer): show sources in the UI
}
}
Unity
// ...
// Get the model's response
var text = response.Text;
// Get the grounding metadata
var groundingMetadata = response.Candidates.First().GroundingMetadata.Value;
// REQUIRED - display Google Search suggestions
// (renderedContent contains HTML and CSS for the search widget)
if (groundingMetadata.SearchEntryPoint.HasValue) {
var renderedContent = groundingMetadata.SearchEntryPoint.Value.RenderedContent;
// TODO(developer): Display Google Search suggestions using a WebView
}
// REQUIRED - display sources
foreach(GroundingChunk chunk in groundingMetadata.GroundingChunks) {
var title = chunk.Web.Value.Title; // for example, "uefa.com"
var uri = chunk.Web.Value.Uri; // for example, "https://vertexaisearch.cloud.google.com..."
// TODO(developer): show sources in the UI
}
Firebase कंसोल में, भरोसेमंद सोर्स से मिले जवाब और एआई की परफ़ॉर्मेंस को मॉनिटर करने की सुविधा
अगर आपने Firebase कंसोल में एआई मॉनिटरिंग की सुविधा चालू की है, तो जवाब Cloud Logging में सेव किए जाते हैं. डिफ़ॉल्ट रूप से, इस डेटा को 30 दिनों तक सेव रखा जाता है.
यह आपकी ज़िम्मेदारी है कि डेटा बनाए रखने की यह अवधि या आपकी तय की गई कोई भी कस्टम अवधि, इस्तेमाल के आपके खास उदाहरण और Gemini APIसेवा देने वाली कंपनी के लिए, अनुपालन से जुड़ी सभी अतिरिक्त ज़रूरी शर्तों के मुताबिक हो: Gemini Developer API या Vertex AI Gemini API (सेवा की खास शर्तों में सेवा की शर्तें सेक्शन देखें). इन ज़रूरी शर्तों को पूरा करने के लिए, आपको Cloud Logging में डेटा बनाए रखने की अवधि में बदलाव करना पड़ सकता है.
कीमत और सीमाएं
आपने Gemini API की सेवा देने वाली जिस कंपनी को चुना है उसके दस्तावेज़ में,