Vector Search 1.0에서 원활하게 전환할 수 있도록 ImportDataObjects API에 새로운 기능이 도입되었습니다.
마이그레이션 프로세스는 세 가지 주요 단계로 이루어집니다.
일치하는 스키마로 컬렉션을 만듭니다. 가져오기 전에 컬렉션을 만들어야 합니다. 데이터 스키마는 변환된 Vector Search 1.0 데이터를 수용할 수 있도록 구조화되어야 합니다.
가져오기 프로세스를 시작합니다.
ImportDataObjectsAPI를 호출하여 Vector Search 1.0 데이터의 Cloud Storage 위치를 지정하고 변환 플래그detect_and_convert_vs1_json을 사용 설정합니다.데이터 변환 이해하기. Vector Search 1.0 데이터 필드가 새 데이터 객체 구조에 매핑되는 방식을 숙지하세요.
컬렉션 만들기
먼저 Vector Search 1.0 데이터의 구조를 반영하는 데이터 스키마로 컬렉션을 만듭니다.
REST
curl -X POST \
'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections?collection_id=COLLECTION_ID' \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H 'Content-Type: application/json' \
-d '{
"data_schema": {
"type": "object",
"properties": {
"restricts": {
"type": "object",
"properties": {
"genres": {
"type": "array",
"items": {
"type": "string"
}
},
"director": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"restricts_deny": {
"type": "object",
"properties": {
"genres": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"numeric_restricts": {
"type": "object",
"properties": {
"year": {
"type": "integer"
},
"imdb_rating": {
"type": "number",
"format": "float"
}
}
},
"embedding_metadata": {
"type": "object",
"properties": {
"plot": {
"type": "string"
},
"customers_review_summary": {
"type": "string"
},
"critics_review_summary": {
"type": "string"
}
},
}
}
},
"vector_schema": {
"embedding": {
"dense_vector": {
"dimensions": 768
}
},
"sparse_embedding": {
"sparse_vector": {}
}
}
}'
Python
from google.cloud import vectorsearch_v1beta
# Create the client
vector_search_service_client = vectorsearch_v1beta.VectorSearchServiceClient()
# The JSON schema for the data
data_schema = {
"type": "object",
"properties": {
"restricts": {
"type": "object",
"properties": {
"genres": {"type": "array", "items": {"type": "string"}},
"director": {"type": "array", "items": {"type": "string"}},
},
},
"restricts_deny": {
"type": "object",
"properties": {
"genres": {"type": "array", "items": {"type": "string"}}
},
},
"numeric_restricts": {
"type": "object",
"properties": {
"year": {"type": "integer"},
"imdb_rating": {"type": "number", "format": "float"},
},
},
"embedding_metadata": {
"type": "object",
"properties": {
"plot": {"type": "string"},
"customers_review_summary": {"type": "string"},
"critics_review_summary": {"type": "string"},
},
},
},
}
# The JSON schema for the vector
vector_schema = {
"embedding": {"dense_vector": {"dimensions": 768}},
"sparse_embedding": {"sparse_vector": {}},
}
collection = vectorsearch_v1beta.Collection(
data_schema=data_schema,
vector_schema=vector_schema,
)
request = vectorsearch_v1beta.CreateCollectionRequest(
parent="projects/PROJECT_ID/locations/LOCATION",
collection_id="COLLECTION_ID",
collection=collection,
)
# Create the collection
operation = vector_search_service_client.create_collection(request=request)
operation.result()
Vector Search 1.0 데이터 가져오기
그런 다음 새로 만든 컬렉션에서 ImportDataObjects API를 사용합니다.
Vector Search 1.0 데이터가 포함된 Cloud Storage 버킷을 지정합니다.
REST
curl -X POST \
"https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections/COLLECTION_ID:importDataObjects" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"gcs_import": {
"contents_uri": "gs://your-bucket/path/to/your-data.jsonl",
"error_uri": "gs://your-bucket/path/to/import-errors/"
}
}'
Python
from google.cloud import vectorsearch_v1beta
# Create the client
vector_search_service_client = vectorsearch_v1beta.VectorSearchServiceClient()
# Initialize request
request = vectorsearch_v1beta.ImportDataObjectsRequest(
name="projects/PROJECT_ID/locations/LOCATION/collections/COLLECTION_ID",
gcs_import={
"contents_uri": "gs://your-bucket/path/to/your-data.jsonl",
"error_uri": "gs://your-bucket/path/to/import-errors/",
},
)
# Make the request
operation = vector_search_service_client.import_data_objects(request=request)
# Wait for the result (note this may take up to several minutes)
operation.result()
데이터 변환
가져오기 프로세스 중에 Vector Search 1.0 데이터는 에이전트 검색 데이터 객체로 변환됩니다. 다음 예시는 필드가 매핑되는 방법을 보여줍니다.
Vector Search 1.0 Cloud Storage 파일 형식
{
"id": "movie-789",
"embedding": [-0.23, 0.88, 0.11, ...],
"sparse_embedding": {"values": [0.1, 0.2], "dimensions": [1, 4]},
"restricts": [
{"namespace": "genres", "allow": ["science-fiction", "action"], "deny": ["horror"]},
{"namespace": "director", "allow": ["Christopher Nolan"]}
],
"numeric_restricts": [
{"namespace": "year", "value_int": 2010},
{"namespace": "imdb_rating", "value_float": 8.8}
],
"embedding_metadata": {
"plot": "...",
"customers_review_summary": "...",
"critics_review_summary": "..."
}
}
변환된 에이전트 검색 데이터 객체
DataObject(
name="/.../movie-789",
data={
"restricts": {
"genres": ["science-fiction", "action"],
"director": ["Christopher Nolan"],
},
"restricts_deny": {
"genres": ["horror"]
},
"numeric_restricts": {
"year": 2010,
"imdb_rating": 8.8,
},
"embedding_metadata": {
"plot": "...",
"customers_review_summary": "...",
"critics_review_summary": "...",
}
},
vectors={
"embedding": {"dense_vector": {"values": [-0.23, 0.88, 0.11, ...]}},
"sparse_embedding": {"sparse_vector": {"values": [0.1, 0.2], "indices": [1, 4]}},
}
)