Skip to main content

Google

All functionality related to Google Cloud Platform and other Google products.

Chat models

Google 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. Example:

from langchain_core.messages import HumanMessage
from langchain_google_genai import ChatGoogleGenerativeAI

llm = ChatGoogleGenerativeAI(model="gemini-pro-vision")
# example
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 PaLM chat models like chat-bison and codechat-bison via Google Cloud.

We need to install google-cloud-aiplatform python package.

pip install google-cloud-aiplatform

See a usage example.

from langchain.chat_models import ChatVertexAI

Document Loaders

Google BigQuery

Google BigQuery is a serverless and cost-effective enterprise data warehouse that works across clouds and scales with your data. BigQuery is a part of the Google Cloud Platform.

We need to install google-cloud-bigquery python package.

pip install google-cloud-bigquery

See a usage example.

from langchain.document_loaders import BigQueryLoader

LLMs

Vertex AI

Access to Gemini and PaLM LLMs (like text-bison and code-bison) via Google Vertex AI.

We need to install google-cloud-aiplatform python package.

pip install google-cloud-aiplatform

See a usage example.

from langchain.llms import VertexAI

Model Garden

Access PaLM and hundreds of OSS models via Vertex AI Model Garden.

We need to install google-cloud-aiplatform python package.

pip install google-cloud-aiplatform

See a usage example.

from langchain.llms import VertexAIModelGarden

Google Cloud Storage

Google Cloud Storage is a managed service for storing unstructured data.

We need to install google-cloud-storage python package.

pip install google-cloud-storage

There are two loaders for the Google Cloud Storage: the Directory and the File loaders.

See a usage example.

from langchain.document_loaders import GCSDirectoryLoader

See a usage example.

from langchain.document_loaders import GCSFileLoader

Google Drive

Google Drive is a file storage and synchronization service developed by Google.

Currently, only Google Docs are supported.

We need to install several python packages.

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib

See a usage example and authorization instructions.

from langchain.document_loaders import GoogleDriveLoader

Speech-to-Text

Google Cloud Speech-to-Text is an audio transcription API powered by Google's speech recognition models.

This document loader transcribes audio files and outputs the text results as Documents.

First, we need to install the python package.

pip install google-cloud-speech

See a usage example and authorization instructions.

from langchain.document_loaders import GoogleSpeechToTextLoader

Vector Stores

Google Vertex AI Vector Search, formerly known as Vertex AI Matching Engine, provides the industry's leading high-scale low latency vector database. These vector databases are commonly referred to as vector similarity-matching or an approximate nearest neighbor (ANN) service.

We need to install several python packages.

pip install tensorflow google-cloud-aiplatform tensorflow-hub tensorflow-text

See a usage example.

from langchain.vectorstores import MatchingEngine

Google ScaNN

Google ScaNN (Scalable Nearest Neighbors) is a python package.

ScaNN is a method for efficient vector similarity search at scale.

ScaNN includes search space pruning and quantization for Maximum Inner Product Search and also supports other distance functions such as Euclidean distance. The implementation is optimized for x86 processors with AVX2 support. See its Google Research github for more details.

We need to install scann python package.

pip install scann

See a usage example.

from langchain.vectorstores import ScaNN

Retrievers

Google Drive

We need to install several python packages.

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib

See a usage example and authorization instructions.

from langchain_googledrive.retrievers import GoogleDriveRetriever

Google Cloud Vertex AI Search allows developers to quickly build generative AI powered search engines for customers and employees.

We need to install the google-cloud-discoveryengine python package.

pip install google-cloud-discoveryengine

See a usage example.

from langchain.retrievers import GoogleVertexAISearchRetriever

Document AI Warehouse

Google Cloud Document AI Warehouse allows enterprises to search, store, govern, and manage documents and their AI-extracted data and metadata in a single platform.

from langchain.retrievers import GoogleDocumentAIWarehouseRetriever
docai_wh_retriever = GoogleDocumentAIWarehouseRetriever(
project_number=...
)
query = ...
documents = docai_wh_retriever.get_relevant_documents(
query, user_ldap=...
)

Tools

Google Cloud Text-to-Speech

Google Cloud Text-to-Speech enables developers to synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible.

We need to install a python package.

pip install google-cloud-text-to-speech

See a usage example and authorization instructions.

from langchain.tools import GoogleCloudTextToSpeechTool

Google Drive

We need to install several python packages.

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib

See a usage example and authorization instructions.

from langchain.utilities.google_drive import GoogleDriveAPIWrapper
from langchain.tools.google_drive.tool import GoogleDriveSearchTool

Google Places

We need to install a python package.

pip install googlemaps

See a usage example and authorization instructions.

