Per semplificare la transizione dalla ricerca vettoriale 1.0, è stata introdotta una nuova funzionalità nell'API ImportDataObjects.
Il processo di migrazione prevede tre passaggi chiave:
Crea una raccolta con uno schema corrispondente. Prima dell'importazione, devi creare una raccolta. Il suo schema di dati deve essere strutturato per ospitare i dati trasformati di Vector Search 1.0.
Avvia il processo di importazione. Chiama l'API
ImportDataObjects, specificando la posizione Cloud Storage dei dati di Vector Search 1.0 e attivando il flag di conversionedetect_and_convert_vs1_json.Comprendere la trasformazione dei dati. Acquisisci familiarità con il modo in cui i campi di dati di Vector Search 1.0 vengono mappati alla nuova struttura dell'oggetto dati.
Creare una raccolta
Per prima cosa, crea una raccolta con uno schema dei dati che rispecchi la struttura dei dati di Vector Search 1.0.
curl -X POST \
'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections?collection_id=movies' \
-H 'Bearer $(gcloud auth print-access-token)' \
-H 'Content-Type: application/json' \
-d '{ \
"data_schema": { \
"$schema": "http://json-schema.org/draft-07/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": {} \
} \
} \
}'
Importare i dati di Vector Search 1.0
Dopodiché, utilizza l'API ImportDataObjects nella raccolta appena creata.
Punta al bucket Cloud Storage contenente i dati di Ricerca vettoriale 1.0.
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/" \
} \
}'
Trasformazione dei dati
Durante la procedura di importazione, i dati di Vector Search 1.0 verranno trasformati in oggetti dati di Vector Search 2.0. I seguenti esempi illustrano come vengono mappati i campi.
Formato file Cloud Storage di Ricerca vettoriale 1.0
{
"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": "..."
}
}
Oggetto dati Ricerca vettoriale 2.0 trasformata
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]}},
}
)