gemini-1.5-pro
, gemini-2.0-flash-exp
, etc.
It also provides some non-Google models such as Anthropic’s Claude.
This will help you getting started with ChatVertexAI
chat models. For detailed documentation of all ChatVertexAI
features and configurations head to the API reference.
Overview
Integration details
Class | Package | Local | Serializable | PY support | Downloads | Version |
---|---|---|---|---|---|---|
ChatVertexAI | @langchain/google-vertexai | ❌ | ✅ | ✅ |
Model features
See the links in the table headers below for guides on how to use specific features.Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
---|---|---|---|---|---|---|---|---|
✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Setup
LangChain.js supports two different authentication methods based on whether you’re running in a Node.js environment or a web environment. It also supports the authentication method used by Vertex AI Express Mode using either package. To accessChatVertexAI
models you’ll need to setup Google VertexAI in your Google Cloud Platform (GCP) account, save the credentials file, and install the @langchain/google-vertexai
integration package.
Credentials
Head to your GCP account and generate a credentials file. Once you’ve done this set theGOOGLE_APPLICATION_CREDENTIALS
environment variable:
GOOGLE_VERTEX_AI_WEB_CREDENTIALS
environment variable as a JSON stringified object, and install the @langchain/google-vertexai-web
package:
@langchain/google-vertexai
or @langchain/google-vertexai-web
package.
You can then go to the Express Mode API Key page and set your API Key in the GOOGLE_API_KEY
environment variable:
Installation
The LangChainChatVertexAI
integration lives in the @langchain/google-vertexai
package:
Instantiation
Now we can instantiate our model object and generate chat completions:Invocation
Tool Calling with Google Search Retrieval
It is possible to call the model with a Google search tool which you can use to ground content generation with real-world information and reduce hallucinations. Grounding is currently not supported bygemini-2.0-flash-exp
.
You can choose to either ground using Google Search or by using a custom data store. Here are examples of both:
Google Search Retrieval
Grounding example that uses Google Search:Google Search Retrieval with Data Store
First, set up your data store (this is a schema of an example data store):ID | Date | Team 1 | Score | Team 2 |
---|---|---|---|---|
3001 | 2023-09-07 | Argentina | 1 - 0 | Ecuador |
3002 | 2023-09-12 | Venezuela | 1 - 0 | Paraguay |
3003 | 2023-09-12 | Chile | 0 - 0 | Colombia |
3004 | 2023-09-12 | Peru | 0 - 1 | Brazil |
3005 | 2024-10-15 | Argentina | 6 - 0 | Bolivia |
projectId
and datastoreId
)