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.
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.
Install
-
pip install langchain-google-community
Imports
- 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}.")