|
| 1 | +# Bigtable |
| 2 | + |
| 3 | +Bigtable is a scalable, fully managed key-value and wide-column store ideal for fast access to structured, semi-structured, or unstructured data. This page provides an overview of Bigtable's LangChain integrations. |
| 4 | + |
| 5 | +**Client Library Documentation:** [cloud.google.com/python/docs/reference/langchain-google-bigtable/latest](https://cloud.google.com/python/docs/reference/langchain-google-bigtable/latest) |
| 6 | + |
| 7 | +**Product Documentation:** [cloud.google.com/bigtable](https://cloud.google.com/bigtable) |
| 8 | + |
| 9 | +## Quick Start |
| 10 | + |
| 11 | +To use this library, you first need to: |
| 12 | + |
| 13 | +1. Select or create a Cloud Platform project. |
| 14 | +2. Enable billing for your project. |
| 15 | +3. Enable the Google Cloud Bigtable API. |
| 16 | +4. Set up Authentication. |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +The main package for this integration is `langchain-google-bigtable`. |
| 21 | + |
| 22 | +```bash |
| 23 | +pip install -U langchain-google-bigtable |
| 24 | +``` |
| 25 | + |
| 26 | +## Integrations |
| 27 | + |
| 28 | +The `langchain-google-bigtable` package provides the following integrations: |
| 29 | + |
| 30 | +### Document Loader |
| 31 | + |
| 32 | +Use the `BigtableLoader` to load data from a Bigtable table and represent it as LangChain `Document` objects. |
| 33 | + |
| 34 | +```python |
| 35 | +from langchain_google_bigtable import BigtableLoader |
| 36 | + |
| 37 | +loader = BigtableLoader( |
| 38 | + project_id="your-project-id", |
| 39 | + instance_id="your-instance-id", |
| 40 | + table_id="your-table-name" |
| 41 | +) |
| 42 | +docs = loader.load() |
| 43 | +``` |
| 44 | + |
| 45 | +Learn more in the [Document Loader how-to guide](https://cloud.google.com/python/docs/reference/langchain-google-bigtable/latest/document-loader). |
| 46 | + |
| 47 | +### Chat Message History |
| 48 | + |
| 49 | +Use `BigtableChatMessageHistory` to store conversation histories, enabling stateful chains and agents. |
| 50 | + |
| 51 | +```python |
| 52 | +from langchain_google_bigtable import BigtableChatMessageHistory |
| 53 | + |
| 54 | +history = BigtableChatMessageHistory( |
| 55 | + project_id="your-project-id", |
| 56 | + instance_id="your-instance-id", |
| 57 | + table_id="your-message-store", |
| 58 | + session_id="user-session-123" |
| 59 | +) |
| 60 | + |
| 61 | +history.add_user_message("Hello!") |
| 62 | +history.add_ai_message("Hi there!") |
| 63 | +``` |
| 64 | + |
| 65 | +Learn more in the [Chat Message History how-to guide](https://cloud.google.com/python/docs/reference/langchain-google-bigtable/latest/chat-message-history). |
| 66 | + |
| 67 | +### Vector Store |
| 68 | + |
| 69 | +With `BigtableVectorStore`, you can store documents and their vector embeddings to find the most similar or relevant information in your database. |
| 70 | + |
| 71 | +* **Full `VectorStore` Implementation:** Supports all methods from the LangChain `VectorStore` abstract class. |
| 72 | +* **Async/Sync Support:** All methods are available in both asynchronous and synchronous versions. |
| 73 | +* **Metadata Filtering:** Powerful filtering on metadata fields, including logical AND/OR combinations. |
| 74 | +* **Multiple Distance Strategies:** Supports both Cosine and Euclidean distance for similarity search. |
| 75 | +* **Customizable Storage:** Full control over how content, embeddings, and metadata are stored in Bigtable columns. |
| 76 | + |
| 77 | +```python |
| 78 | +from langchain_google_bigtable import BigtableVectorStore |
| 79 | + |
| 80 | +# Your embedding service and other configurations |
| 81 | +# embedding_service = ... |
| 82 | + |
| 83 | +engine = await BigtableEngine.async_initialize(project_id="your-project-id") |
| 84 | +vector_store = await BigtableVectorStore.create( |
| 85 | + engine=engine, |
| 86 | + instance_id="your-instance-id", |
| 87 | + table_id="your-table-id", |
| 88 | + embedding_service=embedding_service, |
| 89 | + collection="your_collection_name", |
| 90 | +) |
| 91 | +await vector_store.aadd_documents([your_documents]) |
| 92 | +results = await vector_store.asimilarity_search("your query") |
| 93 | +``` |
| 94 | + |
| 95 | +Learn more in the [Vector Store how-to guide](https://colab.research.google.com/github/googleapis/langchain-google-bigtable-python/blob/main/docs/vector_store.ipynb). |
| 96 | + |
| 97 | +### Key-value Store |
| 98 | + |
| 99 | +Use `BigtableByteStore` as a persistent, scalable key-value store for caching, session management, or other storage needs. It supports both synchronous and asynchronous operations. |
| 100 | + |
| 101 | +```python |
| 102 | +from langchain_google_bigtable import BigtableByteStore |
| 103 | + |
| 104 | +# Initialize the store |
| 105 | +store = await BigtableByteStore.create( |
| 106 | + project_id="your-project-id", |
| 107 | + instance_id="your-instance-id", |
| 108 | + table_id="your-table-id", |
| 109 | +) |
| 110 | + |
| 111 | +# Set and get values |
| 112 | +await store.amset([("key1", b"value1")]) |
| 113 | +retrieved = await store.amget(["key1"]) |
| 114 | +``` |
| 115 | + |
| 116 | +Learn more in the [Key-value Store how-to guide](https://cloud.google.com/python/docs/reference/langchain-google-bigtable/latest/key-value-store). |
| 117 | + |
| 118 | +## Contributions |
| 119 | + |
| 120 | +Contributions to this library are welcome. Please see the CONTRIBUTING guide in the [package repo](https://github.com/googleapis/langchain-google-bigtable-python/) for more details |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +This project is licensed under the Apache 2.0 License - see the LICENSE file in the [package repo](https://github.com/googleapis/langchain-google-bigtable-python/blob/main/LICENSE) for details. |
| 125 | + |
| 126 | +## Disclaimer |
| 127 | + |
| 128 | +This is not an officially supported Google product. |
0 commit comments