Auf dieser Seite erfahren Sie, wie Sie das Vertex AI SDK verwenden, um Aufgaben der Vertex AI RAG Engine auszuführen.
Sie können auch dieses Notebook Einführung in die Vertex AI RAG Engine verwenden.
Erforderliche Rollen
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 example,myemail@example.com
.ROLE
: The IAM role that you grant to your user account.
Google Cloud Console vorbereiten
So verwenden Sie die Vertex AI RAG Engine:
Führen Sie diesen Befehl in der Google Cloud -Console aus, um Ihr Projekt einzurichten.
gcloud config set project {project}
Führen Sie diesen Befehl aus, um Ihre Anmeldung zu autorisieren.
gcloud auth application-default login
Vertex AI RAG Engine ausführen
Kopieren Sie diesen Beispielcode und fügen Sie ihn in die Google Cloud Konsole ein, um die Vertex AI-RAG-Engine auszuführen.
Python
Informationen zur Installation des Vertex AI SDK for Python finden Sie unter Vertex AI SDK for Python installieren. Weitere Informationen finden Sie in der Python-API-Referenzdokumentation.
curl
Erstellen Sie einen RAG-Korpus.
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"'" }'
Weitere Informationen finden Sie unter Beispiel für das Erstellen eines RAG-Korpus.
RAG-Datei importieren
// 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 } }'
Weitere Informationen finden Sie unter Beispiel für den Import von RAG-Dateien.
Führen Sie eine RAG-Abfrage zum Abrufen aus.
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"
Weitere Informationen finden Sie unter RAG Engine API.
Inhalte generieren.
{ "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"
Weitere Informationen finden Sie unter RAG Engine API.
Nächste Schritte
- Weitere Informationen zur RAG API finden Sie unter Vertex AI RAG Engine API.
- Weitere Informationen zu den Antworten von RAG finden Sie unter Ausgabe von Abruf und Generierung der Vertex AI RAG Engine.
- Weitere Informationen zur Vertex AI-RAG-Engine finden Sie unter Vertex AI-RAG-Engine – Übersicht.