Class PgVectorStore.Builder

java.lang.Object
io.agentscope.core.rag.store.PgVectorStore.Builder
Enclosing class:
PgVectorStore

public static class PgVectorStore.Builder extends Object
Builder for creating PgVectorStore instances with fluent configuration.

Example usage:


 PgVectorStore store = PgVectorStore.builder()
     .jdbcUrl("jdbc:postgresql://localhost:5432/mydb")
     .username("postgres")
     .password("password")
     .schema("my_schema")
     .tableName("embeddings")
     .dimensions(1024)
     .distanceType(PgVectorStore.DistanceType.COSINE)
     .connectionTimeoutMs(30000)
     .build();
 
  • Method Details

    • jdbcUrl

      public PgVectorStore.Builder jdbcUrl(String jdbcUrl)
      Sets the PostgreSQL JDBC URL.
      Parameters:
      jdbcUrl - the JDBC URL (e.g., "jdbc:postgresql://localhost:5432/mydb")
      Returns:
      this builder
    • username

      public PgVectorStore.Builder username(String username)
      Sets the database username.
      Parameters:
      username - the username
      Returns:
      this builder
    • password

      public PgVectorStore.Builder password(String password)
      Sets the database password.
      Parameters:
      password - the password
      Returns:
      this builder
    • schema

      public PgVectorStore.Builder schema(String schema)
      Sets the database schema.

      Default is "public". If the schema does not exist, it will be created automatically.

      Parameters:
      schema - the schema name (e.g., "my_schema")
      Returns:
      this builder
    • tableName

      public PgVectorStore.Builder tableName(String tableName)
      Sets the table name.
      Parameters:
      tableName - the name of the table to use
      Returns:
      this builder
    • dimensions

      public PgVectorStore.Builder dimensions(int dimensions)
      Sets the vector dimensions.
      Parameters:
      dimensions - the dimension of vectors that will be stored
      Returns:
      this builder
    • distanceType

      public PgVectorStore.Builder distanceType(PgVectorStore.DistanceType distanceType)
      Sets the distance type for vector similarity search.

      Default is COSINE. Other options include L2 (Euclidean) and INNER_PRODUCT.

      Parameters:
      distanceType - the distance type
      Returns:
      this builder
    • connectionTimeoutMs

      public PgVectorStore.Builder connectionTimeoutMs(long connectionTimeoutMs)
      Sets the connection timeout in milliseconds.

      Default is 30000 (30 seconds). Set to 0 or negative to disable timeout.

      Parameters:
      connectionTimeoutMs - the connection timeout in milliseconds
      Returns:
      this builder
    • build

      public PgVectorStore build() throws VectorStoreException
      Builds a new PgVectorStore instance.

      The database connection is established immediately during construction. If the connection fails or the table cannot be created, a VectorStoreException is thrown.

      Returns:
      a new PgVectorStore instance
      Throws:
      IllegalArgumentException - if required parameters are invalid
      VectorStoreException - if connection initialization or table creation fails