Class SpannerLoader (0.3.0)

SpannerLoader(
    instance_id: str,
    database_id: str,
    query: str,
    content_columns: typing.List[str] = [],
    metadata_columns: typing.List[str] = [],
    format: str = "text",
    databoost: bool = False,
    metadata_json_column: str = "langchain_metadata",
    staleness: typing.Union[float, datetime.datetime] = 0.0,
    client: typing.Optional[google.cloud.spanner_v1.client.Client] = None,
)

Loads data from Google Cloud Spanner.

Methods

SpannerLoader

SpannerLoader(
    instance_id: str,
    database_id: str,
    query: str,
    content_columns: typing.List[str] = [],
    metadata_columns: typing.List[str] = [],
    format: str = "text",
    databoost: bool = False,
    metadata_json_column: str = "langchain_metadata",
    staleness: typing.Union[float, datetime.datetime] = 0.0,
    client: typing.Optional[google.cloud.spanner_v1.client.Client] = None,
)

Initialize Spanner document loader.

Parameters
Name Description
instance_id str

The Spanner instance to load data from.

database_id str

The Spanner database to load data from.

query str

A GoogleSQL or PostgreSQL query. Users must match dialect to their database.

content_columns typing.List[str]

The list of column(s) or field(s) to use for a Document's page content. Page content is the default field for embeddings generation.

metadata_columns typing.List[str]

The list of column(s) or field(s) to use for metadata.

format str

Set the format of page content if using multiple columns or fields. Format included: 'text', 'JSON', 'YAML', 'CSV'.

databoost bool

Use data boost on read. Note: needs extra IAM permissions and higher cost.

metadata_json_column str

The name of the JSON column to use as the metadata's base dictionary.

staleness typing.Union[float, datetime.datetime]

The time bound for stale read. Takes either a datetime or float.

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

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

lazy_load

lazy_load() -> typing.Iterator[langchain_core.documents.base.Document]

A lazy loader for langchain documents from a Spanner database. Use lazy load to avoid caching all documents in memory at once.

Returns
Type Description
(Iterator[langchain_core.documents.Document]) a list of Documents with metadata from specific columns.

load

load() -> typing.List[langchain_core.documents.base.Document]

Load langchain documents from a Spanner database.

Returns
Type Description
(List[langchain_core.documents.Document]) a list of Documents with metadata from specific columns.