그라운딩

생성형 AI에서 그라운딩은 모델 출력을 확인 가능한 정보 소스에 연결하는 기능입니다. 모델에 특정 데이터 소스에 대한 액세스 권한을 제공하면 그라운딩에서 이러한 데이터에 대한 출력을 테더링하므로 콘텐츠가 조작될 가능성이 줄어듭니다.

Vertex AI를 사용하면 다음과 같은 방법으로 모델 출력을 그라운딩할 수 있습니다.

  • Google 검색으로 그라운딩 - 공개적으로 사용 가능한 웹 데이터로 모델을 그라운딩합니다.
  • 자체 데이터에 그라운딩 - Vertex AI Search의 자체 데이터를 데이터 스토어로 사용하여 모델을 그라운딩합니다.

그라운딩에 관한 자세한 내용은 그라운딩 개요를 참조하세요.

지원되는 모델

매개변수 목록

구현 세부정보는 예시를 참고하세요.

GoogleSearchRetrieval

공개 데이터를 사용하여 응답을 그라운딩합니다.

매개변수

google_search_retrieval

필수: Object

공개적으로 사용 가능한 웹 데이터로 그라운딩합니다.

Retrieval

Vertex AI Search의 비공개 데이터를 데이터 스토어로 사용하여 응답을 그라운딩합니다. 모델이 호출하여 외부 지식에 액세스할 수 있는 검색 도구를 정의합니다.

매개변수

source

필수: VertexAISearch

Vertex AI Search 데이터 소스로 그라운딩합니다.

VertexAISearch

매개변수

datastore

필수: string

Vertex AI Search의 정규화된 데이터 스토어 리소스 ID이며, projects/{project}/locations/{location}/collections/default_collection/dataStores/{datastore} 형식입니다.

Google 검색을 사용하여 공개 웹 데이터에 대한 응답 그라운딩

Google 검색 공개 데이터를 사용하여 응답을 그라운딩합니다. 요청에 google_search_retrieval 도구를 포함합니다. 추가 매개변수는 필요하지 않습니다.

Python

설치

pip install --upgrade google-genai

자세한 내용은 SDK 참고 문서를 참조하세요.

Vertex AI에서 Gen AI SDK를 사용하도록 환경 변수를 설정합니다.

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import (
    GenerateContentConfig,
    GoogleSearch,
    HttpOptions,
    Tool,
)

client = genai.Client(http_options=HttpOptions(api_version="v1"))

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="When is the next total solar eclipse in the United States?",
    config=GenerateContentConfig(
        tools=[
            # Use Google Search Tool
            Tool(google_search=GoogleSearch())
        ],
    ),
)

print(response.text)
# Example response:
# 'The next total solar eclipse in the United States will occur on ...'

Go

Go를 설치하거나 업데이트하는 방법을 알아보세요.

자세한 내용은 SDK 참고 문서를 참조하세요.

Vertex AI에서 Gen AI SDK를 사용하도록 환경 변수를 설정합니다.

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	genai "google.golang.org/genai"
)

// generateWithGoogleSearch shows how to generate text using Google Search.
func generateWithGoogleSearch(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.5-flash"
	contents := []*genai.Content{
		{Parts: []*genai.Part{
			{Text: "When is the next total solar eclipse in the United States?"},
		},
			Role: "user"},
	}
	config := &genai.GenerateContentConfig{
		Tools: []*genai.Tool{
			{GoogleSearch: &genai.GoogleSearch{}},
		},
	}

	resp, err := client.Models.GenerateContent(ctx, modelName, contents, config)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText := resp.Text()

	fmt.Fprintln(w, respText)

	// Example response:
	// The next total solar eclipse in the United States will occur on March 30, 2033, but it will only ...

	return nil
}

Vertex AI Search를 사용한 비공개 데이터에 대한 기본 응답

Vertex AI Search 데이터 스토어의 데이터로 응답을 그라운딩합니다. 자세한 내용은 AI Applications를 참고하세요.

비공개 데이터로 응답을 그라운딩하기 전에 데이터 스토어검색 앱을 만듭니다.

경고: 당분간 이 '그라운딩' 인터페이스는 Vertex AI Search '청크 모드'를 지원하지 않습니다.

Python용 Gen AI SDK

from google import genai
from google.genai.types import (
    GenerateContentConfig,
    HttpOptions,
    Retrieval,
    Tool,
    VertexAISearch,
)

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Load Data Store ID from Vertex AI Search
# datastore = "projects/111111111111/locations/global/collections/default_collection/dataStores/data-store-id"

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="How do I make an appointment to renew my driver's license?",
    config=GenerateContentConfig(
        tools=[
            # Use Vertex AI Search Tool
            Tool(
                retrieval=Retrieval(
                    vertex_ai_search=VertexAISearch(
                        datastore=datastore,
                    )
                )
            )
        ],
    ),
)

print(response.text)
# Example response:
# 'The process for making an appointment to renew your driver's license varies depending on your location. To provide you with the most accurate instructions...'

다음 단계

자세한 문서는 다음을 참조하세요.