This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
# Search request | |
def search(query): | |
client = discoveryengine.SearchServiceClient() | |
serving_config = client.serving_config_path( | |
project=PROJECT_ID, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
# Import packages | |
import json | |
import vertexai | |
from vertexai.generative_models import GenerativeModel | |
import vertexai.preview.generative_models as generative_models | |
from google.cloud import discoveryengine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
# Try running a simple similarity search | |
# Below code should return 5 results | |
vector_store.similarity_search("<YOUR QUERY>", k=5) | |
from langchain.chains import RetrievalQA | |
from langchain_google_vertexai import VertexAI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
vector_store = VectorSearchVectorStore.from_components( | |
project_id=PROJECT_ID, | |
region=REGION, | |
gcs_bucket_name=BUCKET, | |
index_id=my_index.name, | |
endpoint_id=my_index_endpoint.name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
from google.cloud import storage | |
from langchain_google_vertexai import ( | |
VectorSearchVectorStore, | |
VectorSearchVectorStoreDatastore, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
# NOTE : If you have existing Index and Endpoints, you can load them using below code | |
# TODO : replace the string with your acutial index ID | |
my_index = aiplatform.MatchingEngineIndex("YOUR INDEX ID") | |
# TODO : replace 1234567890123456789 with your acutial endpoint ID | |
my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint("YOUR ENDPOINT ID") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
# NOTE : This operation can take upto 30 seconds | |
my_index = aiplatform.MatchingEngineIndex.create_tree_ah_index( | |
display_name=DISPLAY_NAME, | |
dimensions=DIMENSIONS, | |
approximate_neighbors_count=150, | |
distance_measure_type="DOT_PRODUCT_DISTANCE", | |
index_update_method="STREAM_UPDATE", # allowed values BATCH_UPDATE , STREAM_UPDATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
PROJECT_ID = "YOUR PROJECT ID" | |
REGION = "us-central1" | |
# Bucket for Staging purposes | |
BUCKET = "DEFINE A BUCKET NAME" | |
BUCKET_URI = f"gs://{BUCKET}" |