LangChain Google Community
langchain-google-community is an integration package that connects LangChain with various miscellaneous Google products and services, such as BigQuery, Document AI, Firestore, and Google Cloud Storage. As of version 3.0.5, it provides components like chat message histories, document loaders, and vector stores for these services. The library follows a frequent release cadence, often aligning with updates in the broader LangChain ecosystem.
Common errors
-
ModuleNotFoundError: No module named 'langchain_community'
cause This error occurs when the `langchain-community` package, which contains many common LangChain integrations and components, is not installed in your Python environment. Many modules, including base classes for features used by `langchain-google-community`, were moved from the core `langchain` package to `langchain-community`.fixInstall the `langchain-community` package: `pip install langchain-community` -
ModuleNotFoundError: No module named 'langchain_google_genai'
cause This specific error indicates that the `langchain-google-genai` package, which provides integrations for Google's Generative AI models (like Gemini), is not installed. Although `langchain-google-community` offers various Google integrations, specific LLM providers often reside in separate integration packages.fixInstall the `langchain-google-genai` package: `pip install langchain-google-genai` -
GoogleAuthError: DefaultCredentialsError: ('_CLOUD_SDK_MISSING_CREDENTIALS', 'Cloud SDK not found. Please install it or set the GOOGLE_APPLICATION_CREDENTIALS environment variable.')cause This authentication error arises when your application attempts to use Google Cloud services (e.g., Vertex AI models via `langchain_google_vertexai`, which is often used alongside `langchain-google-community` components) and cannot find appropriate credentials. This often means the Google Cloud SDK is not installed or configured, or the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to a service account key file is not set.fixIf using `ChatVertexAI` or other Vertex AI components, ensure Google Cloud SDK is installed and authenticated (`gcloud auth application-default login`) or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account JSON key file. Alternatively, for many Gemini API uses, you can often switch to `langchain_google_genai.ChatGoogleGenerativeAI` and provide a `google_api_key`. -
LangChainDeprecationWarning: Importing vector stores from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain_community instead: `from langchain_community.vectorstores import faiss`
cause This warning (which can lead to `ModuleNotFoundError` or `AttributeError` in newer versions) occurs because of a significant restructuring in the LangChain ecosystem. Many core components, including various vector store implementations, have been moved from the main `langchain` package to the `langchain-community` package to promote modularity.fixUpdate your import statements to use `langchain_community` for vector stores and other moved components. For example, change `from langchain.vectorstores import FAISS` to `from langchain_community.vectorstores import FAISS`.
Warnings
- breaking This library has strict version constraints on `langchain` and `langchain-core` (currently `<0.3.0,>=0.2.0`). Upgrading your main `langchain` installation beyond these bounds will break functionality in `langchain-google-community`.
- gotcha Google Cloud authentication is required for all integrations. The library relies on Google Application Default Credentials (ADC). Common setup involves `gcloud auth application-default login` or setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
- gotcha Many specific components are imported from submodules (e.g., `langchain_google_community.chat_message_histories`, `langchain_google_community.documentai`, `langchain_google_community.vectorstores`). Importing directly from `langchain_google_community` for these specific classes will result in an `ImportError`.
- gotcha `langchain-google-community` does not include integrations for Google Generative AI models (Gemini) or Vertex AI (LLMs, embeddings, vector search). These are provided by separate packages: `langchain-google-genai` and `langchain-google-vertexai`, respectively.
- breaking The `langchain-google-community` package must be installed in your Python environment for any of its components to be importable. If the package is not installed, you will encounter `ModuleNotFoundError`.
Install
-
pip install langchain-google-community
Imports
- BigQueryChatMessageHistory
from langchain_google_community import BigQueryChatMessageHistory
from langchain_google_community.chat_message_histories import BigQueryChatMessageHistory
- DocumentAIWrapper
from langchain_google_community.documentai import DocumentAIWrapper
- FirestoreVectorStore
from langchain_google_community.vectorstores import FirestoreVectorStore
- BigQueryCallbackHandler
from langchain_google_community.bigquery import BigQueryCallbackHandler
Quickstart
import os
from langchain_google_community.chat_message_histories import BigQueryChatMessageHistory
from langchain_core.messages import HumanMessage, AIMessage
# Ensure you have GOOGLE_CLOUD_PROJECT, BIGQUERY_DATASET_NAME, BIGQUERY_TABLE_NAME set as environment variables
# or pass them directly to the constructor.
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-gcp-project-id')
dataset_name = os.environ.get('BIGQUERY_DATASET_NAME', 'langchain_chat_history')
table_name = os.environ.get('BIGQUERY_TABLE_NAME', 'chat_sessions')
session_id = 'test_session_123'
if not all([project_id, dataset_name, table_name]) or project_id == 'your-gcp-project-id':
print("Warning: Skipping BigQuery history quickstart. Please set GOOGLE_CLOUD_PROJECT, BIGQUERY_DATASET_NAME, and BIGQUERY_TABLE_NAME environment variables.")
print("Alternatively, replace 'your-gcp-project-id' with a valid project ID.")
else:
try:
# Initialize BigQuery Chat Message History
history = BigQueryChatMessageHistory(
project_id=project_id,
dataset_name=dataset_name,
table_name=table_name,
session_id=session_id
)
# Add messages
history.add_user_message("Hi there!")
history.add_ai_message("Hello! How can I help you today?")
history.add_message(HumanMessage(content="Tell me a joke."))
history.add_message(AIMessage(content="Why don't scientists trust atoms? Because they make up everything!"))
# Retrieve messages
messages = history.messages
print(f"Retrieved {len(messages)} messages for session '{session_id}':")
for msg in messages:
print(f" {type(msg).__name__}: {msg.content}")
# Clear messages (optional, for cleanup)
# history.clear()
# print("History cleared.")
except Exception as e:
print(f"Error running BigQuery history quickstart: {e}")
print("Ensure you have authenticated with Google Cloud (e.g., `gcloud auth application-default login`) and BigQuery API is enabled in project: {project_id}.")