Class SpannerDocumentSaver (0.3.0)

SpannerDocumentSaver(
 instance_id: str,
 database_id: str,
 table_name: str,
 content_column: str = "page_content",
 metadata_columns: typing.List[str] = [],
 metadata_json_column: str = "langchain_metadata",
 primary_key: typing.Optional[str] = None,
 client: typing.Optional[google.cloud.spanner_v1.client.Client] = None,
)

Save docs to Google Cloud Spanner.

Methods

SpannerDocumentSaver

SpannerDocumentSaver(
 instance_id: str,
 database_id: str,
 table_name: str,
 content_column: str = "page_content",
 metadata_columns: typing.List[str] = [],
 metadata_json_column: str = "langchain_metadata",
 primary_key: typing.Optional[str] = None,
 client: typing.Optional[google.cloud.spanner_v1.client.Client] = None,
)

Initialize Spanner document saver.

Parameters
Name Description
instance_id str

The Spanner instance to load data to.

database_id str

The Spanner database to load data to.

table_name str

The table name to load data to.

content_column str

The name of the content column. Defaulted to the first column.

metadata_columns typing.List[str]

This is for user to opt-in a selection of columns to use. Defaulted to use all columns.

metadata_json_column str

The name of the special JSON column. Defaulted to use "langchain_metadata".

client typing.Optional[google.cloud.spanner_v1.client.Client]

The connection object to use. This can be used to customized project id and credentials.

add_documents

add_documents(documents: typing.List[langchain_core.documents.base.Document])

Add documents to the Spanner table.

create_table

create_table(
 client: google.cloud.spanner_v1.client.Client,
 instance_id: str,
 database_id: str,
 table_name: str,
 primary_key: str,
 metadata_json_column: str,
 content_column: str,
 metadata_columns: typing.List[langchain_google_spanner.loader.Column],
)

Create a new table in Spanner database.

Parameters
Name Description
client Client

The connection object to use.

instance_id str

The Spanner instance to load data to.

database_id str

The Spanner database to load data to.

table_name str

The table name to load data to.

primary_key str

The name of the primary key for the table.

metadata_json_column str

The name of the special JSON column.

content_column str

The name of the content column.

metadata_columns typing.List[langchain_google_spanner.loader.Column]

The metadata columns for custom schema.

delete

delete(documents: typing.List[langchain_core.documents.base.Document])

Delete documents from the table.

init_document_table

init_document_table(
 instance_id: str,
 database_id: str,
 table_name: str,
 content_column: str = "page_content",
 metadata_columns: typing.List[langchain_google_spanner.loader.Column] = [],
 primary_key: str = "",
 store_metadata: bool = True,
 metadata_json_column: str = "langchain_metadata",
)

Create a new table to store docs with a custom schema.

Parameters
Name Description
instance_id str

The Spanner instance to load data to.

database_id str

The Spanner database to load data to.

table_name str

The table name to load data to.

content_column str

The name of the content column.

metadata_columns typing.List[langchain_google_spanner.loader.Column]

The metadata columns for custom schema.

primary_key str

The name of the primary key.

store_metadata bool

If true, extra metadata will be stored in the "langchain_metadata" column. Defaulted to true.

metadata_json_column str

The name of the special JSON column. Defaulted to use "langchain_metadata".

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.