Halaman ini menunjukkan cara menghubungkan Mesin RAG ke Penelusuran Vektor Gemini Enterprise Agent Platform.
Anda juga dapat mengikuti langkah-langkahnya menggunakan notebook RAG Engine dengan Agent Platform Penelusuran Vektor.
Penyiapan Penelusuran Vektor Agent Platform
Penelusuran Vektor Agent Platform didasarkan pada teknologi Penelusuran Vektor yang dikembangkan oleh Google Research. Dengan Penelusuran Vektor, Anda dapat menggunakan infrastruktur yang sama yang menyediakan fondasi untuk produk Google, seperti Google Penelusuran, YouTube, dan Google Play.
Untuk berintegrasi dengan RAG Engine, diperlukan indeks Penelusuran Vektor yang kosong.
Menyiapkan Vertex AI SDK
Untuk menyiapkan Vertex AI SDK, lihat Penyiapan.
Membuat indeks Penelusuran Vektor
Untuk membuat indeks Penelusuran Vektor yang kompatibel dengan Korpus RAG Anda, indeks harus memenuhi kriteria berikut:
IndexUpdateMethodharus berupaSTREAM_UPDATE, lihat Membuat indeks aliran data.Jenis pengukuran jarak harus ditetapkan secara eksplisit ke salah satu dari berikut ini:
DOT_PRODUCT_DISTANCECOSINE_DISTANCE
Dimensi vektor harus konsisten dengan model embedding yang ingin Anda gunakan dalam korpus RAG. Parameter lain dapat disesuaikan berdasarkan pilihan Anda, yang menentukan apakah parameter tambahan dapat disesuaikan.
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.
Membuat endpoint indeks Penelusuran Vektor
Endpoint publik didukung oleh RAG Engine.
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.
Men-deploy indeks ke endpoint indeks
Sebelum kita melakukan penelusuran tetangga terdekat, indeks harus di-deploy ke endpoint indeks.
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.
Jika ini adalah pertama kalinya Anda men-deploy indeks ke endpoint indeks, diperlukan waktu sekitar 30 menit untuk otomatis membangun dan memulai backend sebelum indeks dapat disimpan. Setelah deployment pertama, indeks akan siap dalam hitungan detik. Untuk melihat status deployment indeks, buka Vector Search Console, pilih tab Index endpoints, lalu pilih endpoint indeks Anda.
Identifikasi nama resource indeks dan endpoint indeks Anda, yang memiliki format berikut:
projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/indexes/${INDEX_ID}projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/indexEndpoints/${INDEX_ENDPOINT_ID}.
Menggunakan Penelusuran Vektor Agent Platform di Mesin RAG
Setelah instance Penelusuran Vektor disiapkan, ikuti langkah-langkah di bagian ini untuk menetapkan instance Penelusuran Vektor sebagai database vektor untuk aplikasi RAG.
Menetapkan database vektor untuk membuat korpus RAG
Saat Anda membuat korpus RAG, tentukan hanya INDEX_ENDPOINT_NAME dan INDEX_NAME lengkap. Pastikan untuk menggunakan ID numerik untuk nama resource indeks dan endpoint indeks. Korpus RAG dibuat dan otomatis dikaitkan dengan indeks Penelusuran Vektor. Validasi dilakukan pada
kriteria. Jika salah satu persyaratan tidak terpenuhi,
permintaan akan ditolak.
Python
Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di Panduan memulai Agent Platform menggunakan library klien.
Untuk melakukan autentikasi ke Agent Platform, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
REST
# TODO(developer): Update and un-comment the following lines:
# CORPUS_DISPLAY_NAME = "YOUR_CORPUS_DISPLAY_NAME"
# Full index/indexEndpoint resource name
# Index: projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/indexes/${INDEX_ID}
# IndexEndpoint: projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/indexEndpoints/${INDEX_ENDPOINT_ID}
# INDEX_RESOURCE_NAME = "YOUR_INDEX_ENDPOINT_RESOURCE_NAME"
# INDEX_NAME = "YOUR_INDEX_RESOURCE_NAME"
# Call CreateRagCorpus API to create a new RagCorpus
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://${LOCATION_ID}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/ragCorpora -d '{
"display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
"rag_vector_db_config" : {
"vertex_vector_search": {
"index":'\""${INDEX_NAME}"\"'
"index_endpoint":'\""${INDEX_ENDPOINT_NAME}"\"'
}
}
}'
# Call ListRagCorpora API to verify the RagCorpus is created successfully
curl -sS -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://${LOCATION_ID}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/locations/${LOCATION_ID}/ragCorpora"
Mengimpor file menggunakan RAG API
Gunakan metode API ragFiles.import
untuk mengimpor file dari Cloud Storage atau Google Drive ke
indeks Penelusuran Vektor. File disematkan dan disimpan dalam indeks Penelusuran Vektor.
REST
# TODO(developer): Update and uncomment the following lines:
# RAG_CORPUS_ID = "your-rag-corpus-id"
#
# Google Cloud Storage bucket/file location.
# For example, "gs://rag-fos-test/"
# GCS_URIS= "your-gcs-uris"
# Call ImportRagFiles API to embed files and store in the BigQuery table
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_NUMBER}/locations/us-central1/ragCorpora/${RAG_CORPUS_ID}/ragFiles:import \
-d '{
"import_rag_files_config": {
"gcs_source": {
"uris": '\""${GCS_URIS}"\"'
},
"rag_file_chunking_config": {
"chunk_size": 512
}
}
}'
# Call ListRagFiles API to verify the files are imported successfully
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/locations/us-central1/ragCorpora/${RAG_CORPUS_ID}/ragFiles
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.
Mengambil konteks yang relevan menggunakan RAG API
Setelah impor file selesai, konteks yang relevan dapat diambil dari indeks Penelusuran Vektor menggunakan RetrieveContexts API.
REST
# TODO(developer): Update and uncomment the following lines:
# RETRIEVAL_QUERY="your-retrieval-query"
#
# Full RAG corpus resource name
# Format:
# "projects/${PROJECT_NUMBER}/locations/us-central1/ragCorpora/${RAG_CORPUS_ID}"
# RAG_CORPUS_RESOURCE="your-rag-corpus-resource"
# Call RetrieveContexts API to retrieve relevant contexts
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/locations/us-central1:retrieveContexts \
-d '{
"vertex_rag_store": {
"rag_resources": {
"rag_corpus": '\""${RAG_CORPUS_RESOURCE}"\"',
},
},
"query": {
"text": '\""${RETRIEVAL_QUERY}"\"',
"similarity_top_k": 10
}
}'
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.
Membuat konten menggunakan Agent Platform Gemini API
Untuk membuat konten menggunakan model Gemini, lakukan panggilan ke API GenerateContent Agent Platform. Dengan menentukan
RAG_CORPUS_RESOURCE dalam permintaan, API akan otomatis mengambil data dari
indeks Penelusuran Vektor.
REST
# TODO(developer): Update and uncomment the following lines:
# MODEL_ID=gemini-2.5-flash
# GENERATE_CONTENT_PROMPT="your-generate-content-prompt"
# GenerateContent with contexts retrieved from the FeatureStoreOnline index
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_NUMBER}/locations/us-central1/publishers/google/models/${MODEL_ID}:generateContent \
-d '{
"contents": {
"role": "user",
"parts": {
"text": '\""${GENERATE_CONTENT_PROMPT}"\"'
}
},
"tools": {
"retrieval": {
"vertex_rag_store": {
"rag_resources": {
"rag_corpus": '\""${RAG_CORPUS_RESOURCE}"\"',
},
"similarity_top_k": 8,
"vector_distance_threshold": 0.32
}
}
}
}'
Python
Guna mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python.