이 페이지에서는 Vertex AI SDK를 사용하여 Vertex AI RAG Engine 태스크를 실행하는 방법을 보여줍니다.
이 노트북 Vertex AI RAG Engine 소개를 사용하여 따라할 수도 있습니다.
필요한 역할
Grant roles to your user account. Run the following command once for each of the following
IAM roles:
roles/aiplatform.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: Your project ID.USER_IDENTIFIER
: The identifier for your user account. For examples, see Represent workforce pool users in IAM policies.ROLE
: The IAM role that you grant to your user account.
Google Cloud 콘솔 준비
Vertex AI RAG Engine을 사용하려면 다음 단계를 따르세요.
Google Cloud 콘솔에서 이 명령어를 실행하여 프로젝트를 설정합니다.
gcloud config set project {project}
이 명령어를 실행하여 로그인을 승인합니다.
gcloud auth application-default login
Vertex AI RAG Engine 실행
이 샘플 코드를 복사하여 Google Cloud 콘솔에 붙여넣어 Vertex AI RAG Engine을 실행합니다.
Python
Vertex AI SDK for Python을 설치하거나 업데이트하는 방법은 Vertex AI SDK for Python 설치를 참조하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.
curl
RAG 코퍼스 만들기
export LOCATION=LOCATION export PROJECT_ID=PROJECT_ID export CORPUS_DISPLAY_NAME=CORPUS_DISPLAY_NAME // CreateRagCorpus // Output: CreateRagCorpusOperationMetadata curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora \ -d '{ "display_name" : "'"CORPUS_DISPLAY_NAME"'" }'
자세한 내용은 RAG 코퍼스 만들기 예시를 참고하세요.
RAG 파일 가져오기
// ImportRagFiles // Import a single Cloud Storage file or all files in a Cloud Storage bucket. // Input: LOCATION, PROJECT_ID, RAG_CORPUS_ID, GCS_URIS export RAG_CORPUS_ID=RAG_CORPUS_ID export GCS_URIS=GCS_URIS export CHUNK_SIZE=CHUNK_SIZE export CHUNK_OVERLAP=CHUNK_OVERLAP export EMBEDDING_MODEL_QPM_RATE=EMBEDDING_MODEL_QPM_RATE // Output: ImportRagFilesOperationMetadataNumber // Use ListRagFiles, or import_result_sink to get the correct rag_file_id. curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import \ -d '{ "import_rag_files_config": { "gcs_source": { "uris": "GCS_URIS" }, "rag_file_chunking_config": { "chunk_size": CHUNK_SIZE, "chunk_overlap": CHUNK_OVERLAP }, "max_embedding_requests_per_min": EMBEDDING_MODEL_QPM_RATE } }'
자세한 내용은 RAG 파일 가져오기 예시를 참고하세요.
RAG 검색 쿼리를 실행합니다.
export RAG_CORPUS_RESOURCE=RAG_CORPUS_RESOURCE export VECTOR_DISTANCE_THRESHOLD=VECTOR_DISTANCE_THRESHOLD export SIMILARITY_TOP_K=SIMILARITY_TOP_K { "vertex_rag_store": { "rag_resources": { "rag_corpus": "RAG_CORPUS_RESOURCE" }, "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD }, "query": { "text": TEXT "similarity_top_k": SIMILARITY_TOP_K } } curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts"
자세한 내용은 RAG Engine API를 참고하세요.
콘텐츠 생성
{ "contents": { "role": "USER", "parts": { "text": "INPUT_PROMPT" } }, "tools": { "retrieval": { "disable_attribution": false, "vertex_rag_store": { "rag_resources": { "rag_corpus": "RAG_CORPUS_RESOURCE" }, "similarity_top_k": "SIMILARITY_TOP_K", "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD } } } } curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD"
자세한 내용은 RAG Engine API를 참고하세요.
다음 단계
- RAG API에 대해 자세히 알아보려면 Vertex AI RAG Engine API를 참고하세요.
- RAG의 응답에 대해 자세히 알아보려면 Vertex AI RAG 엔진의 검색 및 생성 출력을 참조하세요.
- Vertex AI RAG Engine에 대해 자세히 알아보려면 Vertex AI RAG Engine 개요를 참고하세요.