Skip to content

Instantly share code, notes, and snippets.

@amandafbri
amandafbri / A2_search.py
Last active August 7, 2024 15:28
RAG usando Vertex AI Search e Gemini (PT2)
# 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,
@amandafbri
amandafbri / A1_configuration.py
Created August 6, 2024 17:15
RAG usando Vertex AI Search e Gemini (PT1)
# 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
@amandafbri
amandafbri / 6_testing_after_ingestion.py
Last active August 6, 2024 14:18
RAG super customizado com Vertex AI Vector Search e LangChain (PT6)
# 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
@amandafbri
amandafbri / 5_vector_search_ingestion.py
Last active August 6, 2024 14:18
RAG super customizado com Vertex AI Vector Search e LangChain (PT5)
# 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,
@amandafbri
amandafbri / 4_prepare_pdf_ingestion.py
Last active August 6, 2024 14:18
RAG super customizado com Vertex AI Vector Search e LangChain (PT4)
# Copyright 2024 Google LLC.
# SPDX-License-Identifier: Apache-2.0
from google.cloud import storage
from langchain_google_vertexai import (
VectorSearchVectorStore,
VectorSearchVectorStoreDatastore,
)
@amandafbri
amandafbri / 3_index_endpoint_referencing.py
Last active August 6, 2024 14:18
RAG super customizado com Vertex AI Vector Search e LangChain (PT3)
# 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")
@amandafbri
amandafbri / 2_index_endpoint_creation.py
Last active August 6, 2024 14:18
RAG super customizado com Vertex AI Vector Search e LangChain (PT2)
# 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
@amandafbri
amandafbri / 1_configuration.py
Last active August 6, 2024 14:17
RAG super customizado com Vertex AI Vector Search e LangChain
# 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}"