בדף הזה מוסבר איך לקשר את הקורפוס של RAG Engine למסד הנתונים של Weaviate.
אתם יכולים גם לעקוב אחרי ההוראות ב-notebook הזה: RAG Engine with Weaviate.
אתם יכולים להשתמש במופע של מסד הנתונים Weaviate, שהוא מסד נתונים בקוד פתוח, עם RAG Engine כדי ליצור אינדקס ולבצע חיפוש דמיון מבוסס-וקטור. חיפוש דמיון הוא דרך למצוא קטעי טקסט שדומים לטקסט שאתם מחפשים, וצריך להשתמש במודל הטמעה. מודל ההטמעה יוצר נתוני וקטור לכל קטע טקסט שמשווים. חיפוש הדמיון משמש לאחזור הקשרים סמנטיים לביסוס, כדי להחזיר את התוכן המדויק ביותר מה-LLM.
באמצעות RAG Engine, אתם יכולים להמשיך להשתמש במכונה של מסד נתונים וקטורי בניהול מלא, שאתם אחראים להקצאה שלה. מנוע RAG משתמש במסד הנתונים הווקטורי לאחסון, לניהול אינדקסים ולחיפוש.
לתשומת ליבכם
לפני שמשתמשים במסד הנתונים של Weaviate, כדאי לבצע את הפעולות הבאות:
- אתם צריכים ליצור, להגדיר ולפרוס את המכונה והאוסף של מסד הנתונים ב-Weaviate. פועלים לפי ההוראות במאמר יצירת אוסף ב-Weaviate כדי להגדיר אוסף על סמך הסכימה.
- אתם צריכים לספק מפתח Weaviate API, שמאפשר למנוע RAG לקיים אינטראקציה עם מסד הנתונים של Weaviate. מנוע RAG תומך ב-
AuthNוב-AuthZשמבוססים על מפתח API, שמתחברים למסד הנתונים של Weaviate ותומכים בחיבור HTTPS. - מנוע RAG לא מאחסן ומנהל את מפתח ה-API של Weaviate. במקום זאת, צריך לבצע את הפעולות הבאות:
- שומרים את המפתח ב- Google Cloud Secret Manager.
- נותנים לחשבון השירות של הפרויקט הרשאות גישה לסוד.
- נותנים למנוע RAG גישה לשם המשאב של הסוד.
- כשאתם מבצעים אינטראקציה עם מסד הנתונים של Weaviate, מנוע ה-RAG ניגש למשאב הסודי באמצעות חשבון השירות שלכם.
- הקורפוס של RAG Engine והאוסף של Weaviate ממופים ביחס של אחד לאחד. קבצי RAG מאוחסנים באוסף של מסד נתונים ב-Weaviate. כששולחים קריאה ל-API של
CreateRagCorpusאו ל-API שלUpdateRagCorpus, מאגר הנתונים של RAG משויך לאוסף של מסד הנתונים. - בנוסף לחיפושים סמנטיים שמבוססים על הטמעות צפופות, חיפוש היברידי נתמך גם ב-RAG Engine באמצעות מסד נתונים של Weaviate. אפשר גם לשנות את המשקל בין דמיון וקטורי דחוס ודליל בחיפוש היברידי.
הקצאת מסד הנתונים של Weaviate
לפני שמשתמשים במסד הנתונים של Weaviate עם RAG Engine, צריך לבצע את הפעולות הבאות:
- מגדירים ופורסים את המכונה של מסד הנתונים של Weaviate.
- מכינים את נקודת הקצה (endpoint) של HTTPS.
- יוצרים את האוסף ב-Weaviate.
- משתמשים במפתח ה-API כדי להקצות את Weaviate באמצעות
AuthNו-AuthZ. - מקצים את חשבון השירות של RAG Engine.
הגדרה ופריסה של המכונה של מסד הנתונים של Weaviate
צריך לפעול לפי המדריך הרשמי למתחילים של Weaviate. עם זאת, אפשר להשתמש Google Cloud במדריך של Marketplace, אבל זה אופציונלי.
אתם יכולים להגדיר את המכונה של Weaviate בכל מקום, כל עוד נקודת הקצה של Weaviate נגישה להגדרה ולפריסה בפרויקט. לאחר מכן תוכלו לנהל באופן מלא את המכונה של מסד הנתונים של Weaviate.
מכיוון ש-RAG Engine לא מעורב באף שלב במחזור החיים של המכונה של מסד הנתונים ב-Weaviate, אתם צריכים לתת ל-RAG Engine הרשאות כדי שהוא יוכל לאחסן נתונים במסד הנתונים ב-Weaviate ולחפש בהם. אתם גם צריכים לוודא שמנוע RAG יכול להשתמש בנתונים שבמסד הנתונים שלכם. לדוגמה, אם אתם משנים את הנתונים, RAG Engine לא אחראי להתנהגויות בלתי צפויות שנובעות מהשינויים האלה.
הכנת נקודת הקצה (endpoint) של HTTPS
כשאתם מקצים את Weaviate, חשוב ליצור נקודת קצה מסוג HTTPS. אפשר להשתמש בחיבורי HTTP, אבל אנחנו מעדיפים שתנועת הנתונים במסד הנתונים של RAG Engine ו-Weaviate תשתמש בחיבור HTTPS.
יצירת אוסף Weaviate
מכיוון שהקורפוס של RAG Engine והאוסף של Weaviate ממופים ביחס של אחד לאחד, צריך ליצור אוסף במסד הנתונים של Weaviate לפני שמשייכים את האוסף לקורפוס של RAG Engine. השיוך החד-פעמי הזה מתבצע כששולחים קריאה ל-API של CreateRagCorpus או ל-API של UpdateRagCorpus.
כשיוצרים אוסף ב-Weaviate, צריך להשתמש בסכימה הבאה:
| שם המאפיין | סוג נתונים |
|---|---|
fileId |
text |
corpusId |
text |
chunkId |
text |
chunkDataType |
text |
chunkData |
text |
fileOriginalUri |
text |
משתמשים במפתח ה-API כדי להקצות את Weaviate באמצעות AuthN ו-AuthZ
כדי להקצות את מפתח ה-API של Weaviate, צריך לבצע את השלבים הבאים:
- יוצרים את מפתח ה-API של Weaviate.
- מגדירים את Weaviate באמצעות מפתח ה-API של Weaviate.
- שומרים את מפתח ה-API של Weaviate ב-Secret Manager.
יצירת מפתח ה-API
מנוע RAG יכול להתחבר למכונות של מסד הנתונים ב-Weaviate רק באמצעות מפתח ה-API שלכם לצורך אימות והרשאה. כדי להגדיר אימות שמבוסס על מפתח API במכונה של מסד הנתונים של Weaviate, צריך לפעול לפי המדריך הרשמי של Weaviate לאימות.
אם כדי ליצור את מפתח ה-API של Weaviate צריך פרטי זהות שמשויכים למנוע RAG, אתם צריכים ליצור את הקורפוס הראשון ולהשתמש בחשבון השירות של מנוע RAG בתור זהות.
אחסון מפתח ה-API ב-Secret Manager
מפתח API מכיל פרטים אישיים מזהים בעלי רגישות גבוהה (SPII), שכפופים לדרישות משפטיות. אם נתוני ה-SPII נחשפים או שנעשה בהם שימוש לרעה, האדם עלול להיפגע או שעלול להיגרם לו נזק. כדי למזער את הסיכונים לאדם פרטי בזמן השימוש ב-RAG Engine, אל תאחסנו ותנהלו את מפתח ה-API, והימנעו משיתוף של מפתח ה-API הלא מוצפן.
כדי להגן על SPII, מבצעים את הפעולות הבאות:
- שומרים את מפתח ה-API ב-Secret Manager.
- נותנים לחשבון השירות של RAG Engine את ההרשאות לסודות, ומנהלים את בקרת הגישה ברמת המשאב של הסוד.
- עוברים אל ההרשאות של הפרויקט.
- מפעילים את האפשרות Include Google-provided role grants.
- מאתרים את חשבון השירות, שמופיע בפורמט הבא:
service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.com - עורכים את חשבונות המשתמשים של חשבון השירות.
- מוסיפים לחשבון השירות את התפקיד Secret Manager Secret Accessor.
- במהלך היצירה או העדכון של קורפוס ה-RAG, מעבירים את שם המשאב הסודי למנוע ה-RAG ושומרים את שם המשאב הסודי.
כששולחים בקשות API למכונות של מסד הנתונים של Weaviate, מנוע ה-RAG משתמש בכל חשבון שירות כדי לקרוא את מפתח ה-API שתואם למשאבי הסודות ב-Secret Manager מהפרויקטים.
הקצאת חשבון שירות ל-RAG Engine
כשיוצרים את המשאב הראשון בפרויקט, מנוע ה-RAG יוצר חשבון שירות ייעודי. אתם יכולים למצוא את חשבון השירות בדף IAM של הפרויקט. חשבון השירות הוא בפורמט הבא:
service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.com
לדוגמה, service-123456789@gcp-sa-vertex-rag.iam.gserviceaccount.com.
כשמשלבים את מסד הנתונים של Weaviate, חשבון השירות משמש בתרחישים הבאים:
- אתם יכולים להשתמש בחשבון השירות כדי ליצור את מפתח ה-API של Weaviate לצורך אימות. במקרים מסוימים, כדי ליצור את מפתח ה-API לא נדרשים פרטי משתמש, כלומר לא נדרש חשבון שירות כשיוצרים את מפתח ה-API.
- כדי להגדיר את האימות (
AuthN) וההרשאה (AuthZ), אתם יכולים לקשר את חשבון השירות למפתח ה-API במסד הנתונים של Weaviate, אבל לא חייבים להשתמש בחשבון שירות. - אתם יכולים לאחסן את מפתח ה-API ב-Secret Manager בפרויקט, ולתת לחשבון השירות הרשאות למשאבי הסודות האלה.
- מנוע RAG משתמש בחשבונות שירות כדי לגשת למפתח ה-API מ-Secret Manager בפרויקטים שלכם.
הגדרה של סביבת מסוף Google Cloud
איך מגדירים את הסביבה
כדי להגדיר את הסביבה, בוחרים באחת מהכרטיסיות הבאות:
Python
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
-
אם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי בחשבון המשתמש:
gcloud auth application-default login
אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.
אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
מתקינים או מעדכנים את Agent Platform SDK ל-Python באמצעות הפקודה הבאה:
pip3 install --upgrade "google-cloud-aiplatform>=1.38"
Node.js
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
-
אם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי בחשבון המשתמש:
gcloud auth application-default login
אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.
אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
מתקינים או מעדכנים את Agent Platform SDK ל-Node.js באמצעות הפקודה הבאה:
npm install @google-cloud/vertexai
Java
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
-
אם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי בחשבון המשתמש:
gcloud auth application-default login
אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.
אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
-
כדי להוסיף את
google-cloud-vertexaiכתלות, מוסיפים את הקוד שמתאים לסביבה:Maven עם BOM
מוסיפים את קוד ה-HTML הבא ל-
pom.xml:<dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>libraries-bom</artifactId> <version>26.32.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vertexai</artifactId> </dependency> </dependencies>Maven בלי BOM
מוסיפים את קוד ה-HTML הבא ל-
pom.xml:<dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vertexai</artifactId> <version>0.4.0</version> </dependency>Gradle בלי BOM
מוסיפים את הנתונים הבאים לקובץ
build.gradle:implementation 'com.google.cloud:google-cloud-vertexai:0.4.0'
Go
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
-
אם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי בחשבון המשתמש:
gcloud auth application-default login
אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.
אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
כדי לבחור את החבילה שהכי מתאימה לפרויקט, כדאי לעיין בחבילות של Agent Platform API Go:
החבילה cloud.google.com/go/vertexai (מומלץ)
vertexaiהיא חבילה שנוצרה על ידי בני אדם ומספקת גישה ליכולות ולתכונות נפוצות.החבילה הזו מומלצת כנקודת התחלה לרוב המפתחים שמשתמשים ב-Agent Platform API. כדי לגשת ליכולות ולתכונות שעדיין לא נכללות בחבילה הזו, צריך להשתמש ב-
aiplatformשנוצר אוטומטית.החבילה cloud.google.com/go/aiplatform
aiplatformהיא חבילה שנוצרה אוטומטית.החבילה הזו מיועדת לפרויקטים שדורשים גישה ליכולות ולתכונות של Agent Platform API, שעדיין לא קיימות בחבילה
vertexaiשנוצרה על ידי בני אדם.
מתקינים את חבילת Go הרצויה בהתאם לצרכים של הפרויקט, על ידי הפעלת אחת מהפקודות הבאות:
# Human authored package. Recommended for most developers. go get cloud.google.com/go/vertexai
# Auto-generated package. go get cloud.google.com/go/aiplatform
C#
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
-
אם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי בחשבון המשתמש:
gcloud auth application-default login
אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.
אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
REST
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
מפעילים את Cloud Shell במסוף Google Cloud .
בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
- מזינים את הפרטים הבאים כדי להגדיר משתני סביבה. מחליפים את
PROJECT_IDבמזהה הפרויקט ב- Google Cloud .MODEL_ID="gemini-3.5-flash" PROJECT_ID="PROJECT_ID" - מקצים את נקודת הקצה:
gcloud beta services identity create --service=aiplatform.googleapis.com --project=${PROJECT_ID} - אופציונלי: אם אתם משתמשים ב-Cloud Shell ומתבקשים לאשר את Cloud Shell, לוחצים על Authorize.
הכנת קורפוס RAG
כדי לגשת לנתונים ממסד הנתונים של Weaviate, ל-RAG Engine צריכה להיות גישה לקורפוס RAG. בקטע הזה מוסבר איך יוצרים קורפוס RAG אחד וקורפוסים נוספים של RAG.
שימוש בממשקי ה-API של CreateRagCorpus ו-UpdateRagCorpus
כששולחים קריאה לממשקי ה-API של CreateRagCorpus ו-UpdateRagCorpus, צריך לציין את השדות הבאים:
-
rag_vector_db_config.weaviate: אחרי ששולחים קריאה ל-API שלCreateRagCorpus, בוחרים את ההגדרות של מסד הנתונים הווקטורי. ההגדרה של מסד הנתונים הווקטורי מכילה את כל שדות התצורה. אם השדהrag_vector_db_config.weaviateלא מוגדר,rag_vector_db_config.rag_managed_dbמוגדר כברירת מחדל. -
weaviate.http_endpoint: נקודת הקצה (endpoint) של Weaviate ב-HTTPS או ב-HTTP נוצרת במהלך ההקצאה של המכונה של מסד הנתונים של Weaviate. -
weaviate.collection_name: שם האוסף שנוצר במהלך הקצאת המכונה של Weaviate. השם חייב להתחיל באות גדולה. -
api_auth.api_key_config: ההגדרה מציינת שצריך להשתמש במפתח API כדי לאשר את הגישה למסד הנתונים של הווקטורים. -
api_key_config.api_key_secret_version: שם המשאב של הסוד שמאוחסן ב-Secret Manager, שמכיל את מפתח ה-API של Weaviate.
אתם יכולים ליצור קורפוס RAG ולשייך אותו לאוסף Weaviate במכונה של מסד הנתונים. עם זאת, יכול להיות שתצטרכו את חשבון השירות כדי ליצור את מפתח ה-API ולהגדיר את המכונה של מסד הנתונים של Weaviate. כשיוצרים את קורפוס ה-RAG הראשון, נוצר חשבון השירות. אחרי שיוצרים את מאגר ה-RAG הראשון, יכול להיות שהשיוך בין מסד הנתונים של Weaviate לבין מפתח ה-API לא יהיה מוכן לשימוש ביצירה של מאגר RAG אחר.
אם מסד הנתונים והמפתח לא מוכנים לשיוך לקורפוס ה-RAG, מבצעים את הפעולות הבאות בקורפוס ה-RAG:
מגדירים את השדה
weaviateב-rag_vector_db_config.- אי אפשר לשנות את מסד הנתונים של הווקטורים המשויך.
- משאירים את השדות
http_endpointו-collection_nameריקים. אפשר לעדכן את שני השדות האלה מאוחר יותר.
אם מפתח ה-API לא מאוחסן ב-Secret Manager, אפשר להשאיר את השדה
api_authריק. כששולחים קריאה ל-API שלUpdateRagCorpus, אפשר לעדכן את השדהapi_auth. ב-Weaviate צריך לבצע את הפעולות הבאות:- מגדירים את
api_key_configבשדהapi_auth. מגדירים את
api_key_secret_versionשל מפתח ה-API של Weaviate ב-Secret Manager. השדהapi_key_secret_versionהוא בפורמט הבא:projects/{project}/secrets/{secret}/versions/{version}
- מגדירים את
אם אתם מציינים שדות שאפשר להגדיר רק פעם אחת, כמו
http_endpointאוcollection_name, אתם לא יכולים לשנות אותם אלא אם אתם מוחקים את מאגר הנתונים של RAG ויוצרים אותו מחדש. אפשר לעדכן שדות אחרים, כמו השדה של מפתח ה-API,api_key_secret_version.כשמפעילים את
UpdateRagCorpus, אפשר להגדיר את השדהvector_db. הערך שלvector_dbצריך להיות מוגדר כ-weaviateעל ידי הקריאה ל-API שלCreateRagCorpus. אחרת, המערכת בוחרת באפשרות RAG Managed Database, שהיא ברירת המחדל. אי אפשר לשנות את האפשרות הזו כששולחים קריאה ל-API שלUpdateRagCorpus. כשמפעילים אתUpdateRagCorpusוהשדהvector_dbמוגדר באופן חלקי, אפשר לעדכן את השדות שמסומנים כניתנים לשינוי (נקראים גם mutable).
בטבלה הזו מפורטים WeaviateConfig השדות הניתנים לשינוי והשדות שלא ניתנים לשינוי שבהם נעשה שימוש בקוד.
| שם השדה | ניתן לשינוי או לא ניתן לשינוי |
|---|---|
http_endpoint |
אי אפשר לשנות את ההגדרה אחרי שקובעים אותה |
collection_name |
אי אפשר לשנות את ההגדרה אחרי שקובעים אותה |
api_key_authentication |
ניתן לשינוי |
יצירת קורפוס ה-RAG הראשון
אם חשבון השירות של RAG Engine לא קיים:
- יוצרים קורפוס RAG ב-RAG Engine עם הגדרת Weaviate ריקה, שמתחילה את הקצאת המשאבים של RAG Engine כדי ליצור חשבון שירות.
- בוחרים שם לחשבון השירות של RAG Engine בפורמט הבא:
service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.comלדוגמה,
service-123456789@gcp-sa-vertex-rag.iam.gserviceaccount.com. - באמצעות חשבון השירות, ניגשים לסוד שמאוחסן ב-Secret Manager של הפרויקט, שמכיל את מפתח ה-API של Weaviate.
- אחרי שההקצאה של Weaviate מסתיימת, צריך לקבל את הפרטים הבאים:
- נקודת הקצה (endpoint) של Weaviate ב-HTTPS או ב-HTTP.
- שם האוסף ב-Weaviate.
- מפעילים את ה-API של
CreateRagCorpusכדי ליצור קורפוס RAG עם הגדרת Weaviate ריקה, ומפעילים את ה-API שלUpdateRagCorpusכדי לעדכן את קורפוס ה-RAG עם הפרטים הבאים:- נקודת הקצה (endpoint) של Weaviate ב-HTTPS או ב-HTTP.
- שם האוסף ב-Weaviate.
- שם המשאב של מפתח ה-API.
יצירת קורפוס RAG נוסף
אחרי שחשבון השירות של RAG Engine נוצר:
- מאתרים את חשבון השירות של RAG Engine בהרשאות של הפרויקט.
- מפעילים את האפשרות "Include Google-provided role grants" (הצגת תפקידים שניתנו על ידי Google).
- בוחרים שם לחשבון השירות של RAG Engine בפורמט הבא:
service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.com - באמצעות חשבון השירות, ניגשים לסוד שמאוחסן ב-Secret Manager של הפרויקט, שמכיל את מפתח ה-API של Weaviate.
- במהלך ההקצאה של Weaviate, צריך לקבל את הפרטים הבאים:
- נקודת הקצה (endpoint) של Weaviate ב-HTTPS או ב-HTTP.
- שם האוסף ב-Weaviate.
- יוצרים קורפוס RAG ב-RAG Engine ומקשרים אותו לאוסף ב-Weaviate באחת מהדרכים הבאות:
- שולחים קריאה ל-API של
CreateRagCorpusכדי ליצור קורפוס RAG עם הגדרת Weaviate מאוכלסת, שהיא האפשרות המועדפת. - מבצעים קריאה ל-API של
CreateRagCorpusכדי ליצור קורפוס RAG עם הגדרת Weaviate ריקה, ומבצעים קריאה ל-API שלUpdateRagCorpusכדי לעדכן את קורפוס ה-RAG עם הפרטים הבאים:- נקודת קצה (endpoint) ב-HTTP של מסד נתונים ב-Weaviate
- שם האוסף ב-Weaviate
- מפתח API
- שולחים קריאה ל-API של
דוגמאות
בקטע הזה מוצג קוד לדוגמה שממחיש איך להגדיר את מסד הנתונים של Weaviate, את Secret Manager, את קורפוס ה-RAG ואת קובץ ה-RAG. בנוסף, יש קוד לדוגמה שמראה איך לייבא קבצים, לאחזר הקשר, ליצור תוכן ולמחוק את מאגר הנתונים והקבצים של RAG.
כדי להשתמש ב-notebook של Model Garden RAG API, קראו את המאמר שימוש ב-Weaviate עם Llama 3.
הגדרת מסד הנתונים של Weaviate
דוגמת הקוד הזו ממחישה איך להגדיר את הנתונים של Weaviate ואת Secret Manager.
REST
# TODO(developer): Update the variables.
# The HTTPS/HTTP Weaviate endpoint you created during provisioning.
HTTP_ENDPOINT_NAME="https://your.weaviate.endpoint.com"
# Your Weaviate API Key.
WEAVIATE_API_KEY="example-api-key"
# Select your Weaviate collection name, which roughly corresponds to a Agent Platform Knowledge Engine Corpus.
# For example, "MyCollectionName"
# Note that the first letter needs to be capitalized.
# Otherwise, Weavaite will capitalize it for you.
WEAVIATE_COLLECTION_NAME="MyCollectionName"
# Create a collection in Weaviate which includes the required schema fields shown below.
echo '{
"class": "'${WEAVIATE_COLLECTION_NAME}'",
"properties": [
{ "name": "fileId", "dataType": [ "string" ] },
{ "name": "corpusId", "dataType": [ "string" ] },
{ "name": "chunkId", "dataType": [ "string" ] },
{ "name": "chunkDataType", "dataType": [ "string" ] },
{ "name": "chunkData", "dataType": [ "string" ] },
{ "name": "fileOriginalUri", "dataType": [ "string" ] }
]
}' | curl \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer "${WEAVIATE_API_KEY} \
-d @- \
${HTTP_ENDPOINT_NAME}/v1/schema
הגדרת Secret Manager
כדי להגדיר את Secret Manager, צריך להפעיל אותו ולהגדיר הרשאות.
יצירת סוד
כדי להפעיל את Secret Manager:
המסוף
נכנסים לדף Secret Manager.
לוחצים על + Create Secret.
מזינים את ה-Name של הסוד. שמות של סודות יכולים להכיל רק אותיות באנגלית (A-Z), מספרים (0-9), מקפים (-) וקווים תחתונים (_).
השדות הבאים הם אופציונליים:
- כדי להעלות את הקובץ עם הסוד, לוחצים על Browse.
- המדיניות בנושא שכפול
- אם רוצים לנהל באופן ידני את המיקומים של הסוד, מסמנים את האפשרות Manually manage locations for this secret. צריך לבחור לפחות אזור אחד.
- בוחרים את אפשרות ההצפנה.
- אם רוצים להגדיר ידנית את תקופת הרוטציה, מסמנים את האפשרות Set rotation period.
- אם רוצים לציין נושאים לפרסום או להרשמה כדי לקבל התראות על אירועים, לוחצים על הוספת נושאים.
- כברירת מחדל, לסוד אין תאריך תפוגה. אם רוצים להגדיר תאריך תפוגה, מסמנים את האפשרות הגדרת תאריך תפוגה.
- כברירת מחדל, גרסאות של סודות מושמדות לפי בקשה. כדי לעכב את ההשמדה של גרסאות סודיות, מסמנים את האפשרות Set duration for delayed destruction.
- אם רוצים להשתמש בתוויות כדי לארגן ולסווג את הסודות, לוחצים על + Add label.
- אם רוצים להשתמש בהערות כדי לצרף לסודות מטא-נתונים לא מזהים, לוחצים על + Add annotation.
לוחצים על Create secret.
REST
# Create a secret in SecretManager.
curl "https://secretmanager.googleapis.com/v1/projects/${PROJECT_ID}/secrets?secretId=${SECRET_NAME}" \
--request "POST" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json" \
--data "{\"replication\": {\"automatic\": {}}}"
Python
לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python שמפורטות במאמר התחלה מהירה של Agent Platform באמצעות ספריות לקוח.
כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
הגדרת ההרשאות
אתם צריכים לתת לחשבון השירות הרשאות ל-Secret Manager.
המסוף
בקטע IAM & Admin במסוף Google Cloud , מוצאים את חשבון השירות ולוחצים על סמל העיפרון כדי לערוך אותו.
בשדה Role, בוחרים באפשרות Secret Manager Secret Accessor.
Python
לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python שמפורטות במאמר התחלה מהירה של Agent Platform באמצעות ספריות לקוח.
כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
הוספת גרסת סוד
REST
# TODO(developer): Update the variables.
# Select a resource name for your Secret, which contains your API Key.
SECRET_NAME="MyWeaviateApiKeySecret"
# Your Weaviate API Key.
WEAVIATE_API_KEY="example-api-key"
# Encode your WEAVIATE_API_KEY using base 64.
SECRET_DATA=$(echo ${WEAVIATE_API_KEY} | base64)
# Create a new version of your secret which uses SECRET_DATA as payload
curl "https://secretmanager.googleapis.com/v1/projects/${PROJECT_ID}/secrets/${SECRET_NAME}:addVersion" \
--request "POST" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json" \
--data "{\"payload\": {\"data\": \"${SECRET_DATA}\"}}"
Python
לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python שמפורטות במאמר התחלה מהירה של Agent Platform באמצעות ספריות לקוח.
כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
שימוש ב-Weaviate עם Llama 3
ב-notebook של Model Garden RAG API מוסבר איך להשתמש ב-Agent Platform SDK ל-Python עם קורפוס של Weaviate ומודל Llama 3. כדי להשתמש ב-notebook, צריך:
משתמשים ב-Model Garden RAG API notebook.
יצירת קורפוס RAG
דוגמת הקוד הזו ממחישה איך ליצור קורפוס RAG ולהגדיר את המכונה של Weaviate כמסד הנתונים של הווקטורים.
REST
# TODO(developer): Update the variables.
PROJECT_ID = "YOUR_PROJECT_ID"
# The HTTPS/HTTP Weaviate endpoint you created during provisioning.
HTTP_ENDPOINT_NAME="https://your.weaviate.endpoint.com"
# Your Weaviate collection name, which roughly corresponds to a Agent Platform Knowledge Engine Corpus.
# For example, "MyCollectionName"
# Note that the first letter needs to be capitalized.
# Otherwise, Weaviate will capitalize it for you.
WEAVIATE_COLLECTION_NAME="MyCollectionName"
# The resource name of your Weaviate API Key your Secret.
SECRET_NAME="MyWeaviateApiKeySecret"
# The Secret Manager resource name containing the API Key for your Weaviate endpoint.
# For example, projects/{project}/secrets/{secret}/versions/latest
APIKEY_SECRET_VERSION="projects/${PROJECT_ID}/secrets/${SECRET_NAME}/versions/latest"
# Select a Corpus display name.
CORPUS_DISPLAY_NAME="SpecialCorpus"
# Call CreateRagCorpus API and set all Vector DB Config parameters for Weaviate to create a new corpus associated to your selected Weaviate collection.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora \
-d '{
"display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
"rag_vector_db_config" : {
"weaviate": {
"http_endpoint": '\""${HTTP_ENDPOINT_NAME}"\"',
"collection_name": '\""${WEAVIATE_COLLECTION_NAME}"\"'
},
"api_auth" : {
"api_key_config": {
"api_key_secret_version": '\""${APIKEY_SECRET_VERSION}"\"'
}
}
}
}'
# TODO(developer): Update the variables.
# Get operation_id returned in CreateRagCorpus.
OPERATION_ID="your-operation-id"
# Poll Operation status until done = true in the response.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}
# Call ListRagCorpora API to verify the RAG corpus is created successfully.
curl -sS -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora"
Python
לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python שמפורטות במאמר התחלה מהירה של Agent Platform באמצעות ספריות לקוח.
כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
שימוש בקובץ RAG
RAG API מטפל בהעלאה, בייבוא, בהצגה ובמחיקה של קבצים.
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- RAG_CORPUS_ID: המזהה של המשאב
RagCorpus. - INPUT_FILE: הנתיב של קובץ מקומי.
- FILE_DISPLAY_NAME: השם המוצג של
RagFile. - RAG_FILE_DESCRIPTION: התיאור של
RagFile.
ה-method של ה-HTTP וכתובת ה-URL:
POST https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/media:upload
גוף בקשת JSON:
{
"rag_file": {
"display_name": "FILE_DISPLAY_NAME",
"description": "RAG_FILE_DESCRIPTION"
}
}
כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:
curl
שומרים את גוף הבקשה בקובץ בשם INPUT_FILE ומריצים את הפקודה הבאה:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @INPUT_FILE \
"https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/media:upload"
PowerShell
שומרים את גוף הבקשה בקובץ בשם INPUT_FILE ומריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile INPUT_FILE `
-Uri "https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/media:upload" | Select-Object -Expand ContentRagFile. הרכיב האחרון בשדה RagFile.name הוא rag_file_id שנוצר על ידי השרת.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
ייבוא קובצי RAG
אפשר לייבא קבצים ותיקיות מ-Drive או מ-Cloud Storage.
REST
כדי לראות כשלים חלקיים, זמן בקשה וזמן תגובה באובייקט response של ה-SDK, משתמשים ב-response.metadata.
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- RAG_CORPUS_ID: המזהה של המשאב
RagCorpus. - GCS_URIS: רשימה של מיקומים ב-Cloud Storage. לדוגמה:
gs://my-bucket1, gs://my-bucket2. - DRIVE_RESOURCE_ID: המזהה של המשאב ב-Drive. דוגמאות:
https://drive.google.com/file/d/ABCDEhttps://drive.google.com/corp/drive/u/0/folders/ABCDEFG- DRIVE_RESOURCE_TYPE: סוג המשאב ב-Drive. אפשרויות:
RESOURCE_TYPE_FILE– קובץRESOURCE_TYPE_FOLDER– תיקייה- CHUNK_SIZE: אופציונלי: מספר הטוקנים שצריכים להיות בכל קטע.
- CHUNK_OVERLAP: אופציונלי: מספר הטוקנים שחופפים בין החלקים.
ה-method של ה-HTTP וכתובת ה-URL:
POST https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import
גוף בקשת JSON:
{
"import_rag_files_config": {
"gcs_source": {
"uris": GCS_URIS
},
"google_drive_source": {
"resource_ids": {
"resource_id": DRIVE_RESOURCE_ID,
"resource_type": DRIVE_RESOURCE_TYPE
},
}
}
}
כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:
curl
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import"
PowerShell
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import" | Select-Object -Expand ContentImportRagFilesOperationMetadata.
הדוגמה הבאה ממחישה איך לייבא קובץ מ-Cloud Storage. משתמשים בשדה הבקרה max_embedding_requests_per_min כדי להגביל את הקצב שבו מנוע ה-RAG קורא למודל ההטמעה במהלך תהליך ההוספה לאינדקס של ImportRagFiles. ערך ברירת המחדל של השדה הוא 1000 קריאות לדקה.
// Cloud Storage bucket/file location.
// Such as "gs://rag-e2e-test/"
GCS_URIS=YOUR_GCS_LOCATION
// Enter the QPM rate to limit RAG's access to your embedding model
// Example: 1000
EMBEDDING_MODEL_QPM_RATE=MAX_EMBEDDING_REQUESTS_PER_MIN_LIMIT
// ImportRagFiles
// Import a single Cloud Storage file or all files in a Cloud Storage bucket.
// Input: ENDPOINT, PROJECT_ID, RAG_CORPUS_ID, GCS_URIS
// Output: ImportRagFilesOperationMetadataNumber
// Use ListRagFiles to find the server-generated rag_file_id.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${ENDPOINT}/v1beta1/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": 512
},
"max_embedding_requests_per_min": '"${EMBEDDING_MODEL_QPM_RATE}"'
}
}'
// Poll the operation status.
// The response contains the number of files imported.
OPERATION_ID=OPERATION_ID
poll_op_wait ${OPERATION_ID}
בדוגמה הבאה אפשר לראות איך לייבא קובץ מ-Drive. משתמשים בשדה הבקרה max_embedding_requests_per_min כדי להגביל את הקצב שבו מנוע ה-RAG קורא למודל ההטמעה במהלך תהליך ההוספה לאינדקס של ImportRagFiles. ערך ברירת המחדל של השדה הוא 1000 קריאות לדקה.
// Google Drive folder location.
FOLDER_RESOURCE_ID=YOUR_GOOGLE_DRIVE_FOLDER_RESOURCE_ID
// Enter the QPM rate to limit RAG's access to your embedding model
// Example: 1000
EMBEDDING_MODEL_QPM_RATE=MAX_EMBEDDING_REQUESTS_PER_MIN_LIMIT
// ImportRagFiles
// Import all files in a Google Drive folder.
// Input: ENDPOINT, PROJECT_ID, RAG_CORPUS_ID, FOLDER_RESOURCE_ID
// Output: ImportRagFilesOperationMetadataNumber
// Use ListRagFiles to find the server-generated rag_file_id.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${ENDPOINT}/v1beta1/projects/${PROJECT_ID}/locations/${LOCATION}/ragCorpora/${RAG_CORPUS_ID}/ragFiles:import \
-d '{
"import_rag_files_config": {
"google_drive_source": {
"resource_ids": {
"resource_id": '\""${FOLDER_RESOURCE_ID}"\"',
"resource_type": "RESOURCE_TYPE_FOLDER"
}
},
"max_embedding_requests_per_min": '"${EMBEDDING_MODEL_QPM_RATE}"'
}
}'
// Poll the operation status.
// The response contains the number of files imported.
OPERATION_ID=OPERATION_ID
poll_op_wait ${OPERATION_ID}
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
איך מקבלים קובץ RAG
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- RAG_CORPUS_ID: המזהה של המשאב
RagCorpus. - RAG_FILE_ID: המזהה של המשאב
RagFile.
ה-method של ה-HTTP וכתובת ה-URL:
GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID
כדי לשלוח את הבקשה אתם צריכים לבחור אחת מהאפשרויות הבאות:
curl
מריצים את הפקודה הבאה:
curl -X GET \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID"
PowerShell
מריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID" | Select-Object -Expand ContentRagFile.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
הצגת רשימה של קובצי RAG
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- RAG_CORPUS_ID: המזהה של המשאב
RagCorpus. - PAGE_SIZE: גודל הדף הסטנדרטי של הרשימה. אפשר לשנות את מספר הפריטים מסוג
RagFilesשיוחזרו בכל דף על ידי עדכון הפרמטרpage_size. - PAGE_TOKEN: אסימון הדף הרגיל של הרשימה. בדרך כלל מתקבל באמצעות
ListRagFilesResponse.next_page_tokenשל הקריאה הקודמת שלVertexRagDataService.ListRagFiles.
ה-method של ה-HTTP וכתובת ה-URL:
GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN
כדי לשלוח את הבקשה אתם צריכים לבחור אחת מהאפשרויות הבאות:
curl
מריצים את הפקודה הבאה:
curl -X GET \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN"
PowerShell
מריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN" | Select-Object -Expand ContentRagFiles ב-RAG_CORPUS_ID שצוין.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
מחיקת קובץ RAG
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- RAG_CORPUS_ID: המזהה של המשאב
RagCorpus. - RAG_FILE_ID: המזהה של המשאב
RagFile. פורמט:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}/ragFiles/{rag_file_id}.
ה-method של ה-HTTP וכתובת ה-URL:
DELETE https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID
כדי לשלוח את הבקשה אתם צריכים לבחור אחת מהאפשרויות הבאות:
curl
מריצים את הפקודה הבאה:
curl -X DELETE \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID"
PowerShell
מריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID" | Select-Object -Expand ContentDeleteOperationMetadata.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
אחזור הקשר
כשמשתמש שואל שאלה או מזין הנחיה, רכיב האחזור ב-RAG מחפש במאגר הידע שלו מידע שרלוונטי לשאילתה.
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- LOCATION: האזור שבו הבקשה תעובד.
- PROJECT_ID: .
- RAG_CORPUS_RESOURCE: השם של המשאב ב-
RagCorpus. פורמט:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}. - VECTOR_DISTANCE_THRESHOLD: המערכת מחזירה רק הקשרים עם מרחק וקטורי קטן מהסף.
- TEXT: טקסט השאילתה כדי לקבל הקשרים רלוונטיים.
- SIMILARITY_TOP_K: מספר ההקשרים המובילים לאחזור.
ה-method של ה-HTTP וכתובת ה-URL:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts
גוף בקשת JSON:
{
"vertex_rag_store": {
"rag_resources": {
"rag_corpus": "RAG_CORPUS_RESOURCE",
},
"vector_distance_threshold": 0.8
},
"query": {
"text": "TEXT",
"similarity_top_k": SIMILARITY_TOP_K
}
}
כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:
curl
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts"
PowerShell
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts" | Select-Object -Expand ContentRagFiles קשורים.
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
יוצר תוכן
החיזוי שולט בשיטת ה-LLM שיוצרת תוכן.
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: .
- LOCATION: האזור שבו הבקשה תעובד.
- MODEL_ID: מודל LLM ליצירת תוכן. לדוגמה:
gemini-3.5-flash - GENERATION_METHOD: שיטת LLM ליצירת תוכן. אפשרויות:
generateContent,streamGenerateContent - INPUT_PROMPT: הטקסט שנשלח למודל ה-LLM ליצירת תוכן. נסו להשתמש בהנחיה שרלוונטית לקובצי ה-RAG שהעליתם.
- RAG_CORPUS_RESOURCE: השם של המשאב ב-
RagCorpus. פורמט:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}. - SIMILARITY_TOP_K: אופציונלי: מספר ההקשרים המובילים שרוצים לאחזר.
- VECTOR_DISTANCE_THRESHOLD: אופציונלי: מוחזרים הקשרים עם מרחק וקטורי קטן מהסף.
ה-method של ה-HTTP וכתובת ה-URL:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD
גוף בקשת JSON:
{
"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
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD"
PowerShell
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD" | Select-Object -Expand ContentPython
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
חיפוש היברידי
חיפוש היברידי נתמך במסד הנתונים של Weaviate, שמשלב חיפושים סמנטיים וחיפושים לפי מילות מפתח כדי לשפר את הרלוונטיות של תוצאות החיפוש. במהלך אחזור תוצאות החיפוש, שילוב של ציוני דמיון מסמנטיקה (וקטור צפוף) והתאמה למילות מפתח (וקטור דליל) מפיק את התוצאות הסופיות המדורגות.
חיפוש היברידי באמצעות ה-API לאחזור של RAG Engine
בדוגמה הבאה מוסבר איך להפעיל חיפוש היברידי באמצעות ה-API לאחזור של RAG Engine.
REST
# TODO(developer): Update the variables.
PROJECT_ID = "YOUR_PROJECT_ID"
# The HTTPS/HTTP Weaviate endpoint you created during provisioning.
HTTP_ENDPOINT_NAME="https://your.weaviate.endpoint.com"
# Your Weaviate collection name, which roughly corresponds to a Agent Platform Knowledge Engine Corpus.
# For example, "MyCollectionName"
# Note that the first letter needs to be capitalized.
# Otherwise, Weaviate will capitalize it for you.
WEAVIATE_COLLECTION_NAME="MyCollectionName"
# The resource name of your Weaviate API Key your Secret.
SECRET_NAME="MyWeaviateApiKeySecret"
# The Secret Manager resource name containing the API Key for your Weaviate endpoint.
# For example, projects/{project}/secrets/{secret}/versions/latest
APIKEY_SECRET_VERSION="projects/${PROJECT_ID}/secrets/${SECRET_NAME}/versions/latest"
# Select a Corpus display name.
CORPUS_DISPLAY_NAME="SpecialCorpus"
# Call CreateRagCorpus API and set all Vector DB Config parameters for Weaviate to create a new corpus associated to your selected Weaviate collection.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora \
-d '{
"display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
"rag_vector_db_config" : {
"weaviate": {
"http_endpoint": '\""${HTTP_ENDPOINT_NAME}"\"',
"collection_name": '\""${WEAVIATE_COLLECTION_NAME}"\"'
},
"api_auth" : {
"api_key_config": {
"api_key_secret_version": '\""${APIKEY_SECRET_VERSION}"\"'
}
}
}
}'
# TODO(developer): Update the variables.
# Get operation_id returned in CreateRagCorpus.
OPERATION_ID="your-operation-id"
# Poll Operation status until done = true in the response.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}
# Call ListRagCorpora API to verify the RAG corpus is created successfully.
curl -sS -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora"
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.
שימוש בחיפוש היברידי וב-RAG Engine ליצירת תשובות מעוגנות
זו דוגמה לשימוש בחיפוש היברידי וב-RAG Engine ליצירת תשובות מבוססות-קרקע.
REST
# TODO(developer): Update the variables.
PROJECT_ID = "YOUR_PROJECT_ID"
# The HTTPS/HTTP Weaviate endpoint you created during provisioning.
HTTP_ENDPOINT_NAME="https://your.weaviate.endpoint.com"
# Your Weaviate collection name, which roughly corresponds to a Agent Platform Knowledge Engine Corpus.
# For example, "MyCollectionName"
# Note that the first letter needs to be capitalized.
# Otherwise, Weaviate will capitalize it for you.
WEAVIATE_COLLECTION_NAME="MyCollectionName"
# The resource name of your Weaviate API Key your Secret.
SECRET_NAME="MyWeaviateApiKeySecret"
# The Secret Manager resource name containing the API Key for your Weaviate endpoint.
# For example, projects/{project}/secrets/{secret}/versions/latest
APIKEY_SECRET_VERSION="projects/${PROJECT_ID}/secrets/${SECRET_NAME}/versions/latest"
# Select a Corpus display name.
CORPUS_DISPLAY_NAME="SpecialCorpus"
# Call CreateRagCorpus API and set all Vector DB Config parameters for Weaviate to create a new corpus associated to your selected Weaviate collection.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora \
-d '{
"display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
"rag_vector_db_config" : {
"weaviate": {
"http_endpoint": '\""${HTTP_ENDPOINT_NAME}"\"',
"collection_name": '\""${WEAVIATE_COLLECTION_NAME}"\"'
},
"api_auth" : {
"api_key_config": {
"api_key_secret_version": '\""${APIKEY_SECRET_VERSION}"\"'
}
}
}
}'
# TODO(developer): Update the variables.
# Get operation_id returned in CreateRagCorpus.
OPERATION_ID="your-operation-id"
# Poll Operation status until done = true in the response.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}
# Call ListRagCorpora API to verify the RAG corpus is created successfully.
curl -sS -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora"
Python
במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.