Class PostgresLoader.Builder

java.lang.Object
dev.langchain4j.community.data.document.loader.cloudsql.PostgresLoader.Builder
Enclosing class:
PostgresLoader

public static class PostgresLoader.Builder extends Object
Builder for PostgresLoader.
  • Constructor Details

    • Builder

      public Builder(PostgresEngine engine)
      Construct a LoaderBuilder.
      Parameters:
      engine - The PostgresEngine.
  • Method Details

    • schemaName

      public PostgresLoader.Builder schemaName(String schemaName)
      Sets the schema name for the table. Defaults to "public".
      Parameters:
      schemaName - The schema name.
      Returns:
      This Builder.
    • query

      public PostgresLoader.Builder query(String query)
      Sets the SQL query to execute. If not provided, a default query is generated from the table name.
      Parameters:
      query - The SQL query.
      Returns:
      This Builder.
    • tableName

      public PostgresLoader.Builder tableName(String tableName)
      Sets the table name to load data from. If not provided, a custom query must be specified.
      Parameters:
      tableName - The table name.
      Returns:
      This Builder.
    • formatter

      Sets a custom formatter to convert row data into document content.
      Parameters:
      formatter - The formatter function.
      Returns:
      This Builder.
    • format

      public PostgresLoader.Builder format(String format)
      Sets the format for the document content. Predefined formats are "csv", "text", "JSON", and "YAML". Only one of format or formatter should be specified.
      Parameters:
      format - The format string.
      Returns:
      This Builder.
    • contentColumns

      public PostgresLoader.Builder contentColumns(List<String> contentColumns)
      Sets the list of columns to use for the document content.
      Parameters:
      contentColumns - The content column names.
      Returns:
      This Builder.
    • metadataColumns

      public PostgresLoader.Builder metadataColumns(List<String> metadataColumns)
      Sets the list of columns to use for the document metadata.
      Parameters:
      metadataColumns - The metadata column names.
      Returns:
      This Builder.
    • metadataJsonColumn

      public PostgresLoader.Builder metadataJsonColumn(String metadataJsonColumn)
      Sets the column name containing JSON metadata.
      Parameters:
      metadataJsonColumn - The JSON metadata column name.
      Returns:
      This Builder.
    • build

      public PostgresLoader build() throws SQLException
      Builds an PostgresLoader with the configuration applied to this builder.
      Returns:
      The built PostgresLoader instance.
      Throws:
      IllegalArgumentException - if neither query nor tableName is specified, or if both format and formatter are specified, or if specified column not found.
      SQLException - if a database error occurs.