Kubernetes पर AlloyDB Omni और लोकल एआई मॉडल.

1. परिचय

इस कोडलैब में, आपको GKE पर AlloyDB Omni को डिप्लॉय करने और उसी Kubernetes क्लस्टर में डिप्लॉय किए गए ओपन एम्बेडिंग मॉडल के साथ इसका इस्तेमाल करने का तरीका पता चलेगा. एक ही GKE क्लस्टर में डेटाबेस इंस्टेंस के बगल में मॉडल को डिप्लॉय करने से, इंतज़ार का समय कम हो जाता है. साथ ही, तीसरे पक्ष की सेवाओं पर निर्भरता भी कम हो जाती है. इसके अलावा, सुरक्षा से जुड़ी ज़रूरी शर्तों के तहत भी ऐसा किया जा सकता है. ऐसा तब किया जाता है, जब डेटा को संगठन से बाहर नहीं भेजा जाना चाहिए और तीसरे पक्ष की सेवाओं का इस्तेमाल करने की अनुमति नहीं है.

391e4244b25a7db0.png

ज़रूरी शर्तें

  • Google Cloud Console के बारे में बुनियादी जानकारी
  • कमांड-लाइन इंटरफ़ेस और Cloud Shell की बुनियादी स्किल

आपको क्या सीखने को मिलेगा

  • Google Kubernetes क्लस्टर पर AlloyDB Omni को डिप्लॉय करने का तरीका
  • AlloyDB Omni से कनेक्ट करने का तरीका
  • AlloyDB Omni में डेटा लोड करने का तरीका
  • GKE में ओपन एम्बेडिंग मॉडल को डिप्लॉय करने का तरीका
  • AlloyDB Omni में एम्बेडिंग मॉडल को रजिस्टर करने का तरीका
  • सेमैनटिक सर्च के लिए एम्बेड जनरेट करने का तरीका
  • AlloyDB Omni में, सिमेंटिक सर्च के लिए जनरेट किए गए एम्बेड का इस्तेमाल करने का तरीका
  • AlloyDB में वेक्टर इंडेक्स बनाने और उनका इस्तेमाल करने का तरीका

आपको इन चीज़ों की ज़रूरत होगी

  • Google Cloud खाता और Google Cloud प्रोजेक्ट
  • Google Cloud Console और Cloud Shell के साथ काम करने वाला वेब ब्राउज़र, जैसे कि Chrome

2. सेटअप और ज़रूरी शर्तें

अपने हिसाब से एनवायरमेंट सेट अप करना

  1. Google Cloud Console में साइन इन करें और नया प्रोजेक्ट बनाएं या किसी मौजूदा प्रोजेक्ट का फिर से इस्तेमाल करें. अगर आपके पास पहले से कोई Gmail या Google Workspace खाता नहीं है, तो आपको एक खाता बनाना होगा.

fbef9caa1602edd0.png

a99b7ace416376c4.png

5e3ff691252acf41.png

  • प्रोजेक्ट का नाम, इस प्रोजेक्ट में हिस्सा लेने वाले लोगों के लिए डिसप्ले नेम होता है. यह एक वर्ण स्ट्रिंग है, जिसका इस्तेमाल Google API नहीं करते. इसे कभी भी अपडेट किया जा सकता है.
  • प्रोजेक्ट आईडी, Google Cloud के सभी प्रोजेक्ट के लिए यूनीक होता है. साथ ही, इसे सेट करने के बाद बदला नहीं जा सकता. Cloud Console, अपने-आप एक यूनीक स्ट्रिंग जनरेट करता है. आम तौर पर, आपको यह जानने की ज़रूरत नहीं होती कि यह स्ट्रिंग क्या है. ज़्यादातर कोडलैब में, आपको अपने प्रोजेक्ट आईडी का रेफ़रंस देना होगा. आम तौर पर, इसे PROJECT_ID के तौर पर पहचाना जाता है. अगर आपको जनरेट किया गया आईडी पसंद नहीं आता है, तो कोई दूसरा आईडी जनरेट किया जा सकता है. इसके अलावा, आपके पास खुद का कोई दूसरा नाम चुनने का विकल्प भी है. इस चरण के बाद, इसे बदला नहीं जा सकता. यह प्रोजेक्ट के दौरान बना रहता है.
  • आपकी जानकारी के लिए बता दें कि तीसरी वैल्यू, प्रोजेक्ट नंबर होती है. इसका इस्तेमाल कुछ एपीआई करते हैं. इन तीनों वैल्यू के बारे में ज़्यादा जानने के लिए, दस्तावेज़ देखें.
  1. इसके बाद, आपको Cloud के संसाधनों/एपीआई का इस्तेमाल करने के लिए, Cloud Console में बिलिंग की सुविधा चालू करनी होगी. इस कोडलैब को चलाने के लिए, आपसे कोई शुल्क नहीं लिया जाएगा. इस ट्यूटोरियल के बाद बिलिंग से बचने के लिए, बनाए गए संसाधनों को बंद किया जा सकता है या प्रोजेक्ट को मिटाया जा सकता है. Google Cloud के नए उपयोगकर्ता, 300 डॉलर के मुफ़्त ट्रायल वाले कार्यक्रम में शामिल हो सकते हैं.

Cloud Shell शुरू करना

Google Cloud को आपके लैपटॉप से रिमोट तौर पर इस्तेमाल किया जा सकता है. हालांकि, इस कोडलैब में आपको Google Cloud Shell का इस्तेमाल करना होगा. यह Cloud में चलने वाला कमांड-लाइन एनवायरमेंट है.

Google Cloud Console में, सबसे ऊपर दाएं टूलबार में मौजूद Cloud Shell आइकॉन पर क्लिक करें:

55efc1aaa7a4d3ad.png

एनवायरमेंट से कनेक्ट होने और उसे प्रोवाइड करने में सिर्फ़ कुछ मिनट लगेंगे. इसके पूरा होने पर, आपको कुछ ऐसा दिखेगा:

7ffe5cbb04455448.png

इस वर्चुअल मशीन में, डेवलपमेंट के लिए ज़रूरी सभी टूल लोड होते हैं. यह 5 जीबी की होम डायरेक्ट्री उपलब्ध कराता है. यह Google Cloud पर चलता है, जिससे नेटवर्क की परफ़ॉर्मेंस और पुष्टि करने की सुविधा बेहतर होती है. इस कोडलैब में, सारा काम ब्राउज़र में किया जा सकता है. आपको कुछ भी इंस्टॉल करने की ज़रूरत नहीं है.

