Skip to content

Commit

Permalink
Match on case object name values instead of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed Jul 17, 2024
1 parent 4635dbb commit d9b5145
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory}

object DenseVectorFieldBuilderFn {
private def similarityFromString(similarity: String): Similarity = similarity match {
case "l2_norm" => L2Norm
case "dot_product" => DotProduct
case "cosine" => Cosine
case "max_inner_product" => MaxInnerProduct
case L2Norm.name => L2Norm
case DotProduct.name => DotProduct
case Cosine.name => Cosine
case MaxInnerProduct.name => MaxInnerProduct
}

private def getIndexOptions(values: Map[String, Any]): DenseVectorIndexOptions =
values("type").asInstanceOf[String] match {
case "hnsw" => DenseVectorIndexOptions(
case DenseVectorField.Hnsw.name => DenseVectorIndexOptions(
DenseVectorField.Hnsw,
values.get("m").map(_.asInstanceOf[Int]),
values.get("ef_construction").map(_.asInstanceOf[Int])
)
case "int8_hnsw" => DenseVectorIndexOptions(
case DenseVectorField.Int8Hnsw.name => DenseVectorIndexOptions(
DenseVectorField.Int8Hnsw,
values.get("m").map(_.asInstanceOf[Int]),
values.get("ef_construction").map(_.asInstanceOf[Int]),
values.get("confidence_interval").map(d => d.asInstanceOf[Double].toFloat)
)
case "int4_hnsw" => DenseVectorIndexOptions(
case DenseVectorField.Int4Hnsw.name => DenseVectorIndexOptions(
DenseVectorField.Int4Hnsw,
values.get("m").map(_.asInstanceOf[Int]),
values.get("ef_construction").map(_.asInstanceOf[Int]),
Expand All @@ -34,13 +34,13 @@ object DenseVectorFieldBuilderFn {
case DenseVectorField.Flat.name => DenseVectorIndexOptions(
DenseVectorField.Flat
)
case "int8_flat" => DenseVectorIndexOptions(
case DenseVectorField.Int8Flat.name => DenseVectorIndexOptions(
DenseVectorField.Int8Flat,
None,
None,
values.get("confidence_interval").map(d => d.asInstanceOf[Double].toFloat)
)
case "int4_flat" => DenseVectorIndexOptions(
case DenseVectorField.Int4Flat.name => DenseVectorIndexOptions(
DenseVectorField.Int4Flat,
None,
None,
Expand Down

0 comments on commit d9b5145

Please sign in to comment.