בדף הזה מוסבר איך להשתמש ב-Vertex AI SDK כדי להריץ את RAG Engine במשימות של פלטפורמת הסוכנים של Gemini Enterprise.
אפשר גם לעקוב אחרי ההסבר באמצעות מחברת Intro to RAG Engine.
התפקידים הנדרשים
מעניקים תפקידים לחשבון המשתמש. מריצים את הפקודה הבאה לכל אחד מהתפקידים הבאים ב-IAM:
roles/aiplatform.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
מחליפים את מה שכתוב בשדות הבאים:
-
PROJECT_ID: מזהה הפרויקט. -
USER_IDENTIFIER: המזהה של חשבון המשתמש . לדוגמה,myemail@example.com. -
ROLE: תפקיד ה-IAM שאתם מקצים לחשבון המשתמש.
הכנת קונסולת Google Cloud
כדי להשתמש ב-RAG Engine:
מריצים את הפקודה הזו במסוף Google Cloud כדי להגדיר את הפרויקט.
gcloud config set project {project}מריצים את הפקודה הזו כדי לאשר את הכניסה.
gcloud auth application-default login
הרצת מנוע RAG
מעתיקים את קוד הדוגמה הזה ומדביקים אותו במסוף Google Cloud כדי להריץ את RAG Engine.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-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 זמין במאמר RAG Engine API.
מידע נוסף על התשובות מ-RAG זמין במאמר בנושא שליפה ויצירה של פלט ממנוע RAG.
מידע נוסף על RAG Engine זמין במאמר סקירה כללית על RAG Engine.