BigtableByteStore
This guide covers how to use Google Cloud Bigtable as a key-value store. Bigtable is a key-value and wide-column store, ideal for fast access to structured, semi-structured, or unstructured data.Overview
TheBigtableByteStore uses Google Cloud Bigtable as a backend for a key-value store. It supports synchronous and asynchronous operations for setting, getting, and deleting key-value pairs.
Integration details
| Class | Package | Local | JS support | Package downloads | Package latest |
|---|---|---|---|---|---|
| BigtableByteStore | langchain-google-bigtable | ❌ | ❌ |
Setup
Prerequisites
To get started, you will need a Google Cloud project with an active Bigtable instance and table.Installation
The integration is in thelangchain-google-bigtable package. The command below also installs langchain-google-vertexai for the embedding cache example.
Set your Google Cloud project
Set your Google Cloud project to use its resources within this notebook. If you don’t know your project ID, you can rungcloud config list or see the support page: Locate the project ID.
Authentication
Authenticate to Google Cloud to access your project resources.- For Colab, use the cell below.
- For Vertex AI Workbench, see the setup instructions.
Instantiation
To useBigtableByteStore, we first ensure a table exists and then initialize a BigtableEngine to manage connections.
BigtableEngine
ABigtableEngine object handles the execution context for the store, especially for async operations. It’s recommended to initialize a single engine and reuse it across multiple stores for better performance.
BigtableByteStore
This is the main class for interacting with the key-value store. It provides the methods for setting, getting, and deleting data.Usage
The store supports both sync (mset, mget) and async (amset, amget) methods. This guide uses the async versions.
Set
Useamset to save key-value pairs to the store.
Get
Useamget to retrieve values. If a key is not found, None is returned for that key.
Delete
Useamdelete to remove keys from the store.
Iterate over keys
Useayield_keys to iterate over all keys or keys with a specific prefix.
Advanced usage: embedding caching
A common use case for a key-value store is to cache expensive operations like computing text embeddings, which saves time and cost.As a simple document retriever
This section shows how to create a simple retriever using the Bigtable store. It acts as a document persistence layer, fetching documents that match a query prefix.API reference
For full details on theBigtableByteStore class, see the source code on GitHub.