3. शुरू करने से पहले

एपीआई चालू करना

आउटपुट:

Cloud Shell में, पक्का करें कि आपका प्रोजेक्ट आईडी सेट अप हो:

PROJECT_ID=$(gcloud config get-value project)
echo $PROJECT_ID

अगर यह क्लाउड शेल कॉन्फ़िगरेशन में तय नहीं किया गया है, तो इसे सेट अप करने के लिए नीचे दिए गए निर्देशों का पालन करें

export PROJECT_ID=<your project>
gcloud config set project $PROJECT_ID

सभी ज़रूरी सेवाएं चालू करें:

gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com

अनुमानित आउटपुट

student@cloudshell:~ (test-project-001-402417)$ PROJECT_ID=test-project-001-402417
student@cloudshell:~ (test-project-001-402417)$ gcloud config set project test-project-001-402417
Updated property [core/project].
student@cloudshell:~ (test-project-001-402417)$ gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com
Operation "operations/acat.p2-4470404856-1f44ebd8-894e-4356-bea7-b84165a57442" finished successfully.

4. GKE पर AlloyDB Omni को डिप्लॉय करना

GKE पर AlloyDB Omni को डिप्लॉय करने के लिए, हमें AlloyDB Omni ऑपरेटर की ज़रूरी शर्तों में बताई गई शर्तों के मुताबिक Kubernetes क्लस्टर तैयार करना होगा.

GKE क्लस्टर बनाना

हमें एक स्टैंडर्ड GKE क्लस्टर को ऐसे पूल कॉन्फ़िगरेशन के साथ डिप्लॉय करना होगा जो AlloyDB Omni इंस्टेंस के साथ पॉड को डिप्लॉय करने के लिए ज़रूरी हो. Omni के लिए, हमें कम से कम दो सीपीयू और 8 जीबी रैम की ज़रूरत होती है. साथ ही, ऑपरेटर और मॉनिटरिंग सेवाओं के लिए भी कुछ जगह होनी चाहिए.

अपने डिप्लॉयमेंट के लिए एनवायरमेंट वैरिएबल सेट अप करें.

export PROJECT_ID=$(gcloud config get project)
export LOCATION=us-central1
export CLUSTER_NAME=alloydb-ai-gke
export MACHINE_TYPE=e2-standard-4

इसके बाद, हम GKE स्टैंडर्ड क्लस्टर बनाने के लिए gcloud का इस्तेमाल करते हैं.

gcloud container clusters create ${CLUSTER_NAME} \
  --project=${PROJECT_ID} \
  --region=${LOCATION} \
  --workload-pool=${PROJECT_ID}.svc.id.goog \
  --release-channel=rapid \
  --machine-type=${MACHINE_TYPE} \
  --num-nodes=1

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~ (gleb-test-short-001-415614)$ export PROJECT_ID=$(gcloud config get project)
export LOCATION=us-central1
export CLUSTER_NAME=alloydb-ai-gke
export MACHINE_TYPE=n2-highmem-2
Your active configuration is: [gleb-test-short-001-415614]
student@cloudshell:~ (gleb-test-short-001-415614)$ gcloud container clusters create ${CLUSTER_NAME} \
  --project=${PROJECT_ID} \
  --region=${LOCATION} \
  --workload-pool=${PROJECT_ID}.svc.id.goog \
  --release-channel=rapid \
  --machine-type=${MACHINE_TYPE} \
  --num-nodes=1
Note: The Kubelet readonly port (10255) is now deprecated. Please update your workloads to use the recommended alternatives. See https://cloud.google.com/kubernetes-engine/docs/how-to/disable-kubelet-readonly-port for ways to check usage and for migration instructions.
Note: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
Creating cluster alloydb-ai-gke in us-central1..


NAME: omni01
ZONE: us-central1-a
MACHINE_TYPE: e2-standard-4
PREEMPTIBLE: 
INTERNAL_IP: 10.128.0.3
EXTERNAL_IP: 35.232.157.123
STATUS: RUNNING
student@cloudshell:~ (gleb-test-short-001-415614)$ 

क्लस्टर तैयार करना

हमें cert-manager सेवा जैसे ज़रूरी कॉम्पोनेंट इंस्टॉल करने होंगे. cert-manager इंस्टॉल करने के लिए, दस्तावेज़ में दिया गया तरीका अपनाया जा सकता है

हम Kubernetes कमांड-लाइन टूल, kubectl का इस्तेमाल करते हैं. यह टूल, Cloud Shell में पहले से इंस्टॉल होता है. इस सुविधा का इस्तेमाल करने से पहले, हमें अपने क्लस्टर के लिए क्रेडेंशियल चाहिए.

gcloud container clusters get-credentials ${CLUSTER_NAME} --region=${LOCATION}

अब हम cert-manager इंस्टॉल करने के लिए, kubectl का इस्तेमाल कर सकते हैं:

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yaml

कंसोल का अनुमानित आउटपुट(छिपाया गया):

student@cloudshell:~$ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yaml
namespace/cert-manager created
customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io created
...
validatingwebhookconfiguration.admissionregistration.k8s.io/cert-manager-webhook created

AlloyDB Omni इंस्टॉल करना

AlloyDB Omni ऑपरेटर को इंस्टॉल करने के लिए, हेल्म यूटिलिटी का इस्तेमाल किया जा सकता है.

AlloyDB Omni ऑपरेटर इंस्टॉल करने के लिए, यह कमांड चलाएं:

