All functionality related to Google Cloud Platform and other Google
products.
Integration packages for Gemini models and the VertexAI platform are maintained in the langchain-google repository. You can find a host of LangChain integrations with other Google APIs in the googleapis Github organization.
Chat models
We recommend individual developers to start with Gemini API (langchain-google-genai
) and move to Vertex AI (langchain-google-vertexai
) when they need access to commercial support and higher rate limits. If you’re already Cloud-friendly or Cloud-native, then you can get started in Vertex AI straight away.
Please see here for more information.
Google Generative AI
Access GoogleAI Gemini
models such as gemini-pro
and gemini-pro-vision
through the ChatGoogleGenerativeAI
class.
pip install -U langchain-google-genai
Configure your API key.
export GOOGLE_API_KEY=your-api-key
from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm.invoke("Sing a ballad of LangChain.")
Gemini vision model supports image inputs when providing a single chat message.
from langchain_core.messages import HumanMessage
from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro-vision")
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
}, # You can optionally provide text parts
{"type": "image_url", "image_url": "https://picsum.photos/seed/picsum/200/300"},
]
)
llm.invoke([message])
The value of image_url can be any of the following:
- A public image URL
- A gcs file (e.g., "gcs://path/to/file.png")
- A local file path
- A base64 encoded image (e.g., data:image/png;base64,abcd124)
- A PIL image
Vertex AI
Access chat models like Gemini
via Google Cloud.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
See a usage example.
from langchain_google_vertexai import ChatVertexAI
Anthropic on Vertex AI Model Garden
See a usage example.
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
Llama on Vertex AI Model Garden
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
Mistral on Vertex AI Model Garden
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral
Gemma local from Hugging Face
Local
Gemma
model loaded fromHuggingFace
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatLocalHF
Gemma local from Kaggle
Local
Gemma
model loaded fromKaggle
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle
Gemma on Vertex AI Model Garden
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden
Vertex AI image captioning
Implementation of the
Image Captioning model
as a chat.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChat
Vertex AI image editor
Given an image and a prompt, edit the image. Currently only supports mask-free editing.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.vision_models import VertexAIImageEditorChat
Vertex AI image generator
Generates an image from a prompt.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat
Vertex AI visual QnA
Chat implementation of a visual QnA model
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.vision_models import VertexAIVisualQnAChat
LLMs
Google Generative AI
Access GoogleAI Gemini
models such as gemini-pro
and gemini-pro-vision
through the GoogleGenerativeAI
class.
Install python package.
pip install langchain-google-genai
See a usage example.
from langchain_google_genai import GoogleGenerativeAI
Vertex AI Model Garden
Access PaLM
and hundreds of OSS models via Vertex AI Model Garden
service.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
See a usage example.
from langchain_google_vertexai import VertexAIModelGarden
Gemma local from Hugging Face
Local
Gemma
model loaded fromHuggingFace
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaLocalHF
Gemma local from Kaggle
Local
Gemma
model loaded fromKaggle
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaLocalKaggle
Gemma on Vertex AI Model Garden
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden
Vertex AI image captioning
Implementation of the
Image Captioning model
as an LLM.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.vision_models import VertexAIImageCaptioning
Embedding models
Google Generative AI embedding
See a usage example.
pip install -U langchain-google-genai
Configure your API key.
export GOOGLE_API_KEY=your-api-key
from langchain_google_genai import GoogleGenerativeAIEmbeddings
Google Generative AI server-side embedding
Install the python package:
pip install langchain-google-genai
from langchain_google_genai.google_vector_store import ServerSideEmbedding
Vertex AI
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
See a usage example.
from langchain_google_vertexai import VertexAIEmbeddings
Palm embedding
We need to install langchain-community
python package.
pip install langchain-community
from langchain_community.embeddings.google_palm import GooglePalmEmbeddings
Document Loaders
AlloyDB for PostgreSQL
Google Cloud AlloyDB is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability on Google Cloud. AlloyDB is 100% compatible with PostgreSQL.
Install the python package:
pip install langchain-google-alloydb-pg
See usage example.
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBLoader
BigQuery
Google Cloud BigQuery is a serverless and cost-effective enterprise data warehouse that works across clouds and scales with your data in Google Cloud.
We need to install langchain-google-community
with Big Query dependencies:
pip install langchain-google-community[bigquery]
See a usage example.
from langchain_google_community import BigQueryLoader