Skip to content

Commit

Permalink
Replace host, port, and database properties by url in VectorStore con…
Browse files Browse the repository at this point in the history
…figuration (#535)

* Replace host, port, and database properties by url

* Add invoke method
  • Loading branch information
franciscodr authored Nov 13, 2023
1 parent e498b5a commit ea1be66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.flywaydb.core.api.configuration.FluentConfiguration
import org.flywaydb.core.api.output.MigrateResult

class PsqlVectorStoreConfig(
val uri: String,
val url: String,
val driver: String,
val user: String,
val password: String,
Expand All @@ -18,7 +18,7 @@ class PsqlVectorStoreConfig(
withContext(Dispatchers.IO) {
val migration: FluentConfiguration = Flyway.configure()
.dataSource(
uri,
url,
user,
password
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,41 @@ import org.slf4j.Logger

@Serializable
class PSQLVectorStoreConfig(
val host: String,
val port: Int,
val database: String,
val url: String,
val driver: String,
val user: String,
val password: String,
val collectionName: String,
val vectorSize: Int
) : VectorStoreConfig {

fun getUrl(): String = "jdbc:postgresql://$host:$port/$database"

override suspend fun getVectorStoreService(logger: Logger): PostgresVectorStoreService {
val vectorStoreHikariDataSource =
RepositoryService.getHikariDataSource(getUrl(), user, password)
val vectorStoreHikariDataSource = RepositoryService.getHikariDataSource(url, user, password)
return PostgresVectorStoreService(toPGVectorStoreConfig(), logger, vectorStoreHikariDataSource)
}

private fun toPGVectorStoreConfig() =
PostgreSQLXef.PGVectorStoreConfig(
dbConfig =
PostgreSQLXef.DBConfig(
host = host,
port = port,
database = database,
user = user,
password = password
),
dbConfig = PostgreSQLXef.DBConfig(url = url, user = user, password = password),
collectionName = collectionName,
vectorSize = vectorSize
)

companion object {
operator fun invoke(
host: String,
port: Int,
database: String,
driver: String,
user: String,
password: String,
collectionName: String,
vectorSize: Int
): PSQLVectorStoreConfig {
val url = "jdbc:postgresql://${host}:${port}/${database}"
return PSQLVectorStoreConfig(url, driver, user, password, collectionName, vectorSize)
}

@OptIn(ExperimentalSerializationApi::class)
suspend fun load(configNamespace: String, config: Config?): PSQLVectorStoreConfig =
withContext(Dispatchers.IO) {
Expand All @@ -61,9 +63,7 @@ class PSQLVectorStoreConfig(

private fun PSQLVectorStoreConfig.toPSQLConfig(): PsqlVectorStoreConfig =
PsqlVectorStoreConfig(
host = this.host,
port = this.port,
database = this.database,
url = this.url,
driver = this.driver,
user = this.user,
password = this.password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ import kotlinx.uuid.generateUUID
import org.slf4j.Logger

object PostgreSQLXef {
data class DBConfig(
val host: String,
val port: Int,
val database: String,
val user: String,
val password: String
)
data class DBConfig(val url: String, val user: String, val password: String)

data class PGVectorStoreConfig(
val dbConfig: DBConfig,
Expand Down

0 comments on commit ea1be66

Please sign in to comment.