...
This commit is contained in:
@@ -62,14 +62,28 @@ object TradeLogTable : Table("trade_logs") {
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
class VectorColumnType(private val dimension: Int) : ColumnType<String>() {
|
||||
// [수정] H2에서 ARRAY는 내부 타입을 명시해야 합니다.
|
||||
// VECTOR 대신 FLOAT8 ARRAY를 사용하면 벡터 연산 함수와 100% 호환됩니다.
|
||||
class VectorColumnType(private val dimension: Int) : ColumnType<DoubleArray>() {
|
||||
override fun sqlType(): String = "FLOAT8 ARRAY"
|
||||
|
||||
override fun valueFromDB(value: Any): String = value.toString()
|
||||
override fun valueFromDB(value: Any): DoubleArray {
|
||||
return when (value) {
|
||||
// H2 드라이버에서 반환된 객체를 처리
|
||||
is java.sql.Array -> {
|
||||
val array = value.array as Array<*>
|
||||
array.map { (it as Number).toDouble() }.toDoubleArray()
|
||||
}
|
||||
is Array<*> -> value.map { (it as Number).toDouble() }.toDoubleArray()
|
||||
is DoubleArray -> value
|
||||
else -> DoubleArray(0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun notNullValueToDB(value: String): Any = value
|
||||
// [핵심 수정 부분]
|
||||
// primitive double[]을 Object Double[]로 변환하여 반환합니다.
|
||||
// 이렇게 해야 H2 JDBC 드라이버가 직렬화 대신 SQL ARRAY로 인식합니다.
|
||||
override fun notNullValueToDB(value: DoubleArray): Any {
|
||||
return value.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
object VectorStoreTable : Table("VECTOR_STORE") {
|
||||
@@ -77,8 +91,8 @@ object VectorStoreTable : Table("VECTOR_STORE") {
|
||||
val content = text("content")
|
||||
val metadata = text("metadata")
|
||||
|
||||
// 이제 FLOAT8 ARRAY 타입으로 컬럼이 생성됩니다.
|
||||
val embedding = registerColumn<String>("embedding", VectorColumnType(1024))
|
||||
// 이제 이 컬럼은 DoubleArray 데이터를 직접 주고받습니다.
|
||||
val embedding = registerColumn<DoubleArray>("embedding", VectorColumnType(1024))
|
||||
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user