from langchain.tools import GooglePlacesTool
  • Set up a Custom Search Engine, following these instructions
  • Get an API Key and Custom Search Engine ID from the previous step, and set them as environment variables GOOGLE_API_KEY and GOOGLE_CSE_ID respectively.
from langchain.utilities import GoogleSearchAPIWrapper

For a more detailed walkthrough of this wrapper, see this notebook.

We can easily load this wrapper as a Tool (to use with an Agent). We can do this with:

from langchain.agents import load_tools
tools = load_tools(["google-search"])

Google Finance

We need to install a python package.

pip install google-search-results

See a usage example and authorization instructions.

from langchain.tools.google_finance import GoogleFinanceQueryRun
from langchain.utilities.google_finance import GoogleFinanceAPIWrapper

Google Jobs

We need to install a python package.

pip install google-search-results

See a usage example and authorization instructions.

from langchain.tools.google_jobs import GoogleJobsQueryRun
from langchain.utilities.google_finance import GoogleFinanceAPIWrapper

Google Lens

See a usage example and authorization instructions.

from langchain.tools.google_lens import GoogleLensQueryRun
from langchain.utilities.google_lens import GoogleLensAPIWrapper

Google Scholar

We need to install a python package.

pip install google-search-results

See a usage example and authorization instructions.

from langchain.tools.google_scholar import GoogleScholarQueryRun
from langchain.utilities.google_scholar import GoogleScholarAPIWrapper

We need to install a python package.

pip install google-search-results

See a usage example and authorization instructions.

from langchain.tools.google_trends import GoogleTrendsQueryRun
from langchain.utilities.google_trends import GoogleTrendsAPIWrapper

Document Transformers

Google Document AI

Document AI is a Google Cloud Platform service that transforms unstructured data from documents into structured data, making it easier to understand, analyze, and consume.

We need to set up a GCS bucket and create your own OCR processor
The GCS_OUTPUT_PATH should be a path to a folder on GCS (starting with gs://) and a processor name should look like projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID. We can get it either programmatically or copy from the Prediction endpoint section of the Processor details tab in the Google Cloud Console.

pip install google-cloud-documentai
pip install google-cloud-documentai-toolbox

See a usage example.

from langchain.document_loaders.blob_loaders import Blob
from langchain.document_loaders.parsers import DocAIParser

Google Translate

Google Translate is a multilingual neural machine translation service developed by Google to translate text, documents and websites from one language into another.

The GoogleTranslateTransformer allows you to translate text and HTML with the Google Cloud Translation API.

To use it, you should have the google-cloud-translate python package installed, and a Google Cloud project with the Translation API enabled. This transformer uses the Advanced edition (v3).

First, we need to install the python package.

pip install google-cloud-translate

See a usage example and authorization instructions.

from langchain.document_transformers import GoogleTranslateTransformer

Toolkits

GMail

Gmail is a free email service provided by Google. This toolkit works with emails through the Gmail API.

We need to install several python packages.

pip install google-api-python-client google-auth-oauthlib google-auth-httplib2

See a usage example and authorization instructions.

from langchain.agents.agent_toolkits import GmailToolkit

Chat Loaders

GMail

Gmail is a free email service provided by Google. This loader works with emails through the Gmail API.

We need to install several python packages.

pip install google-api-python-client google-auth-oauthlib google-auth-httplib2

See a usage example and authorization instructions.

from langchain.chat_loaders.gmail import GMailLoader

3rd Party Integrations

SearchApi

SearchApi provides a 3rd-party API to access Google search results, YouTube search & transcripts, and other Google-related engines.

See usage examples and authorization instructions.

from langchain.utilities import SearchApiAPIWrapper

SerpAPI

SerpApi provides a 3rd-party API to access Google search results.

See a usage example and authorization instructions.

from langchain.utilities import SerpAPIWrapper

Serper.dev

See a usage example and authorization instructions.

from langchain.utilities import GoogleSerperAPIWrapper

YouTube

YouTube Search package searches YouTube videos avoiding using their heavily rate-limited API.

It uses the form on the YouTube homepage and scrapes the resulting page.

We need to install a python package.

pip install youtube_search

See a usage example.

from langchain.tools import YouTubeSearchTool

YouTube audio

YouTube is an online video sharing and social media platform created by Google.

Use YoutubeAudioLoader to fetch / download the audio files.

Then, use OpenAIWhisperParser to transcribe them to text.

We need to install several python packages.

pip install yt_dlp pydub librosa

See a usage example and authorization instructions.

from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
from langchain.document_loaders.parsers import OpenAIWhisperParser, OpenAIWhisperParserLocal

YouTube transcripts

YouTube is an online video sharing and social media platform created by Google.

We need to install youtube-transcript-api python package.

pip install youtube-transcript-api

See a usage example.

from langchain.document_loaders import YoutubeLoader