Questa pagina mostra come utilizzare l'SDK Vertex AI per eseguire le attività di RAG Engine su Gemini Enterprise Agent Platform.
Puoi anche seguire la procedura utilizzando questo blocco note Introduzione a RAG Engine.
Ruoli obbligatori
Concedi i ruoli al tuo account utente. Esegui il seguente comando una volta per ciascuno dei seguenti ruoli IAM:
roles/aiplatform.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Sostituisci quanto segue:
PROJECT_ID: il tuo ID progetto.USER_IDENTIFIER: l'identificatore del tuo account utente. Ad esempio:myemail@example.com.ROLE: il ruolo IAM che concedi al tuo account utente.
Prepara la console Google Cloud
Per utilizzare RAG Engine, segui questi passaggi:
Esegui questo comando nella console Google Cloud per configurare il progetto.
gcloud config set project {project}Esegui questo comando per autorizzare l'accesso.
gcloud auth application-default login
Esegui RAG Engine
Copia e incolla questo codice campione nella console Google Cloud per eseguire il motore RAG.
Python
Per scoprire come installare o aggiornare l'SDK Vertex AI Python, consulta Installa l'SDK Vertex AI Python. Per saperne di più, consulta la documentazione di riferimento dell'API Python.
curl
Crea un corpus 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"'" }'Per saperne di più, consulta Crea un esempio di corpus RAG.
Importa un 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 } }'Per saperne di più, consulta Esempio di importazione di file RAG.
Esegui una query di recupero 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"Per saperne di più, consulta l'API RAG Engine.
Crea contenuti.
{ "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"Per saperne di più, consulta l'API RAG Engine.
Passaggi successivi
Per scoprire di più sull'API RAG, consulta l'API RAG Engine.
Per scoprire di più sulle risposte di RAG, consulta Output di recupero e generazione di RAG Engine.
Per scoprire di più sul RAG Engine, consulta la panoramica del RAG Engine.