Class AlloyDBLoader (0.5.0)

AlloyDBLoader(
    key: object,
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    query: str,
    content_columns: typing.List[str],
    metadata_columns: typing.List[str],
    formatter: typing.Callable[
        [typing.Dict[str, typing.Any], typing.Iterable[str]], str
    ],
    metadata_json_column: typing.Optional[str] = None,
)

Load documents from AlloyDB`.

Each document represents one row of the result. The content_columns are written into the content_columns of the document. The metadata_columns are written into the metadata_columns of the document. By default, first columns is written into the page_content and everything else into the metadata.

Methods

AlloyDBLoader

AlloyDBLoader(
    key: object,
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    query: str,
    content_columns: typing.List[str],
    metadata_columns: typing.List[str],
    formatter: typing.Callable[
        [typing.Dict[str, typing.Any], typing.Iterable[str]], str
    ],
    metadata_json_column: typing.Optional[str] = None,
)

AlloyDBLoader constructor.

Parameters
Name Description
key object

Prevent direct constructor usage.

engine AlloyDBEngine

AsyncEngine with pool connection to the postgres database

query Optional[str], optional

SQL query. Defaults to None.

content_columns Optional[List[str]], optional

Column that represent a Document's page_content. Defaults to the first column.

metadata_columns Optional[List[str]], optional

Column(s) that represent a Document's metadata. Defaults to None.

formatter Optional[Callable], optional

A function to format page content (OneOf: format, formatter). Defaults to None.

metadata_json_column Optional[str], optional

Column to store metadata as JSON. Defaults to "langchain_metadata".

Exceptions
Type Description
Exception If called directly by user.

_collect_async_items

_collect_async_items(
    docs_generator: typing.AsyncIterator[langchain_core.documents.base.Document],
) -> typing.List[langchain_core.documents.base.Document]

Exhause document generator into a list.

alazy_load

alazy_load() -> typing.AsyncIterator[langchain_core.documents.base.Document]

Load AlloyDB data into Document objects lazily.

aload

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

Load AlloyDB data into Document objects.

create

create(
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    query: typing.Optional[str] = None,
    table_name: typing.Optional[str] = None,
    content_columns: typing.Optional[typing.List[str]] = None,
    metadata_columns: typing.Optional[typing.List[str]] = None,
    metadata_json_column: typing.Optional[str] = None,
    format: typing.Optional[str] = None,
    formatter: typing.Optional[typing.Callable] = None,
) -> langchain_google_alloydb_pg.loader.AlloyDBLoader

Create an AlloyDBLoader instance.

Parameters
Name Description
engine AlloyDBEngine

AsyncEngine with pool connection to the postgres database

query Optional[str], optional

SQL query. Defaults to None.

table_name Optional[str], optional

Name of table to query. Defaults to None.

content_columns Optional[List[str]], optional

Column that represent a Document's page_content. Defaults to the first column.

metadata_columns Optional[List[str]], optional

Column(s) that represent a Document's metadata. Defaults to None.

metadata_json_column Optional[str], optional

Column to store metadata as JSON. Defaults to "langchain_metadata".

format Optional[str], optional

Format of page content (OneOf: text, csv, YAML, JSON). Defaults to 'text'.

formatter Optional[Callable], optional

A function to format page content (OneOf: format, formatter). Defaults to None.

Exceptions
Type Description
Exception if called directly by user.

create_sync

create_sync(
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    query: typing.Optional[str] = None,
    table_name: typing.Optional[str] = None,
    content_columns: typing.Optional[typing.List[str]] = None,
    metadata_columns: typing.Optional[typing.List[str]] = None,
    metadata_json_column: typing.Optional[str] = None,
    format: typing.Optional[str] = None,
    formatter: typing.Optional[typing.Callable] = None,
) -> langchain_google_alloydb_pg.loader.AlloyDBLoader

Create an AlloyDBLoader instance.

Parameters
Name Description
engine AlloyDBEngine

AsyncEngine with pool connection to the postgres database

query Optional[str], optional

SQL query. Defaults to None.

table_name Optional[str], optional

Name of table to query. Defaults to None.

content_columns Optional[List[str]], optional

Column that represent a Document's page_content. Defaults to the first column.

metadata_columns Optional[List[str]], optional

Column(s) that represent a Document's metadata. Defaults to None.

metadata_json_column Optional[str], optional

Column to store metadata as JSON. Defaults to "langchain_metadata".

format Optional[str], optional

Format of page content (OneOf: text, csv, YAML, JSON). Defaults to 'text'.

formatter Optional[Callable], optional

A function to format page content (OneOf: format, formatter). Defaults to None.

lazy_load

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

Load AlloyDB data into Document objects lazily.

load

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

Load AlloyDB data into Document objects.