export GCS_BUCKET=alloydb-omni-operator
export HELM_PATH=$(gcloud storage cat gs://$GCS_BUCKET/latest)
export OPERATOR_VERSION="${HELM_PATH%%/*}"
gcloud storage cp gs://$GCS_BUCKET/$HELM_PATH ./ --recursive
helm install alloydbomni-operator alloydbomni-operator-${OPERATOR_VERSION}.tgz \
--create-namespace \
--namespace alloydb-omni-system \
--atomic \
--timeout 5m

कंसोल का अनुमानित आउटपुट(छिपाया गया):

student@cloudshell:~$ gcloud storage cp gs://$GCS_BUCKET/$HELM_PATH ./ --recursive
Copying gs://alloydb-omni-operator/1.2.0/alloydbomni-operator-1.2.0.tgz to file://./alloydbomni-operator-1.2.0.tgz
  Completed files 1/1 | 126.5kiB/126.5kiB
student@cloudshell:~$ helm install alloydbomni-operator alloydbomni-operator-${OPERATOR_VERSION}.tgz \
> --create-namespace \
> --namespace alloydb-omni-system \
> --atomic \
> --timeout 5m
NAME: alloydbomni-operator
LAST DEPLOYED: Mon Jan 20 13:13:20 2025
NAMESPACE: alloydb-omni-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
student@cloudshell:~$

AlloyDB Omni ऑपरेटर इंस्टॉल होने के बाद, हम अपने डेटाबेस क्लस्टर को डिप्लॉय कर सकते हैं.

यहां GoogleMLExtension पैरामीटर और इंटरनल (निजी) लोड बैलेंसर की सुविधा चालू होने पर, डिप्लॉयमेंट मेनिफ़ेस्ट का उदाहरण दिया गया है.:

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-my-omni
type: Opaque
data:
  my-omni: "VmVyeVN0cm9uZ1Bhc3N3b3Jk"
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: my-omni
spec:
  databaseVersion: "15.7.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-my-omni
    features:
      googleMLExtension:
        enabled: true
    resources:
      cpu: 1
      memory: 8Gi
      disks:
      - name: DataDisk
        size: 20Gi
        storageClass: standard
    dbLoadBalancerOptions:
      annotations:
        networking.gke.io/load-balancer-type: "internal"
  allowExternalIncomingTraffic: true

पासवर्ड की सीक्रेट वैल्यू, पासवर्ड "VeryStrongPassword" के Base64 वर्शन के तौर पर होती है. पासवर्ड की वैल्यू सेव करने के लिए, Google Secret Manager का इस्तेमाल करना ज़्यादा भरोसेमंद तरीका है. इस बारे में ज़्यादा जानने के लिए, दस्तावेज़ पढ़ें.

मेनिफ़ेस्ट को my-omni.yaml के तौर पर सेव करें, ताकि उसे अगले चरण में लागू किया जा सके. अगर आप Cloud Shell में हैं, तो एडिटर का इस्तेमाल करके ऐसा किया जा सकता है. इसके लिए, टर्मिनल के सबसे ऊपर दाईं ओर मौजूद "एडिटर खोलें" बटन को दबाएं.

47ab85dad9afdff7.png

my-omni.yaml नाम से फ़ाइल सेव करने के बाद, "टर्मिनल खोलें" बटन दबाकर टर्मिनल पर वापस जाएं.

b9b7747b39dbe8c7.png

kubectl टूल का इस्तेमाल करके, क्लस्टर में my-omni.yaml मेनिफ़ेस्ट लागू करें:

kubectl apply -f my-omni.yaml

कंसोल का अनुमानित आउटपुट:

secret/db-pw-my-omni created
dbcluster.alloydbomni.dbadmin.goog/my-omni created

kubectl टूल का इस्तेमाल करके, अपने my-omni क्लस्टर की स्थिति देखें:

kubectl get dbclusters.alloydbomni.dbadmin.goog my-omni -n default

डिप्लॉयमेंट के दौरान, क्लस्टर अलग-अलग चरणों से गुज़रता है. आखिर में, यह DBClusterReady स्टेटस पर पहुंच जाना चाहिए.

कंसोल का अनुमानित आउटपुट:

$ kubectl get dbclusters.alloydbomni.dbadmin.goog my-omni -n default
NAME      PRIMARYENDPOINT   PRIMARYPHASE   DBCLUSTERPHASE   HAREADYSTATUS   HAREADYREASON
my-omni   10.131.0.33        Ready          DBClusterReady

AlloyDB Omni से कनेक्ट करना

Kubernetes पॉड का इस्तेमाल करके कनेक्ट करना

क्लस्टर तैयार होने के बाद, हम AlloyDB Omni इंस्टेंस पॉड पर PostgreSQL क्लाइंट बाइनरी का इस्तेमाल कर सकते हैं. हम पॉड आईडी ढूंढते हैं और फिर सीधे पॉड से कनेक्ट करने और क्लाइंट सॉफ़्टवेयर चलाने के लिए, kubectl का इस्तेमाल करते हैं. पासवर्ड, VeryStrongPassword है, जैसा कि my-omni.yaml में हैश के ज़रिए सेट किया गया है:

DB_CLUSTER_NAME=my-omni
DB_CLUSTER_NAMESPACE=default
DBPOD=`kubectl get pod --selector=alloydbomni.internal.dbadmin.goog/dbcluster=$DB_CLUSTER_NAME,alloydbomni.internal.dbadmin.goog/task-type=database -n $DB_CLUSTER_NAMESPACE -o jsonpath='{.items[0].metadata.name}'`
kubectl exec -ti $DBPOD -n $DB_CLUSTER_NAMESPACE -c database -- psql -h localhost -U postgres

कंसोल आउटपुट का सैंपल:

DB_CLUSTER_NAME=my-omni
DB_CLUSTER_NAMESPACE=default
DBPOD=`kubectl get pod --selector=alloydbomni.internal.dbadmin.goog/dbcluster=$DB_CLUSTER_NAME,alloydbomni.internal.dbadmin.goog/task-type=database -n $DB_CLUSTER_NAMESPACE -o jsonpath='{.items[0].metadata.name}'`
kubectl exec -ti $DBPOD -n $DB_CLUSTER_NAMESPACE -c database -- psql -h localhost -U postgres
Password for user postgres: 
psql (15.7)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_128_GCM_SHA256, compression: off)
Type "help" for help.

postgres=#

5. GKE पर एआई मॉडल डिप्लॉय करना

स्थानीय मॉडल के साथ AlloyDB Omni एआई इंटिग्रेशन की जांच करने के लिए, हमें क्लस्टर में एक मॉडल को डिप्लॉय करना होगा.

मॉडल के लिए नोड पूल बनाना

मॉडल को चलाने के लिए, हमें अनुमान लगाने के लिए एक नोड पूल तैयार करना होगा. परफ़ॉर्मेंस के लिहाज़ से, ग्राफ़िक ऐक्सेलरेटर वाला पूल सबसे अच्छा तरीका है. इसमें L4 Nvidia ऐक्सेलरेटर के साथ g2-standard-8 जैसे नोड कॉन्फ़िगरेशन का इस्तेमाल किया जाता है.

