Skip to content

Commit 35ec27e

Browse files
committed
SCBC-461: Support for base64 encoded vector types
CBD-5903: SDK API 3.6 Release Preparation Supporting base64 vectors, and bumping vector search in general to Committed level. Change-Id: Id93f9e5b5329d171695318a48f4ca2639e48eec8 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/210964 Reviewed-by: Graham Pople <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 0488bf7 commit 35ec27e

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

scala-client/src/main/scala/com/couchbase/client/scala/search/vector/SearchRequest.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ case class SearchRequest private (
4141
* @return a copy of this, for chaining.
4242
*/
4343
@SinceCouchbase("7.6")
44-
@Uncommitted
4544
def vectorSearch(vectorSearch: VectorSearch): SearchRequest = {
4645
this.vectorSearch match {
4746
case Some(_) =>
@@ -100,7 +99,6 @@ object SearchRequest {
10099
new SearchRequest(Some(searchQuery), None)
101100

102101
/** Execute a [[VectorSearch]]. */
103-
@Uncommitted
104102
def vectorSearch(vectorSearch: VectorSearch): SearchRequest =
105103
new SearchRequest(None, Some(vectorSearch))
106104
}

scala-client/src/main/scala/com/couchbase/client/scala/search/vector/VectorQuery.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package com.couchbase.client.scala.search.vector
1818

19+
import com.couchbase.client.core.annotation.SinceCouchbase
1920
import com.couchbase.client.core.annotation.Stability.Uncommitted
2021
import com.couchbase.client.core.api.search.vector.{CoreVector, CoreVectorQuery}
2122

2223
/** Represents a vector query. */
23-
@Uncommitted
2424
case class VectorQuery private (
25-
private val vectorQuery: Array[Float],
25+
private val vectorQuery: Either[Array[Float], String],
2626
private val vectorField: String,
2727
private val numCandidates: Option[Int] = None,
28-
private val boost: Option[Double] = None
28+
private val boost: Option[Double] = None,
2929
) {
3030

3131
/** Can be used to control how much weight to give the results of this query vs other queries.
@@ -46,15 +46,24 @@ case class VectorQuery private (
4646

4747
private[scala] def toCore: CoreVectorQuery =
4848
new CoreVectorQuery(
49-
CoreVector.eitherOf(vectorQuery, null),
49+
vectorQuery match {
50+
case Left(floatArray) => CoreVector.of(floatArray)
51+
case Right(base64String) => CoreVector.of(base64String)
52+
},
5053
vectorField,
5154
numCandidates.map(Integer.valueOf).orNull,
5255
boost.map(java.lang.Double.valueOf).orNull
5356
)
5457
}
5558

56-
@Uncommitted
5759
object VectorQuery {
60+
/** Will perform a vector query using a vector provided as an array of floats. */
61+
@SinceCouchbase("7.6")
5862
def apply(vectorField: String, vectorQuery: Array[Float]): VectorQuery =
59-
new VectorQuery(vectorQuery, vectorField)
63+
new VectorQuery(Left(vectorQuery), vectorField)
64+
65+
/** Will perform a vector query using a vector provided as an array of floats. */
66+
@SinceCouchbase("7.6.2")
67+
def apply(vectorField: String, vectorQueryBase64: String): VectorQuery =
68+
new VectorQuery(Right(vectorQueryBase64), vectorField)
6069
}

scala-client/src/main/scala/com/couchbase/client/scala/search/vector/VectorSearch.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.couchbase.client.core.api.search.vector.CoreVectorSearch
2121
import scala.collection.JavaConverters._
2222

2323
/** Allows one or more [[VectorQuery]]s to be executed. */
24-
@Uncommitted
2524
case class VectorSearch private (
2625
private val vectorQueries: Iterable[VectorQuery],
2726
private val vectorSearchOptions: Option[VectorSearchOptions] = None
@@ -41,7 +40,6 @@ case class VectorSearch private (
4140
)
4241
}
4342

44-
@Uncommitted
4543
object VectorSearch {
4644

4745
/** Create a [[VectorSearch]] containing a single [[VectorQuery]]. */

scala-client/src/main/scala/com/couchbase/client/scala/search/vector/VectorSearchOptions.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616

1717
package com.couchbase.client.scala.search.vector
1818

19-
import com.couchbase.client.core.annotation.Stability.Uncommitted
20-
import com.couchbase.client.core.api.search.vector.{
21-
CoreVectorQueryCombination,
22-
CoreVectorSearchOptions
23-
}
19+
import com.couchbase.client.core.api.search.vector.{CoreVectorQueryCombination, CoreVectorSearchOptions}
2420

2521
/** Specifies how multiple [[VectorQuery]]s in a [[VectorSearch]] are combined. */
26-
@Uncommitted
2722
sealed trait VectorQueryCombination
2823
object VectorQueryCombination {
2924

@@ -35,7 +30,6 @@ object VectorQueryCombination {
3530
}
3631

3732
/** Options related to executing a [[VectorSearch]]. */
38-
@Uncommitted
3933
case class VectorSearchOptions private (
4034
private val vectorQueryCombination: Option[VectorQueryCombination] = None
4135
) {

0 commit comments

Comments
 (0)