그라운딩 API

그라운딩하면 모델은 출력을 신뢰할 수 있는 정보 소스에 연결할 수 있습니다. 그라운딩 절차는 모델 출력을 특정 데이터에 연결하여 할루시네이션을 최소화합니다. Google 검색을 공개적으로 사용 가능한 웹 데이터로 그라운딩하거나 사용자가 Vertex AI Search의 자체 데이터를 데이터 스토어로 활용할 수 있습니다.

지원되는 모델:

  • Gemini 1.0 Pro
    • gemini-1.0-pro-001
    • gemini-1.0-pro-002

제한사항

  • 영어 데이터를 지원합니다.
  • 그라운딩은 텍스트 응답에만 사용할 수 있습니다.

매개변수 목록

그라운딩을 사용 설정하려면 요청에 검색 tool을 지정하세요. ML Ops 옵션은 다음과 같습니다.

  • GoogleSearchRetrieval: 그라운딩에 공개 웹 데이터를 사용합니다.
  • Retrieval: Vertex AI Search를 사용하여 비공개 데이터 소스에 연결합니다.

GoogleSearchRetrieval

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

검색

Vertex AI Search를 통해 비공개 데이터로 그라운딩합니다. 모델이 외부 지식에 액세스하기 위해 호출할 수 있는 검색 도구를 정의합니다.

매개변수

source

VertexAISearch

Vertex AI Search에서 제공하는 데이터 소스를 사용하도록 설정합니다.

VertexAISearch

그라운딩을 위해 Vertex AI Search 데이터 스토어에서 검색합니다. 자세한 내용은 Vertex AI Search and Conversation을 참조하세요.

매개변수

datastore

string

Vertex AI Search의 정규화된 데이터 스토어 리소스 ID입니다.projects/<>/locations/<>/collections/<>/dataStores/<>

예시

  • PROJECT_ID = PROJECT_ID
  • 리전 = us-central1
  • MODEL_ID = gemini-1.0-pro

공개 웹 데이터에 대한 기본 응답

curl

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  https://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${REGION}/publishers/google/models/${MODEL_ID}:generateContent \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "What did Lincoln do for fun?"
      }]
    }],
    "tools": [{
      "googleSearchRetrieval": {}
    }]
  }'

Python

import vertexai
from vertexai.generative_models import GenerativeModel, Tool
from vertexai.preview import generative_models as preview_generative_models

vertexai.init(project=PROJECT_ID, location=REGION)

gemini_model = GenerativeModel(MODEL_ID)
google_search_tool = Tool.from_google_search_retrieval(
    google_search_retrieval=preview_generative_models.grounding.GoogleSearchRetrieval()
)

model_response = gemini_model.generate_content(
    "What did Lincoln do for fun?", tools=[google_search_tool]
)

print(model_response)

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

기본 요건: 먼저 검색 데이터 스토어를 만들어야 합니다.

데이터 스토어 리소스 경로를 이 예시에 사용할 DATASTORE 변수로 설정합니다.

curl

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  https://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${REGION}/publishers/google/models/${MODEL_ID}:generateContent \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "How to make appointment to renew driving license?"
      }]
    }],
    "tools": [{
      "retrieval": {
        "vertexAiSearch": {
          "datastore": "'${DATASTORE}'"
        }
      }
    }]
  }'

Python

import vertexai
from vertexai.generative_models import GenerativeModel, Tool
from vertexai.preview import generative_models as preview_generative_models

vertexai.init(project=PROJECT_ID, location=REGION)

gemini_model = GenerativeModel(MODEL_ID)
vertex_search_tool = Tool.from_retrieval(
    retrieval=preview_generative_models.grounding.Retrieval(
        source=preview_generative_models.grounding.VertexAISearch(datastore=DATASTORE),
    )
)

model_response = gemini_model.generate_content(
    "How to make appointment to renew driving license?", tools=[vertex_search_tool]
)

print(model_response)

더 살펴보기

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