L4 एक्सेलेरेटर की मदद से नोड पूल बनाएं:

export PROJECT_ID=$(gcloud config get project)
export LOCATION=us-central1
export CLUSTER_NAME=alloydb-ai-gke
gcloud container node-pools create gpupool \
  --accelerator type=nvidia-l4,count=1,gpu-driver-version=latest \
  --project=${PROJECT_ID} \
  --location=${LOCATION} \
  --node-locations=${LOCATION}-a \
  --cluster=${CLUSTER_NAME} \
  --machine-type=g2-standard-8 \
  --num-nodes=1

अनुमानित आउटपुट

student@cloudshell$ export PROJECT_ID=$(gcloud config get project)
Your active configuration is: [pant]
export LOCATION=us-central1
export CLUSTER_NAME=alloydb-ai-gke
student@cloudshell$ gcloud container node-pools create gpupool \
>   --accelerator type=nvidia-l4,count=1,gpu-driver-version=latest \
>   --project=${PROJECT_ID} \
>   --location=${LOCATION} \
>   --node-locations=${LOCATION}-a \
>   --cluster=${CLUSTER_NAME} \
>   --machine-type=g2-standard-8 \
>   --num-nodes=1
Note: Machines with GPUs have certain limitations which may affect your workflow. Learn more at https://cloud.google.com/kubernetes-engine/docs/how-to/gpus
Note: Starting in GKE 1.30.1-gke.115600, if you don't specify a driver version, GKE installs the default GPU driver for your node's GKE version.
Creating node pool gpupool...done.
Created [https://container.googleapis.com/v1/projects/student-test-001/zones/us-central1/clusters/alloydb-ai-gke/nodePools/gpupool].
NAME     MACHINE_TYPE   DISK_SIZE_GB  NODE_VERSION
gpupool  g2-standard-8  100           1.31.4-gke.1183000

डिप्लॉयमेंट मेनिफ़ेस्ट तैयार करना

मॉडल को डिप्लॉय करने के लिए, हमें डिप्लॉयमेंट मेनिफ़ेस्ट तैयार करना होगा.

हम Hugging Face के BGE Base v1.5 एम्बेडिंग मॉडल का इस्तेमाल कर रहे हैं. मॉडल कार्ड को यहां पढ़ा जा सकता है. मॉडल को डिप्लॉय करने के लिए, Hugging Face से पहले से तैयार किए गए निर्देशों और GitHub से डिप्लॉयमेंट पैकेज का इस्तेमाल किया जा सकता है.

पैकेज का क्लोन बनाना

git clone https://github.com/huggingface/Google-Cloud-Containers

cloud.google.com/gke-accelerator की वैल्यू को हमारे nvidia-l4 से बदलकर, मेनिफ़ेस्ट में बदलाव करें. साथ ही, संसाधनों की सीमाएं जोड़ें.

vi Google-Cloud-Containers/examples/gke/tei-deployment/gpu-config/deployment.yaml

यहां सही मेनिफ़ेस्ट दिया गया है.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tei-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tei-server
  template:
    metadata:
      labels:
        app: tei-server
        hf.co/model: Snowflake--snowflake-arctic-embed-m
        hf.co/task: text-embeddings
    spec:
      containers:
        - name: tei-container
          image: us-docker.pkg.dev/deeplearning-platform-release/gcr.io/huggingface-text-embeddings-inference-cu122.1-4.ubuntu2204:latest
          resources:
            requests:
              nvidia.com/gpu: 1
            limits:
              nvidia.com/gpu: 1
          env:
            - name: MODEL_ID
              value: Snowflake/snowflake-arctic-embed-m
            - name: NUM_SHARD
              value: "1"
            - name: PORT
              value: "8080"
          volumeMounts:
            - mountPath: /dev/shm
              name: dshm
            - mountPath: /data
              name: data
      volumes:
        - name: dshm
          emptyDir:
            medium: Memory
            sizeLimit: 1Gi
        - name: data
          emptyDir: {}
      nodeSelector:
        cloud.google.com/gke-accelerator: nvidia-l4

मॉडल को डिप्लॉय करना

हमें डिप्लॉयमेंट के लिए, एक सेवा खाता और नेमस्पेस तैयार करना होगा.

kubernetes नेमस्पेस hf-gke-namespace बनाएं.

export NAMESPACE=hf-gke-namespace
kubectl create namespace $NAMESPACE

Kubernetes सेवा खाता बनाना

export SERVICE_ACCOUNT=hf-gke-service-account
kubectl create serviceaccount $SERVICE_ACCOUNT --namespace $NAMESPACE

मॉडल को डिप्लॉय करना

kubectl apply -f Google-Cloud-Containers/examples/gke/tei-deployment/gpu-config

डिप्लॉयमेंट की पुष्टि करना

kubectl get pods

मॉडल सेवा की पुष्टि करना

kubectl get service tei-service

इसमें, चल रही सेवा का टाइप ClusterIP दिखना चाहिए

आउटपुट का सैंपल:

student@cloudshell$ kubectl get service tei-service
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
tei-service   ClusterIP   34.118.233.48   <none>        8080/TCP   10m

सेवा के लिए CLUSTER-IP का इस्तेमाल, एंडपॉइंट पते के तौर पर किया जाएगा. मॉडल को एम्बेड करने के लिए, यूआरआई http://34.118.233.48:8080/embed का इस्तेमाल किया जा सकता है. इसका इस्तेमाल बाद में, AlloyDB Omni में मॉडल को रजिस्टर करते समय किया जाएगा.

हम kubectl port-forward कमांड का इस्तेमाल करके, इसे एक्सपोज़ करके इसकी जांच कर सकते हैं.

kubectl port-forward service/tei-service 8080:8080

पोर्ट फ़ॉरवर्डिंग एक Cloud Shell सेशन में चलेगी और हमें इसकी जांच करने के लिए एक और सेशन की ज़रूरत है.

सबसे ऊपर मौजूद "+" साइन का इस्तेमाल करके, Cloud Shell का दूसरा टैब खोलें.

4ca978f5142bb6ce.png

इसके बाद, नए शेल सेशन में curl कमांड चलाएं.

curl http://localhost:8080/embed \
    -X POST \
    -d '{"inputs":"Test"}' \
    -H 'Content-Type: application/json'

यह वैक्टर कलेक्शन दिखाना चाहिए, जैसा कि यहां दिए गए सैंपल आउटपुट में दिखाया गया है (इसमें डेटा छिपाया गया है):

curl http://localhost:8080/embed \
>     -X POST \
>     -d '{"inputs":"Test"}' \
>     -H 'Content-Type: application/json'
[[-0.018975832,0.0071419072,0.06347208,0.022992613,0.014205903
...
-0.03677433,0.01636146,0.06731572]]

6. AlloyDB Omni में मॉडल रजिस्टर करना

यह जांचने के लिए कि हमारा AlloyDB Omni, डिप्लॉय किए गए मॉडल के साथ कैसे काम करता है, हमें एक डेटाबेस बनाना होगा और मॉडल को रजिस्टर करना होगा.

डेटाबेस बनाना

जंप बॉक्स के तौर पर GCE वीएम बनाएं. इसके बाद, अपने क्लाइंट वीएम से AlloyDB Omni से कनेक्ट करें और डेटाबेस बनाएं.

हमें जंप बॉक्स की ज़रूरत है, क्योंकि Omni के लिए GKE का बाहरी लोड बैलेंसर, निजी आईपी पते का इस्तेमाल करके आपको VPC से ऐक्सेस देता है. हालांकि, यह आपको VPC से बाहर से कनेक्ट करने की अनुमति नहीं देता. यह आम तौर पर ज़्यादा सुरक्षित होता है और आपके डेटाबेस इंस्टेंस को इंटरनेट पर एक्सपोज़ नहीं करता. ज़्यादा जानकारी के लिए, कृपया डायग्राम देखें.

391e4244b25a7db0.png

Cloud Shell सेशन में वीएम बनाने के लिए, यह तरीका अपनाएं:

export ZONE=us-central1-a
gcloud compute instances create instance-1 \
    --zone=$ZONE 

Cloud Shell में kubectl का इस्तेमाल करके, AlloyDB Omni एंडपॉइंट का आईपी पता ढूंढें:

kubectl get dbclusters.alloydbomni.dbadmin.goog my-omni -n default

PRIMARYENDPOINT को नोट करें. यहां एक उदाहरण दिया गया है.

output:

student@cloudshell:~$ kubectl get dbclusters.alloydbomni.dbadmin.goog my-omni -n default
NAME      PRIMARYENDPOINT   PRIMARYPHASE   DBCLUSTERPHASE   HAREADYSTATUS   HAREADYREASON
my-omni   10.131.0.33        Ready          DBClusterReady
student@cloudshell:~$

10.131.0.33 वह आईपी है जिसका इस्तेमाल हम अपने उदाहरणों में, AlloyDB Omni इंस्टेंस से कनेक्ट करने के लिए करेंगे.

gcloud का इस्तेमाल करके वीएम से कनेक्ट करना:

gcloud compute ssh instance-1 --zone=$ZONE 

अगर आपसे एसएसएच पासकोड जनरेट करने के लिए कहा जाए, तो निर्देशों का पालन करें. दस्तावेज़ में, एसएसएच कनेक्शन के बारे में ज़्यादा पढ़ें.

PostgreSQL क्लाइंट को इंस्टॉल करने के लिए, VM के एसएसएच सेशन में:

sudo apt-get update
sudo apt-get install --yes postgresql-client

AlloyDB Omni लोड बैलेंसर आईपी को यहां दिए गए उदाहरण के मुताबिक एक्सपोर्ट करें. आईपी की जगह अपना लोड बैलेंसर आईपी डालें:

export INSTANCE_IP=10.131.0.33

AlloyDB Omni से कनेक्ट करें. पासवर्ड, my-omni.yaml में हैश के ज़रिए सेट किया गया VeryStrongPassword है:

psql "host=$INSTANCE_IP user=postgres sslmode=require"

पहले से मौजूद psql सेशन में, यह कमांड चलाएं:

create database demo;

सेशन से बाहर निकलें और डेटाबेस डेमो से कनेक्ट करें. इसके अलावा, उसी सेशन में "\c demo" चलाया जा सकता है

psql "host=$INSTANCE_IP user=postgres sslmode=require dbname=demo"

ट्रांसफ़ॉर्म फ़ंक्शन बनाना

तीसरे पक्ष के एम्बेड किए गए मॉडल के लिए, हमें ट्रांसफ़ॉर्म फ़ंक्शन बनाने होंगे. ये फ़ंक्शन, इनपुट और आउटपुट को मॉडल और हमारे इंटरनल फ़ंक्शन के हिसाब से फ़ॉर्मैट करते हैं.

यहां ट्रांसफ़ॉर्म फ़ंक्शन दिया गया है, जो इनपुट को मैनेज करता है:

-- Input Transform Function corresponding to the custom model endpoint
CREATE OR REPLACE FUNCTION tei_text_input_transform(model_id VARCHAR(100), input_text TEXT)
RETURNS JSON
LANGUAGE plpgsql
AS $$
DECLARE
  transformed_input JSON;
  model_qualified_name TEXT;
BEGIN
  SELECT json_build_object('inputs', input_text, 'truncate', true)::JSON INTO transformed_input;
  RETURN transformed_input;
END;
$$;

सैंपल आउटपुट में दिखाए गए तरीके से, डेमो डेटाबेस से कनेक्ट होने के दौरान, दिया गया कोड चलाएं:

demo=# -- Input Transform Function corresponding to the custom model endpoint
CREATE OR REPLACE FUNCTION tei_text_input_transform(model_id VARCHAR(100), input_text TEXT)
RETURNS JSON
LANGUAGE plpgsql
AS $$
DECLARE
  transformed_input JSON;
  model_qualified_name TEXT;
BEGIN
  SELECT json_build_object('inputs', input_text, 'truncate', true)::JSON INTO transformed_input;
  RETURN transformed_input;
END;
$$;
CREATE FUNCTION
demo=#

यहां आउटपुट फ़ंक्शन दिया गया है, जो मॉडल के रिस्पॉन्स को रीयल नंबर के कलेक्शन में बदलता है:

-- Output Transform Function corresponding to the custom model endpoint
CREATE OR REPLACE FUNCTION tei_text_output_transform(model_id VARCHAR(100), response_json JSON)
RETURNS REAL[]
LANGUAGE plpgsql
AS $$
DECLARE
  transformed_output REAL[];
BEGIN
  SELECT ARRAY(SELECT json_array_elements_text(response_json->0)) INTO transformed_output;
  RETURN transformed_output;
END;
$$;

इसे उसी सेशन में लागू करें:

demo=# -- Output Transform Function corresponding to the custom model endpoint
CREATE OR REPLACE FUNCTION tei_text_output_transform(model_id VARCHAR(100), response_json JSON)
RETURNS REAL[]
LANGUAGE plpgsql
AS $$
DECLARE
  transformed_output REAL[];
BEGIN
  SELECT ARRAY(SELECT json_array_elements_text(response_json->0)) INTO transformed_output;
  RETURN transformed_output;
END;
$$;
CREATE FUNCTION
demo=#

मॉडल रजिस्टर करना

अब हम मॉडल को डेटाबेस में रजिस्टर कर सकते हैं.

bge-base-1.5 नाम से मॉडल को रजिस्टर करने के लिए, यहां दिया गया तरीका अपनाएं. आईपी 34.118.233.48 की जगह, मॉडल की सेवा का आईपी पता डालें. यह पता, kubectl get service tei-service से मिलता है:

CALL
  google_ml.create_model(
    model_id => 'bge-base-1.5',
    model_request_url => 'http://34.118.233.48:8080/embed',
    model_provider => 'custom',
    model_type => 'text_embedding',
    model_in_transform_fn => 'tei_text_input_transform',
    model_out_transform_fn => 'tei_text_output_transform');

डेमो डेटाबेस से कनेक्ट होने के दौरान, दिया गया कोड चलाएं:

demo=# CALL
  google_ml.create_model(
    model_id => 'bge-base-1.5',
    model_request_url => 'http://34.118.233.48:8080/embed',
    model_provider => 'custom',
    model_type => 'text_embedding',
    model_in_transform_fn => 'tei_text_input_transform',
    model_out_transform_fn => 'tei_text_output_transform');
CALL
demo=#

रजिस्टर मॉडल की जांच करने के लिए, नीचे दी गई टेस्ट क्वेरी का इस्तेमाल किया जा सकता है. इससे असल संख्याओं का कलेक्शन दिखेगा.

select google_ml.embedding('bge-base-1.5','What is AlloyDB Omni?');

7. AlloyDB Omni में मॉडल को टेस्ट करना

डेटा लोड करना

डिप्लॉय किए गए मॉडल के साथ, AlloyDB Omni के काम करने का तरीका जानने के लिए, हमें कुछ डेटा लोड करना होगा. मैंने AlloyDB में वेक्टर सर्च के लिए, उसी डेटा का इस्तेमाल किया है जिसका इस्तेमाल अन्य कोडलैब में किया गया था.

डेटा लोड करने का एक तरीका यह है कि Google Cloud SDK और PostgreSQL क्लाइंट सॉफ़्टवेयर का इस्तेमाल किया जाए. हम उसी क्लाइंट VM का इस्तेमाल कर सकते हैं जिसका इस्तेमाल डेमो डेटाबेस बनाने के लिए किया गया था. अगर आपने वीएम इमेज के लिए डिफ़ॉल्ट विकल्पों का इस्तेमाल किया है, तो Google Cloud SDK टूल पहले से ही इंस्टॉल होना चाहिए. हालांकि, अगर आपने Google SDK टूल के बिना कस्टम इमेज का इस्तेमाल किया है, तो दस्तावेज़ में दिए गए निर्देशों का पालन करके, उसे जोड़ा जा सकता है.

AlloyDB Omni लोड बैलेंसर आईपी को यहां दिए गए उदाहरण के मुताबिक एक्सपोर्ट करें. आईपी की जगह अपना लोड बैलेंसर आईपी डालें:

export INSTANCE_IP=10.131.0.33

डेटाबेस से कनेक्ट करें और pgvector एक्सटेंशन चालू करें.

psql "host=$INSTANCE_IP user=postgres sslmode=require dbname=demo"

psql सेशन में:

CREATE EXTENSION IF NOT EXISTS vector;

psql सेशन से बाहर निकलें और कमांड लाइन सेशन में डेटा को डेमो डेटाबेस में लोड करने के लिए कमांड चलाएं.

टेबल बनाएं:

gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_demo_schema.sql |psql "host=$INSTANCE_IP user=postgres dbname=demo"

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_demo_schema.sql |psql "host=$INSTANCE_IP user=postgres dbname=demo"
Password for user postgres:
SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE SEQUENCE
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
ALTER TABLE
ALTER TABLE
student@cloudshell:~$ 

यहां बनाई गई टेबल की सूची दी गई है:

psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\dt+"

आउटपुट:

student@cloudshell:~$ psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\dt+"
Password for user postgres: 
                                           List of relations
 Schema |       Name       | Type  |  Owner   | Persistence | Access method |    Size    | Description 
--------+------------------+-------+----------+-------------+---------------+------------+-------------
 public | cymbal_embedding | table | postgres | permanent   | heap          | 8192 bytes | 
 public | cymbal_inventory | table | postgres | permanent   | heap          | 8192 bytes | 
 public | cymbal_products  | table | postgres | permanent   | heap          | 8192 bytes | 
 public | cymbal_stores    | table | postgres | permanent   | heap          | 8192 bytes | 
(4 rows)
student@cloudshell:~$ 

cymbal_products टेबल में डेटा लोड करें:

gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_products.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_products from stdin csv header"

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_products.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_products from stdin csv header"
COPY 941
student@cloudshell:~$ 

यहां cymbal_products टेबल की कुछ पंक्तियों का सैंपल दिया गया है.

psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT uniq_id,left(product_name,30),left(product_description,50),sale_price FROM cymbal_products limit 3"

आउटपुट:

student@cloudshell:~$ psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT uniq_id,left(product_name,30),left(product_description,50),sale_price FROM cymbal_products limit 3"
Password for user postgres: 
             uniq_id              |              left              |                        left                        | sale_price 
----------------------------------+--------------------------------+----------------------------------------------------+------------
 a73d5f754f225ecb9fdc64232a57bc37 | Laundry Tub Strainer Cup       |   Laundry tub strainer cup Chrome For 1-.50, drain |      11.74
 41b8993891aa7d39352f092ace8f3a86 | LED Starry Star Night Light La |  LED Starry Star Night Light Laser Projector 3D Oc |      46.97
 ed4a5c1b02990a1bebec908d416fe801 | Surya Horizon HRZ-1060 Area Ru |  The 100% polypropylene construction of the Surya  |       77.4
(3 rows)
student@cloudshell:~$ 

cymbal_inventory टेबल में डेटा लोड करें:

gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_inventory.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_inventory from stdin csv header"

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_inventory.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_inventory from stdin csv header"
Password for user postgres: 
COPY 263861
student@cloudshell:~$ 

यहां cymbal_inventory टेबल की कुछ पंक्तियों का सैंपल दिया गया है.

psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT * FROM cymbal_inventory LIMIT 3"

आउटपुट:

student@cloudshell:~$ psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT * FROM cymbal_inventory LIMIT 3"
Password for user postgres: 
 store_id |             uniq_id              | inventory 
----------+----------------------------------+-----------
     1583 | adc4964a6138d1148b1d98c557546695 |         5
     1490 | adc4964a6138d1148b1d98c557546695 |         4
     1492 | adc4964a6138d1148b1d98c557546695 |         3
(3 rows)
student@cloudshell:~$ 

cymbal_stores टेबल में डेटा लोड करें:

gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_stores.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_stores from stdin csv header"

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_stores.csv |psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "\copy cymbal_stores from stdin csv header"
Password for user postgres: 
COPY 4654
student@cloudshell:~$

यहां cymbal_stores टेबल की कुछ पंक्तियों का सैंपल दिया गया है.

psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT store_id, name, zip_code FROM cymbal_stores limit 3"

आउटपुट:

student@cloudshell:~$ psql "host=$INSTANCE_IP user=postgres dbname=demo" -c "SELECT store_id, name, zip_code FROM cymbal_stores limit 3"
Password for user postgres: 
 store_id |       name        | zip_code 
----------+-------------------+----------
     1990 | Mayaguez Store    |      680
     2267 | Ware Supercenter  |     1082
     4359 | Ponce Supercenter |      780
(3 rows)
student@cloudshell:~$ 

एम्बेड करने की सुविधा जोड़ना

psql का इस्तेमाल करके, डेमो डेटाबेस से कनेक्ट करें. इसके बाद, cymbal_products टेबल में बताए गए प्रॉडक्ट के नाम और ब्यौरे के आधार पर, उन प्रॉडक्ट के लिए एम्बेड बनाएं.

डेमो डेटाबेस से कनेक्ट करने के लिए:

psql "host=$INSTANCE_IP user=postgres sslmode=require dbname=demo"

हम अपने एम्बेडमेंट को सेव करने के लिए, कॉलम एम्बेडिंग के साथ cymbal_embedding टेबल का इस्तेमाल कर रहे हैं. साथ ही, हम फ़ंक्शन में टेक्स्ट इनपुट के तौर पर प्रॉडक्ट के ब्यौरे का इस्तेमाल करते हैं.

अपनी क्वेरी के लिए टाइमिंग चालू करें, ताकि बाद में उन्हें रिमोट मॉडल के साथ तुलना की जा सके.:

\timing

एम्बेड बनाने के लिए क्वेरी चलाएं:

INSERT INTO cymbal_embedding(uniq_id,embedding)  SELECT uniq_id, google_ml.embedding('bge-base-1.5',product_description)::vector FROM cymbal_products;

कंसोल का अनुमानित आउटपुट:

demo=#  INSERT INTO cymbal_embedding(uniq_id,embedding)  SELECT uniq_id, google_ml.embedding('bge-base-1.5',product_description)::vector FROM cymbal_products;
INSERT 0 941
Time: 11069.762 ms (00:11.070)
demo=#

इस उदाहरण में, 941 रिकॉर्ड के लिए एम्बेड बनाने में करीब 11 सेकंड लगे.

टेस्ट क्वेरी चलाना

psql का इस्तेमाल करके, डेमो डेटाबेस से कनेक्ट करें. साथ ही, टाइमिंग चालू करें, ताकि हम क्वेरी के लिए, प्रोसेस होने में लगने वाले समय को मेज़र कर सकें. हमने एम्बेड बनाने के लिए भी ऐसा ही किया था.

आइए, "यहां किस तरह के फ़्रूट ट्री अच्छी तरह से उगते हैं?" जैसे अनुरोध से मैच होने वाले पांच सबसे लोकप्रिय प्रॉडक्ट ढूंढते हैं. इसके लिए, वेक्टर सर्च के एल्गोरिदम के तौर पर कोसाइन डिस्टेंस का इस्तेमाल किया जाएगा.

psql सेशन में, यह कमांड चलाएं:

SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        (ce.embedding <=> google_ml.embedding('bge-base-1.5','What kind of fruit trees grow well here?')::vector) as distance
FROM
        cymbal_products cp
JOIN cymbal_embedding ce on
        ce.uniq_id=cp.uniq_id
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        distance ASC
LIMIT 5;

कंसोल का अनुमानित आउटपुट:

demo=# SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        (ce.embedding <=> google_ml.embedding('bge-base-1.5','What kind of fruit trees grow well here?')::vector) as distance
FROM
        cymbal_products cp
JOIN cymbal_embedding ce on
        ce.uniq_id=cp.uniq_id
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        distance ASC
LIMIT 5;
     product_name      |                                   description                                    | sale_price | zip_code |      distance
-----------------------+----------------------------------------------------------------------------------+------------+----------+---------------------
 California Sycamore   | This is a beautiful sycamore tree that can grow to be over 100 feet tall. It is  |     300.00 |    93230 | 0.22753925487632942
 Toyon                 | This is a beautiful toyon tree that can grow to be over 20 feet tall. It is an e |      10.00 |    93230 | 0.23497374266229387
 California Peppertree | This is a beautiful peppertree that can grow to be over 30 feet tall. It is an e |      25.00 |    93230 | 0.24215884459965364
 California Redwood    | This is a beautiful redwood tree that can grow to be over 300 feet tall. It is a |    1000.00 |    93230 | 0.24564130578287147
 Cherry Tree           | This is a beautiful cherry tree that will produce delicious cherries. It is an d |      75.00 |    93230 | 0.24846117929767153
(5 rows)

Time: 28.724 ms
demo=#

क्वेरी को 28 मिलीसेकंड लगे और यह अनुरोध से मैच करने वाली cymbal_products टेबल से पेड़ों की सूची दिखाती है. साथ ही, यह सूची स्टोर में मौजूद 1583 नंबर वाली इन्वेंट्री से भी मैच करती है.

एएनएन इंडेक्स बनाना

जब हमारे पास सिर्फ़ एक छोटा डेटा सेट होता है, तो सभी एम्बेड को स्कैन करने वाली सटीक खोज का इस्तेमाल करना आसान होता है. हालांकि, डेटा बढ़ने पर लोड और रिस्पॉन्स का समय भी बढ़ जाता है. परफ़ॉर्मेंस को बेहतर बनाने के लिए, एम्बेड किए गए डेटा पर इंडेक्स बनाए जा सकते हैं. वेक्टर डेटा के लिए, Google ScaNN इंडेक्स का इस्तेमाल करके ऐसा करने का उदाहरण यहां दिया गया है.

अगर आपका कनेक्शन टूट गया है, तो डेमो डेटाबेस से फिर से कनेक्ट करें:

psql "host=$INSTANCE_IP user=postgres sslmode=require dbname=demo"

alloydb_scann एक्सटेंशन चालू करें:

CREATE EXTENSION IF NOT EXISTS alloydb_scann;

इंडेक्स बनाएं:

CREATE INDEX cymbal_embedding_scann ON cymbal_embedding USING scann (embedding cosine);

पहले की तरह ही क्वेरी आज़माएं और नतीजों की तुलना करें:

demo=# SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        (ce.embedding <=> google_ml.embedding('bge-base-1.5','What kind of fruit trees grow well here?')::vector) as distance
FROM
        cymbal_products cp
JOIN cymbal_embedding ce on
        ce.uniq_id=cp.uniq_id
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        distance ASC
LIMIT 5;
     product_name      |                                   description                                    | sale_price | zip_code |      distance
-----------------------+----------------------------------------------------------------------------------+------------+----------+---------------------
 California Sycamore   | This is a beautiful sycamore tree that can grow to be over 100 feet tall. It is  |     300.00 |    93230 | 0.22753925487632942
 Toyon                 | This is a beautiful toyon tree that can grow to be over 20 feet tall. It is an e |      10.00 |    93230 | 0.23497374266229387
 California Peppertree | This is a beautiful peppertree that can grow to be over 30 feet tall. It is an e |      25.00 |    93230 | 0.24215884459965364
 California Redwood    | This is a beautiful redwood tree that can grow to be over 300 feet tall. It is a |    1000.00 |    93230 | 0.24564130578287147
 Fremont Cottonwood    | This is a beautiful cottonwood tree that can grow to be over 100 feet tall. It i |     200.00 |    93230 |  0.2533482837690365
(5 rows)

Time: 14.665 ms
demo=#

क्वेरी को पूरा होने में लगने वाला समय थोड़ा कम हो गया है. यह फ़ायदा, बड़े डेटासेट के साथ ज़्यादा दिखेगा. दोनों के नतीजे काफ़ी मिलते-जुलते हैं. सिर्फ़ चेरी की जगह फ़्रेमोंट कॉटनवुड का इस्तेमाल किया गया है.

अन्य क्वेरी आज़माएं और दस्तावेज़ में वेक्टर इंडेक्स चुनने के बारे में ज़्यादा पढ़ें.

साथ ही, यह भी याद रखें कि AlloyDB Omni में और भी सुविधाएं और लैब हैं.

8. एनवायरमेंट को साफ़ करना

अब हम AlloyDB Omni और एआई मॉडल की मदद से, अपना GKE क्लस्टर मिटा सकते हैं

GKE क्लस्टर मिटाना

Cloud Shell में, यह कमांड चलाएं:

export PROJECT_ID=$(gcloud config get project)
export LOCATION=us-central1
export CLUSTER_NAME=alloydb-ai-gke
gcloud container clusters delete ${CLUSTER_NAME} \
  --project=${PROJECT_ID} \
  --region=${LOCATION}

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ gcloud container clusters delete ${CLUSTER_NAME} \
>   --project=${PROJECT_ID} \
>   --region=${LOCATION}
The following clusters will be deleted.
 - [alloydb-ai-gke] in [us-central1]

Do you want to continue (Y/n)?  Y

Deleting cluster alloydb-ai-gke...done.
Deleted

वीएम मिटाना

Cloud Shell में, यह कमांड चलाएं:

export PROJECT_ID=$(gcloud config get project)
export ZONE=us-central1-a
gcloud compute instances delete instance-1 \
  --project=${PROJECT_ID} \
  --zone=${ZONE}

कंसोल का अनुमानित आउटपुट:

student@cloudshell:~$ export PROJECT_ID=$(gcloud config get project)
export ZONE=us-central1-a
gcloud compute instances delete instance-1 \
  --project=${PROJECT_ID} \
  --zone=${ZONE}
Your active configuration is: [cloudshell-5399]
The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and specifies them for keeping. Deleting a disk 
is irreversible and any data on the disk will be lost.
 - [instance-1] in [us-central1-a]

Do you want to continue (Y/n)?  Y

Deleted

अगर आपने इस कोडलैब के लिए नया प्रोजेक्ट बनाया है, तो पूरा प्रोजेक्ट मिटाया जा सकता है: https://console.cloud.google.com/cloud-resource-manager

9. बधाई हो

कोडलैब पूरा करने के लिए बधाई.

हमने क्या-क्या शामिल किया है

  • Google Kubernetes क्लस्टर पर AlloyDB Omni को डिप्लॉय करने का तरीका
  • AlloyDB Omni से कनेक्ट करने का तरीका
  • AlloyDB Omni में डेटा लोड करने का तरीका
  • GKE में ओपन एम्बेडिंग मॉडल को डिप्लॉय करने का तरीका
  • AlloyDB Omni में एम्बेडिंग मॉडल को रजिस्टर करने का तरीका
  • सेमैनटिक सर्च के लिए एम्बेड जनरेट करने का तरीका
  • AlloyDB Omni में, सिमेंटिक सर्च के लिए जनरेट किए गए एम्बेड का इस्तेमाल करने का तरीका
  • AlloyDB में वेक्टर इंडेक्स बनाने और उनका इस्तेमाल करने का तरीका

AlloyDB Omni में एआई के साथ काम करने के बारे में ज़्यादा जानने के लिए, दस्तावेज़ पढ़ें.

10. सर्वे

आउटपुट:

इस ट्यूटोरियल का इस्तेमाल कैसे किया जाएगा?

सिर्फ़ पढ़ें इसे पढ़ें और इसमें दिए गए अभ्यास पूरे करें