Class PostgresLoader (0.4.0)

PostgresLoader(
    key,
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    query: str,
    content_columns: typing.List[str],
    metadata_columns: typing.List[str],
    formatter: typing.Callable,
    metadata_json_column: typing.Optional[str] = None,
)

Load documents from PostgreSQL`.

Each document represents one row of the result. The content_columns are written into the content_columnsof 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

alazy_load

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

Load PostgreSQL data into Document objects lazily.

aload

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

Load PostgreSQL data into Document objects.

create

create(
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    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,
)

Constructor for PostgresLoader

Parameters
Name Description
engine PostgresEngine

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 PostgreSQL data into Document objects lazily.

load

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

Load PostgreSQL data into Document objects.