Google 검색으로 그라운딩은 Gemini 모델을 실시간으로 공개적으로 사용 가능한 웹 콘텐츠에 연결합니다. 이를 통해 모델은 지식 컷오프를 넘어 더 정확하고 최신 답변을 제공하고 검증 가능한 출처를 인용할 수 있습니다.
Google 검색을 사용한 그라운딩에는 다음과 같은 이점이 있습니다.
- 사실에 기반한 정확성 향상: 실제 정보를 기반으로 대답하여 모델 할루시네이션을 줄입니다.
- 실시간 정보 액세스: 최근 이벤트 및 주제에 관한 질문에 답변합니다.
- 인용 제공: 모델의 주장에 대한 출처를 표시하여 사용자 신뢰를 구축하거나 사용자가 관련 사이트를 탐색할 수 있도록 합니다.
- 더 복잡한 작업 완료: 추론 작업을 지원하기 위해 아티팩트와 관련 이미지, 동영상 또는 기타 미디어를 검색합니다.
- 지역 또는 언어별 대답 개선: 지역별 정보를 찾거나 콘텐츠를 정확하게 번역하는 데 도움을 받습니다.
Google 검색의 그라운딩 지원은 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 검색으로 모델 그라운딩
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다. |
GenerativeModel
인스턴스를 만들 때 모델이 대답을 생성하는 데 사용할 수 있는 tool
로 GoogleSearch
를 제공합니다.
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 검색을 사용한 그라운딩의 작동 방식
GoogleSearch
도구를 사용하면 모델이 정보 검색, 처리, 인용의 전체 워크플로를 자동으로 처리합니다.
모델의 워크플로는 다음과 같습니다.
- 프롬프트 수신: 앱이
GoogleSearch
도구가 사용 설정된 상태로 Gemini 모델에 프롬프트를 전송합니다. - 프롬프트 분석: 모델이 프롬프트를 분석하고 Google 검색이 대답을 개선할 수 있는지 확인합니다.
- Google 검색에 질문 보내기: 필요한 경우 모델이 하나 이상의 검색어를 자동으로 생성하고 실행합니다.
- 검색 결과 처리: 모델이 Google 검색 결과를 처리하고 원래 프롬프트에 대한 대답을 구성합니다.
- '그라운딩된 결과' 반환: 모델이 Google 검색 결과에 그라운딩된 최종 사용자 친화적인 응답을 반환합니다. 이 대답에는 모델의 텍스트 답변과 검색어, 웹 결과, 인용이 포함된
groundingMetadata
가 포함됩니다.
모델에 Google 검색을 도구로 제공한다고 해서 모델이 항상 Google 검색 도구를 사용하여 응답을 생성해야 하는 것은 아닙니다. 이러한 경우 대답에 groundingMetadata
객체가 포함되지 않으므로 '그라운딩된 결과'가 아닙니다.
그라운딩된 결과 이해하기
모델이 Google 검색 결과에 대답을 그라운딩하면 대답에 클레임을 확인하고 애플리케이션에서 풍부한 인용 환경을 구축하는 데 필수적인 구조화된 데이터가 포함된 groundingMetadata
객체가 포함됩니다.
'그라운딩된 결과'의 groundingMetadata
객체에는 다음 정보가 포함됩니다.
webSearchQueries
: Google 검색에 전송된 검색어의 배열입니다. 이 정보는 디버깅하고 모델의 추론 프로세스를 이해하는 데 유용합니다.searchEntryPoint
: 필수 'Google 검색 추천'을 렌더링하는 HTML과 CSS가 포함되어 있습니다. 선택한 API 제공업체(Gemini Developer API 또는 Vertex AI Gemini API)의 'Google 검색을 사용한 그라운딩' 사용 요구사항을 준수해야 합니다(서비스 특정 약관의 서비스 약관 섹션 참고). 이 페이지 뒷부분에서 그라운딩된 결과를 사용하고 표시하는 방법을 알아보세요.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]
}
]
}
}
]
}
그라운딩된 결과 사용 및 표시
모델이 Google 검색 도구를 사용하여 응답을 생성하는 경우 응답에 groundingMetadata
객체를 제공합니다.
Google 검색 추천을 표시하는 것은 필수이며 인용을 표시하는 것은 권장됩니다.
Google 검색 도구 사용 요구사항을 준수하는 것 외에도 이 정보를 표시하면 개발자와 최종 사용자가 대답을 검증하고 추가 학습의 기회를 얻을 수 있습니다.
(필수) Google 검색 추천 표시
대답에 'Google 검색 추천'이 포함된 경우 Google 검색을 사용한 그라운딩 사용 요구사항을 준수해야 합니다. 여기에는 Google 검색 추천을 표시하는 방법이 포함됩니다.
groundingMetadata
객체에는 'Google 검색 추천'이 포함되어 있습니다. 특히 searchEntryPoint
필드에는 호환되는 HTML 및 CSS 스타일을 제공하는 renderedContent
필드가 있습니다. 이 스타일은 앱에서 검색 추천을 표시하기 위해 구현해야 합니다.
Google Cloud 문서에서 Google 검색 추천의 표시 및 동작 요구사항에 관한 자세한 정보를 검토하세요. 이 자세한 안내는 Vertex AI Gemini API 문서에 있지만 Gemini Developer API 제공업체에도 적용됩니다.
이 섹션의 뒷부분에 나오는 예시 코드 샘플을 참고하세요.
(권장) 인용 표시
groundingMetadata
객체에는 구조화된 인용 데이터, 특히 groundingSupports
및 groundingChunks
필드가 포함됩니다. 이 정보를 사용하여 모델의 설명을 UI 내 소스에 직접 연결합니다 (인라인 및 집계).
이 섹션의 뒷부분에 나오는 예시 코드 샘플을 참고하세요.
예시 코드 샘플
이러한 코드 샘플은 그라운딩된 결과를 사용하고 표시하기 위한 일반화된 패턴을 제공합니다. 하지만 특정 구현이 규정 준수 요구사항을 준수하는지 확인할 책임은 사용자에게 있습니다.
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 콘솔의 그라운딩된 결과 및 AI 모니터링
Firebase 콘솔에서 AI 모니터링을 사용 설정한 경우 대답이 Cloud Logging에 저장됩니다. 기본적으로 이 데이터의 보관 기간은 30일입니다.
이 보관 기간 또는 설정한 맞춤 기간이 특정 사용 사례 및 선택한 Gemini API 제공업체(Gemini Developer API 또는 Vertex AI Gemini API)의 추가 규정 준수 요구사항과 완전히 일치하는지 확인해야 합니다(서비스별 약관의 서비스 약관 섹션 참고). 이러한 요구사항을 충족하려면 Cloud Logging에서 보관 기간을 조정해야 할 수 있습니다.
가격 및 제한
선택한 Gemini API 제공업체 문서(Gemini Developer API 또는 Vertex AI Gemini API)에서 Google 검색을 사용한 그라운딩의 가격, 모델 가용성, 한도를 검토하세요.