Halaman ini menunjukkan cara menggunakan Vertex AI SDK untuk menjalankan tugas Vertex AI RAG Engine.
Anda juga dapat mengikuti notebook ini Pengantar Vertex AI RAG Engine.
Peran yang diperlukan
Berikan peran ke akun pengguna Anda. Jalankan perintah berikut satu kali untuk setiap peran IAM berikut:
roles/aiplatform.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Ganti kode berikut:
PROJECT_ID: Project ID Anda.USER_IDENTIFIER: ID untuk akun pengguna Anda. Misalnya,myemail@example.com.ROLE: Peran IAM yang Anda berikan ke akun pengguna Anda.
Menyiapkan Google Cloud konsol
Untuk menggunakan Vertex AI RAG Engine, lakukan hal berikut:
Jalankan perintah ini di Google Cloud konsol untuk menyiapkan project Anda.
gcloud config set project {project}Jalankan perintah ini untuk mengotorisasi login Anda.
gcloud auth application-default login
Menjalankan Vertex AI RAG Engine
Salin dan tempel contoh kode ini di Google Cloud konsol untuk menjalankan Vertex AI RAG Engine.
Python
Untuk mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat Python Dokumentasi referensi API.
curl
Buat korpus 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"'" }'Untuk mengetahui informasi selengkapnya, lihat Contoh membuat korpus RAG contoh.
Impor file 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 } }'Untuk mengetahui informasi selengkapnya, lihat Contoh mengimpor file RAG.
Jalankan kueri pengambilan 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"Untuk mengetahui informasi selengkapnya, lihat RAG Engine API.
Buat konten.
{ "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"Untuk mengetahui informasi selengkapnya, lihat RAG Engine API.
Langkah berikutnya
Untuk mempelajari RAG API lebih lanjut, lihat Vertex AI RAG Engine API.
Untuk mempelajari respons dari RAG lebih lanjut, lihat Output Pengambilan dan Pembuatan Vertex AI RAG Engine.
Untuk mempelajari Vertex AI RAG Engine, lihat Ringkasan Vertex AI RAG Engine.