langchain-google-vertexai: 2.0.27#

LangChain Google Generative AI Integration

This module contains the LangChain integrations for Vertex AI service - Google foundational models, third-party foundational modela available on Vertex Model Garden and.

Supported integrations

  1. Google’s foundational models: Gemini family, Codey, embeddings - ChatVertexAI, VertexAI, VertexAIEmbeddings.

  2. Other Google’s foundational models: Imagen - VertexAIImageCaptioning, VertexAIImageCaptioningChat, VertexAIImageEditorChat, VertexAIImageGeneratorChat, VertexAIVisualQnAChat.

  3. Third-party foundational models available as a an API (mdel-as-a-service) on Vertex Model Garden (Mistral, Llama, Anthropic) - model_garden.ChatAnthropicVertex, model_garden_maas.VertexModelGardenLlama, model_garden_maas.VertexModelGardenMistral.

  4. Third-party foundational models deployed on Vertex AI endpoints from Vertex Model Garden or Huggingface - VertexAIModelGarden.

  5. Gemma deployed on Vertex AI endpoints or locally - GemmaChatLocalHF, GemmaChatLocalKaggle, GemmaChatVertexAIModelGarden, GemmaLocalHF, GemmaLocalKaggle, GemmaVertexAIModelGarden.

  6. Vector Search on Vertex AI - VectorSearchVectorStore, VectorSearchVectorStoreDatastore, VectorSearchVectorStoreGCS.

  7. Vertex AI evaluators for generative AI - VertexPairWiseStringEvaluator, VertexStringEvaluator.

Take a look at detailed documentation for each class for further details.

Installation

You need to enable required Google Cloud APIs (depending on the integration you’re using) and set up credentials by either:
  • Having credentials configured for your environment (gcloud, workload identity, etc…)

  • Storing the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable

This codebase uses the google.auth library which first looks for the application credentials variable mentioned above, and then looks for system-level auth.

More information:

callbacks#

Classes

callbacks.VertexAICallbackHandler()

Callback Handler that tracks VertexAI info.

chains#

Functions

chains.create_structured_runnable(function, ...)

Create a runnable sequence that uses OpenAI functions.

chains.get_output_parser(functions)

Get the appropriate function output parser given the user functions.

chat_models#

Classes

chat_models.ChatVertexAI

Google Cloud Vertex AI chat model integration.

embeddings#

Classes

evaluators#

Classes

evaluators.evaluation.VertexPairWiseStringEvaluator(...)

Evaluate the perplexity of a predicted string.

evaluators.evaluation.VertexStringEvaluator(...)

Evaluate the perplexity of a predicted string.

functions_utils#

Classes

functions_utils.PydanticFunctionsOutputParser

Parse an output as a pydantic object.

gemma#

Classes

gemma.GemmaChatLocalHF

gemma.GemmaChatLocalKaggle

Needed for mypy typing to recognize model_name as a valid arg.

gemma.GemmaChatVertexAIModelGarden

Needed for mypy typing to recognize model_name as a valid arg.

gemma.GemmaLocalHF

Local gemma model loaded from HuggingFace.

gemma.GemmaLocalKaggle

Local gemma chat model loaded from Kaggle.

gemma.GemmaVertexAIModelGarden

Create a new model by parsing and validating input data from keyword arguments.

Functions

gemma.gemma_messages_to_prompt(history)

Converts a list of messages to a chat prompt for Gemma.

llms#

Classes

llms.VertexAI

Google Vertex AI large language models.

model_garden#

Classes

model_garden.CacheUsageMetadata

model_garden.ChatAnthropicVertex

Create a new model by parsing and validating input data from keyword arguments.

model_garden.VertexAIModelGarden

Large language models served from Vertex AI Model Garden.

model_garden_maas#

Classes

model_garden_maas.llama.VertexModelGardenLlama

Integration for Llama 3.1 on Google Cloud Vertex AI Model-as-a-Service.

model_garden_maas.mistral.VertexModelGardenMistral

Create a new model by parsing and validating input data from keyword arguments.

utils#

Functions

utils.create_context_cache(model, messages)

Creates a cache for content in some model.

vectorstores#

Classes

vectorstores.document_storage.DataStoreDocumentStorage(...)

Stores documents in Google Cloud DataStore.

vectorstores.document_storage.DocumentStorage()

Abstract interface of a key, text storage for retrieving documents.

vectorstores.document_storage.GCSDocumentStorage(bucket)

Stores documents in Google Cloud Storage.

vectorstores.vectorstores.VectorSearchVectorStore(...)

VertexAI VectorStore that handles the search and indexing using Vector Search and stores the documents in Google Cloud Storage.

vectorstores.vectorstores.VectorSearchVectorStoreDatastore(...)

VectorSearch with DatasTore document storage.

vectorstores.vectorstores.VectorSearchVectorStoreGCS(...)

Alias of VectorSearchVectorStore for consistency with the rest of vector stores with different document storage backends.

vision_models#

Classes

vision_models.VertexAIImageCaptioning

Implementation of the Image Captioning model as an LLM.

vision_models.VertexAIImageCaptioningChat

Implementation of the Image Captioning model as a chat.

vision_models.VertexAIImageEditorChat

Given an image and a prompt, edits the image.

vision_models.VertexAIImageGeneratorChat

Generates an image from a prompt.

vision_models.VertexAIVisualQnAChat

Chat implementation of a visual QnA model