์ด ํ์ด์ง์์๋ Vertex AI RAG Engine์ Vertex AI ๋ฒกํฐ ๊ฒ์์ ์ฐ๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
์ด ๋ ธํธ๋ถ Vertex AI ๋ฒกํฐ ๊ฒ์์ ์ฌ์ฉํ Vertex AI RAG Engine์ ์ฌ์ฉํ์ฌ ๋ฐ๋ผํ ์๋ ์์ต๋๋ค.
Vertex AI RAG Engine์ Spanner๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ๊ธฐ๋ณธ ์ ๊ณต ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ ๋ฌธ์์ ๋ฒกํฐ ํํ์ ์ ์ฅํ๊ณ ๊ด๋ฆฌํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ ๋๋ค. ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉํ๋ฉด ํน์ ์ฟผ๋ฆฌ์ ๋ํ ๋ฌธ์์ ์๋งจํฑ ์ ์ฌ์ฑ์ ๊ธฐ๋ฐ์ผ๋ก ๊ด๋ จ ๋ฌธ์๋ฅผ ํจ์จ์ ์ผ๋ก ๊ฒ์ํ ์ ์์ต๋๋ค. Vertex AI ๋ฒกํฐ ๊ฒ์์ Vertex AI RAG Engine์ ์ถ๊ฐ ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ก ํตํฉํ๋ฉด ๋ฒกํฐ ๊ฒ์์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ์ฌ ์งง์ ์ง์ฐ ์๊ฐ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ์ฌ RAG ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฑ๋ฅ๊ณผ ํ์ฅ์ฑ์ ๊ฐ์ ํ ์ ์์ต๋๋ค.
Vertex AI ๋ฒกํฐ ๊ฒ์ ์ค์
Vertex AI ๋ฒกํฐ ๊ฒ์์ Google ์ฐ๊ตฌํ์์ ๊ฐ๋ฐํ ๋ฒกํฐ ๊ฒ์ ๊ธฐ์ ์ ๊ธฐ๋ฐ์ผ๋ก ํฉ๋๋ค. ๋ฒกํฐ ๊ฒ์์ ์ฌ์ฉํ๋ฉด Google ๊ฒ์, YouTube, Google Play์ ๊ฐ์ Google ์ ํ์ ๊ธฐ๋ฐ์ด ๋๋ ๋์ผํ ์ธํ๋ผ๋ฅผ ํ์ฉํ ์ ์์ต๋๋ค.
Vertex AI RAG Engine๊ณผ ํตํฉํ๋ ค๋ฉด ๋น ๋ฒกํฐ ๊ฒ์ ์์ธ์ด ํ์ํฉ๋๋ค.
Vertex AI SDK ์ค์
Vertex AI SDK๋ฅผ ์ค์ ํ๋ ค๋ฉด ์ค์ ์ ์ฐธ๊ณ ํ์ธ์.
๋ฒกํฐ ๊ฒ์ ์์ธ ๋ง๋ค๊ธฐ
RAG ์ฝํผ์ค์ ํธํ๋๋ ๋ฒกํฐ ๊ฒ์ ์์ธ์ ๋ง๋ค๋ ค๋ฉด ์์ธ์ด ๋ค์ ๊ธฐ์ค์ ์ถฉ์กฑํด์ผ ํฉ๋๋ค.
IndexUpdateMethod
๋STREAM_UPDATE
์ฌ์ผ ํฉ๋๋ค. ์คํธ๋ฆผ ์์ธ ๋ง๋ค๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์ธ์.๊ฑฐ๋ฆฌ ์ธก์ ์ ํ์ ๋ค์ ์ค ํ๋๋ก ๋ช ์์ ์ผ๋ก ์ค์ ํด์ผ ํฉ๋๋ค.
DOT_PRODUCT_DISTANCE
COSINE_DISTANCE
๋ฒกํฐ์ ์ฐจ์์ RAG ์ฝํผ์ค์ ์ฌ์ฉํ ์๋ฒ ๋ฉ ๋ชจ๋ธ๊ณผ ์ผ์นํด์ผ ํฉ๋๋ค. ์ถ๊ฐ ํ๋ผ๋ฏธํฐ๋ฅผ ์กฐ์ ํ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ ์ ํ์ฌํญ์ ๋ฐ๋ผ ๋ค๋ฅธ ํ๋ผ๋ฏธํฐ๋ฅผ ์กฐ์ ํ ์ ์์ต๋๋ค.
Python์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
๋ฒกํฐ ๊ฒ์ ์์ธ ์๋ํฌ์ธํธ ๋ง๋ค๊ธฐ
๊ณต๊ฐ ์๋ํฌ์ธํธ๋ Vertex AI RAG Engine์์ ์ง์๋ฉ๋๋ค.
Python์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
์์ธ ์๋ํฌ์ธํธ์ ์์ธ ๋ฐฐํฌ
์ต๊ทผ์ ์ด์ ๊ฒ์์ ์ํํ๊ธฐ ์ ์ ์์ธ์ ์์ธ ์๋ํฌ์ธํธ์ ๋ฐฐํฌํด์ผ ํฉ๋๋ค.
Python์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
์์ธ์ ์์ธ ์๋ํฌ์ธํธ์ ์ฒ์ ๋ฐฐํฌํ๋ ๊ฒฝ์ฐ ์์ธ์ ์ ์ฅํ๊ธฐ ์ ์ ๋ฐฑ์๋๋ฅผ ์๋์ผ๋ก ๋น๋ํ๊ณ ์์ํ๋ ๋ฐ ์ฝ 30๋ถ์ด ๊ฑธ๋ฆฝ๋๋ค. ์ฒซ ๋ฒ์งธ ๋ฐฐํฌ ํ ๋ช ์ด ๋ด์ ์์ธ์ด ์ค๋น๋ฉ๋๋ค. ์์ธ ๋ฐฐํฌ ์ํ๋ฅผ ๋ณด๋ ค๋ฉด ๋ฒกํฐ ๊ฒ์ ์ฝ์์ ์ด๊ณ ์์ธ ์๋ํฌ์ธํธ ํญ์ ์ ํํ ๋ค์ ์์ธ ์๋ํฌ์ธํธ๋ฅผ ์ ํํฉ๋๋ค.
์์ธ ๋ฐ ์์ธ ์๋ํฌ์ธํธ์ ๋ฆฌ์์ค ์ด๋ฆ์ ์๋ณํฉ๋๋ค. ๋ฆฌ์์ค ์ด๋ฆ์ ํ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
projects/${PROJECT_ID}/locations/${LOCATION_ID}/indexes/${INDEX_ID}
projects/${PROJECT_ID}/locations/${LOCATION_ID}/indexEndpoints/${INDEX_ENDPOINT_ID}
.
Vertex AI RAG Engine์์ Vertex AI ๋ฒกํฐ ๊ฒ์ ์ฌ์ฉ
๋ฒกํฐ ๊ฒ์ ์ธ์คํด์ค๊ฐ ์ค์ ๋ ํ ์ด ์น์ ์ ๋จ๊ณ์ ๋ฐ๋ผ ๋ฒกํฐ ๊ฒ์ ์ธ์คํด์ค๋ฅผ RAG ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ก ์ค์ ํฉ๋๋ค.
๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ค์ ํ์ฌ RAG ์ฝํผ์ค ๋ง๋ค๊ธฐ
RAG ์ฝํผ์ค๋ฅผ ๋ง๋ค ๋๋ ์ ์ฒด INDEX_ENDPOINT_NAME
๋ฐ INDEX_NAME
๋ง ์ง์ ํฉ๋๋ค. ์์ธ ๋ฐ ์์ธ ์๋ํฌ์ธํธ ๋ฆฌ์์ค ์ด๋ฆ ๋ชจ๋์ ์ซ์ ID๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. RAG ์ฝํผ์ค๊ฐ ์์ฑ๋๊ณ ๋ฒกํฐ ๊ฒ์ ์์ธ๊ณผ ์๋์ผ๋ก ์ฐ๊ฒฐ๋ฉ๋๋ค. ๊ธฐ์ค์ ๋ํด ์ ํจ์ฑ ๊ฒ์ฌ๊ฐ ์ํ๋ฉ๋๋ค. ์๊ตฌ์ฌํญ ์ค ํ๋๋ผ๋ ์ถฉ์กฑ๋์ง ์์ผ๋ฉด ์์ฒญ์ด ๊ฑฐ๋ถ๋ฉ๋๋ค.
Python
์ด ์ํ์ ์ฌ์ฉํด ๋ณด๊ธฐ ์ ์ Vertex AI ๋น ๋ฅธ ์์: ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์ Python ์ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์. ์์ธํ ๋ด์ฉ์ Vertex AI Python API ์ฐธ๊ณ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์.
Vertex AI์ ์ธ์ฆํ๋ ค๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ๊ธฐ๋ณธ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ ์ค์ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ก์ปฌ ๊ฐ๋ฐ ํ๊ฒฝ์ ์ธ์ฆ ์ค์ ์ ์ฐธ์กฐํ์ธ์.
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_ID}/locations/${LOCATION_ID}/indexes/${INDEX_ID}
# IndexEndpoint: projects/${PROJECT_ID}/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_ID}/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_ID}/locations/${LOCATION_ID}/ragCorpora"
RAG API๋ฅผ ์ฌ์ฉํ์ฌ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ
ImportRagFiles
API๋ฅผ ์ฌ์ฉํ์ฌ Cloud Storage ๋๋ Google Drive์ ํ์ผ์ ๋ฒกํฐ ๊ฒ์ ์์ธ์ผ๋ก ๊ฐ์ ธ์ต๋๋ค. ํ์ผ์ ๋ฒกํฐ ๊ฒ์ ์์ธ์ ์ฝ์
๋์ด ์ ์ฅ๋ฉ๋๋ค.
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_ID}/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_ID}/locations/us-central1/ragCorpora/${RAG_CORPUS_ID}/ragFiles
Python์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
RAG API๋ฅผ ์ฌ์ฉํ์ฌ ๊ด๋ จ ์ปจํ ์คํธ ๊ฐ์ ธ์ค๊ธฐ
ํ์ผ ๊ฐ์ ธ์ค๊ธฐ๊ฐ ์๋ฃ๋๋ฉด RetrieveContexts
API๋ฅผ ์ฌ์ฉํ์ฌ ๋ฒกํฐ ๊ฒ์ ์์ธ์์ ๊ด๋ จ ์ปจํ
์คํธ๋ฅผ ๊ฒ์ํ ์ ์์ต๋๋ค.
REST
# TODO(developer): Update and uncomment the following lines:
# RETRIEVAL_QUERY="your-retrieval-query"
#
# Full RAG corpus resource name
# Format:
# "projects/${PROJECT_ID}/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_ID}/locations/us-central1:retrieveContexts \
-d '{
"vertex_rag_store": {
"rag_resources": {
"rag_corpus": '\""${RAG_CORPUS_RESOURCE}"\"',
},
},
"query": {
"text": '\""${RETRIEVAL_QUERY}"\"',
"similarity_top_k": 10
}
}'
Python์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
Vertex AI Gemini API๋ฅผ ์ฌ์ฉํ์ฌ ์ฝํ ์ธ ์์ฑ
Gemini ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ฝํ
์ธ ๋ฅผ ์์ฑํ๋ ค๋ฉด Vertex AI GenerateContent
API๋ฅผ ํธ์ถํฉ๋๋ค. ์์ฒญ์ RAG_CORPUS_RESOURCE
๋ฅผ ์ง์ ํ๋ฉด API๊ฐ ๋ฒกํฐ ๊ฒ์ ์์ธ์์ ๋ฐ์ดํฐ๋ฅผ ์๋์ผ๋ก ๊ฒ์ํฉ๋๋ค.
REST
# TODO(developer): Update and uncomment the following lines:
# MODEL_ID=gemini-2.0-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_ID}/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์ฉ Vertex AI SDK
Python์ฉ Vertex AI SDK๋ฅผ ์ค์นํ๊ฑฐ๋ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ Python์ฉ Vertex AI SDK ์ค์น๋ฅผ ์ฐธ์กฐํ์ธ์. ์์ธํ ๋ด์ฉ์ Python์ฉ Vertex AI SDK API ์ฐธ์กฐ ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.