diff --git a/example-configs/schema/dense.json b/example-configs/schema/dense.json index 99705ee5..b88f154d 100644 --- a/example-configs/schema/dense.json +++ b/example-configs/schema/dense.json @@ -48,7 +48,7 @@ "clip": { "factory": "DenseEmbedding", "parameters": { - "host": "http://10.34.64.84:8888/", + "host": "http://10.34.64.83:8888/", "model": "open-clip-vit-b32", "length": "512", "timeoutSeconds": "100", diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/query/basics/Distance.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/query/basics/Distance.kt index 4bd0737c..59379f45 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/query/basics/Distance.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/query/basics/Distance.kt @@ -98,6 +98,19 @@ enum class Distance { override fun invoke(v1: Value.DoubleVector, v2: Value.DoubleVector): Double = throw UnsupportedOperationException("Jaccard distance is not supported for float vectors.") }; + companion object { + infix fun fromString(value: String): Distance { + return when (value) { + "manhattan" -> MANHATTAN + "euclidean" -> EUCLIDEAN + "cosine" -> COSINE + "hamming" -> HAMMING + "jaccard" -> JACCARD + else -> throw IllegalArgumentException("Distance function $value is not supported.") + } + } + } + /** * Calculates this [Distance] between two [Value.FloatVector]. * @@ -115,4 +128,5 @@ enum class Distance { * @return [Double] */ abstract operator fun invoke(v1: Value.DoubleVector, v2: Value.DoubleVector): Double -} \ No newline at end of file +} + diff --git a/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/dense/DenseEmbedding.kt b/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/dense/DenseEmbedding.kt index bd6b971c..1fae947d 100644 --- a/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/dense/DenseEmbedding.kt +++ b/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/dense/DenseEmbedding.kt @@ -18,6 +18,7 @@ import org.vitrivr.engine.core.model.descriptor.vector.FloatVectorDescriptor import org.vitrivr.engine.core.model.metamodel.Analyser.Companion.merge import org.vitrivr.engine.core.model.metamodel.Schema import org.vitrivr.engine.core.model.query.Query +import org.vitrivr.engine.core.model.query.basics.Distance import org.vitrivr.engine.core.model.query.proximity.ProximityQuery import org.vitrivr.engine.core.model.retrievable.Retrievable import org.vitrivr.engine.core.model.types.Value @@ -36,6 +37,8 @@ class DenseEmbedding : ExternalFesAnalyser, FloatVectorDescrip companion object { const val LENGTH_PARAMETER_DEFAULT = 512 const val LENGTH_PARAMETER_NAME = "length" + const val DISTANCE_PARAMETER_DEFAULT = "euclidean" + const val DISTANCE_PARAMETER_NAME = "distance" } override val contentClasses = setOf(ImageContent::class, TextContent::class) override val descriptorClass = FloatVectorDescriptor::class @@ -103,6 +106,7 @@ class DenseEmbedding : ExternalFesAnalyser, FloatVectorDescrip val retries = field.parameters[RETRIES_PARAMETER_NAME]?.toIntOrNull() ?: RETRIES_PARAMETER_DEFAULT val model = field.parameters[MODEL_PARAMETER_NAME] ?: throw IllegalStateException("Model parameter not set.") val k = context.getProperty(field.fieldName, "limit")?.toLongOrNull() ?: 1000L + val distance = Distance fromString (field.parameters[DISTANCE_PARAMETER_NAME] ?: DISTANCE_PARAMETER_DEFAULT) val fetchVector = context.getProperty(field.fieldName, "returnDescriptor")?.toBooleanStrictOrNull() ?: false /* Generate vector for content element. */ @@ -116,6 +120,6 @@ class DenseEmbedding : ExternalFesAnalyser, FloatVectorDescrip } /* Return retriever. */ - return this.newRetrieverForQuery(field, ProximityQuery(value = vector, k = k, fetchVector = fetchVector), context) + return this.newRetrieverForQuery(field, ProximityQuery(value = vector, distance = distance, k = k, fetchVector = fetchVector), context) } } \ No newline at end of file