Spanner is a highly scalable database that combines unlimited scalability with relational semantics, such as secondary indexes, strong consistency, schemas, and SQL providing 99.999% availability in one easy solution.This notebook goes over how to use Spanner to save, load and delete langchain documents with
SpannerLoader
and SpannerDocumentSaver
.
Learn more about the package on GitHub.
langchain-google-spanner
package, so we need to install it.
gcloud config list
.gcloud projects list
.SpannerDocumentSaver.add_documents(<documents>)
. To initialize SpannerDocumentSaver
class you need to provide 3 things:
instance_id
- An instance of Spanner to load data from.database_id
- An instance of Spanner database to load data from.table_name
- The name of the table within the Spanner database to store langchain documents.SpannerLoader.load()
or SpannerLoader.lazy_load()
. lazy_load
returns a generator that only queries database during the iteration. To initialize SpannerLoader
class you need to provide:
instance_id
- An instance of Spanner to load data from.database_id
- An instance of Spanner database to load data from.query
- A query of the database dialect.SpannerDocumentSaver.delete(<documents>)
.
credentials
and project
explicitly, a custom client can be passed to the constructor.
page_content
. These defaults can be changed like so:
text
(space-separated string concatenation). There are other format that user can specify, including text
, JSON
, YAML
, CSV
.
langchain_metadata
that store JSON data. The metadata column will be used as the base dictionary. By default, all other column data will be added and may overwrite the original value. These defaults can be changed like so:
langchain_metadata
as the base dictionary. This can be customized to select a JSON column to use as base dictionary for the Document’s metadata.
credentials
and project
explicitly, a custom client can be passed to the constructor.
page_content
.
metadata_columns: These metadata will be saved into specific columns if the key exists in the Document’s metadata.
metadata_json_column: This will be the column name for the spcial JSON column. Defaulted to langchain_metadata
.
init_document_table
method to create a new table to store docs with custom schema.