Package io.agentscope.core.rag.store
Class PgVectorStore.Builder
java.lang.Object
io.agentscope.core.rag.store.PgVectorStore.Builder
- Enclosing class:
- PgVectorStore
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 Summary
Modifier and TypeMethodDescriptionbuild()Builds a new PgVectorStore instance.connectionTimeoutMs(long connectionTimeoutMs) Sets the connection timeout in milliseconds.dimensions(int dimensions) Sets the vector dimensions.distanceType(PgVectorStore.DistanceType distanceType) Sets the distance type for vector similarity search.Sets the PostgreSQL JDBC URL.Sets the database password.Sets the database schema.Sets the table name.Sets the database username.
-
Method Details
-
jdbcUrl
Sets the PostgreSQL JDBC URL.- Parameters:
jdbcUrl- the JDBC URL (e.g., "jdbc:postgresql://localhost:5432/mydb")- Returns:
- this builder
-
username
Sets the database username.- Parameters:
username- the username- Returns:
- this builder
-
password
Sets the database password.- Parameters:
password- the password- Returns:
- this builder
-
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
Sets the table name.- Parameters:
tableName- the name of the table to use- Returns:
- this builder
-
dimensions
Sets the vector dimensions.- Parameters:
dimensions- the dimension of vectors that will be stored- Returns:
- this builder
-
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
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
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 invalidVectorStoreException- if connection initialization or table creation fails
-