Skip to content

Commit

Permalink
Auto stash before rebase of "feature/filtercriteria" onto "origin/dev"
Browse files Browse the repository at this point in the history
  • Loading branch information
net-cscience-raphael committed Dec 12, 2024
1 parent 0fb0adc commit ade752c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example-configs/schema/dense.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*
Expand All @@ -115,4 +128,5 @@ enum class Distance {
* @return [Double]
*/
abstract operator fun invoke(v1: Value.DoubleVector, v2: Value.DoubleVector): Double
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,8 @@ class DenseEmbedding : ExternalFesAnalyser<ContentElement<*>, 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
Expand Down Expand Up @@ -103,6 +106,7 @@ class DenseEmbedding : ExternalFesAnalyser<ContentElement<*>, 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. */
Expand All @@ -116,6 +120,6 @@ class DenseEmbedding : ExternalFesAnalyser<ContentElement<*>, 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)
}
}

0 comments on commit ade752c

Please sign in to comment.