-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qdrant support for vector knn search (#971)
* qdrant support for vector knn search * unbreak connector e2e tests * ci win fix
- Loading branch information
Showing
31 changed files
with
458 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Recommendations in Metarank | ||
|
||
Starting from version `0.6.x`, Metarank supports two types of recommendations: | ||
Starting from version `0.6.x`, Metarank supports three types of recommendations: | ||
* [Trending](recommendations/trending.md): popularity-sorted list of items with customized ordering. | ||
* [Similar items](recommendations/similar.md): matrix-factorization collaborative filtering recommender of items you may also like. | ||
* [Semantin](recommendations/semantic.md): a content-based semantic similarity recommender, based on neural embeddings. | ||
* [Semantic](recommendations/semantic.md): a content-based semantic similarity recommender, based on neural embeddings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ai.metaranke2e.knn | ||
|
||
import ai.metarank.ml.recommend.KnnConfig.QdrantConfig | ||
import ai.metarank.ml.recommend.embedding.{EmbeddingMap, KnnIndex} | ||
import ai.metarank.model.Identifier.ItemId | ||
import cats.effect.unsafe.implicits.global | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class QdrantTest extends AnyFlatSpec with Matchers { | ||
it should "write embeddings" in { | ||
val map = EmbeddingMap( | ||
ids = Array("1", "2", "3"), | ||
embeddings = Array( | ||
Array(1.0, 2.0, 3.0), | ||
Array(1.0, 2.0, 1.0), | ||
Array(1.0, 1.0, 0.0) | ||
), | ||
rows = 3, | ||
cols = 3 | ||
) | ||
val store = KnnIndex.write(map, QdrantConfig("http://localhost:6333", "test", 3, "Cosine")).unsafeRunSync() | ||
val response = store.lookup(List(ItemId("1")), 3).unsafeRunSync() | ||
response.map(_.item.value) shouldBe List("2", "3") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ai.metarank.ml.recommend | ||
|
||
import io.circe.{Decoder, DecodingFailure, Encoder, Json, JsonObject} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
|
||
sealed trait KnnConfig | ||
|
||
object KnnConfig { | ||
case class HnswConfig(m: Int = 32, ef: Int = 200) extends KnnConfig | ||
case class QdrantConfig(endpoint: String, collection: String, size: Int, distance: String) extends KnnConfig | ||
|
||
implicit val hnswDecoder: Decoder[HnswConfig] = Decoder.instance(c => | ||
for { | ||
m <- c.downField("m").as[Option[Int]] | ||
ef <- c.downField("ef").as[Option[Int]] | ||
} yield { | ||
HnswConfig(m.getOrElse(32), ef.getOrElse(200)) | ||
} | ||
) | ||
implicit val hnswEncoder: Encoder[HnswConfig] = deriveEncoder | ||
|
||
implicit val qdrantDecoder: Decoder[QdrantConfig] = deriveDecoder | ||
implicit val qdrantEncoder: Encoder[QdrantConfig] = deriveEncoder | ||
|
||
implicit val knnDecoder: Decoder[KnnConfig] = Decoder.instance(c => | ||
c.downField("type").as[String] match { | ||
case Left(value) => Left(value) | ||
case Right("hnsw") => hnswDecoder.tryDecode(c) | ||
case Right("qdrant") => qdrantDecoder.tryDecode(c) | ||
case Right(other) => Left(DecodingFailure(s"knn index type '$other' is not supported", c.history)) | ||
} | ||
) | ||
|
||
implicit val knnEncoder: Encoder[KnnConfig] = Encoder.instance { | ||
case c: HnswConfig => hnswEncoder(c).deepMerge(withType("hnsw")) | ||
case c: QdrantConfig => qdrantEncoder(c).deepMerge(withType("qdrant")) | ||
} | ||
|
||
def withType(tpe: String) = Json.fromJsonObject(JsonObject.fromIterable(List("type" -> Json.fromString(tpe)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.