Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace host, port, and database properties by url in VectorStore configuration #535

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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