diff --git a/firestore/integration_test.go b/firestore/integration_test.go index a1101a166593..dfc19692c545 100644 --- a/firestore/integration_test.go +++ b/firestore/integration_test.go @@ -2851,10 +2851,10 @@ func TestIntegration_FindNearest(t *testing.T) { t.Cleanup(func() { cancel() }) - + queryField := "EmbeddedField64" indexNames := createVectorIndexes(adminCtx, t, wantDBPath, []vectorIndex{ { - fieldPath: "EmbeddedField", + fieldPath: queryField, dimension: 3, }, }) @@ -2862,7 +2862,6 @@ func TestIntegration_FindNearest(t *testing.T) { deleteIndexes(adminCtx, indexNames) }) - queryField := "EmbeddedField64" type coffeeBean struct { ID string EmbeddedField64 Vector64 diff --git a/firestore/query.go b/firestore/query.go index a843e57fef19..e46de704943e 100644 --- a/firestore/query.go +++ b/firestore/query.go @@ -392,7 +392,7 @@ const ( DistanceMeasureDotProduct DistanceMeasure = DistanceMeasure(pb.StructuredQuery_FindNearest_DOT_PRODUCT) ) -// FindNearestOptions is options to use while building FindNearest vector query +// FindNearestOptions are options for a FindNearest vector query. type FindNearestOptions struct { } @@ -412,7 +412,7 @@ type VectorQuery struct { // // The vectorField argument can be a single field or a dot-separated sequence of // fields, and must not contain any of the runes "˜*/[]". -func (q Query) FindNearest(vectorField string, queryVector interface{}, limit int, measure DistanceMeasure, options *FindNearestOptions) VectorQuery { +func (q Query) FindNearest(vectorField string, queryVector any, limit int, measure DistanceMeasure, options *FindNearestOptions) VectorQuery { // Validate field path fieldPath, err := parseDotSeparatedString(vectorField) if err != nil { @@ -430,7 +430,7 @@ func (vq VectorQuery) Documents(ctx context.Context) *DocumentIterator { } // FindNearestPath is similar to FindNearest but it accepts a [FieldPath]. -func (q Query) FindNearestPath(vectorFieldPath FieldPath, queryVector interface{}, limit int, measure DistanceMeasure, options *FindNearestOptions) VectorQuery { +func (q Query) FindNearestPath(vectorFieldPath FieldPath, queryVector any, limit int, measure DistanceMeasure, options *FindNearestOptions) VectorQuery { vq := VectorQuery{ q: q, } @@ -446,13 +446,15 @@ func (q Query) FindNearestPath(vectorFieldPath FieldPath, queryVector interface{ switch v := queryVector.(type) { case Vector32: fnvq = vectorToProtoValue([]float32(v)) + case []float32: + fnvq = vectorToProtoValue([]float32(v)) case Vector64: fnvq = vectorToProtoValue([]float64(v)) + case []float64: + fnvq = vectorToProtoValue([]float64(v)) default: vq.q.err = errors.New("firestore: queryVector must be Vector32 or Vector64") - return VectorQuery{ - q: q, - } + return vq } vq.q.findNearest = &pb.StructuredQuery_FindNearest{ diff --git a/firestore/query_test.go b/firestore/query_test.go index 63e6d568dfdc..106a1bbe15bd 100644 --- a/firestore/query_test.go +++ b/firestore/query_test.go @@ -1475,7 +1475,7 @@ func TestFindNearest(t *testing.T) { desc: "Invalid vector type", path: "path", queryVector: "abcd", - wantErr: false, + wantErr: true, }, { desc: "Valid vector type", diff --git a/firestore/vector.go b/firestore/vector.go index 2514acffbc03..4eaa60c35b40 100644 --- a/firestore/vector.go +++ b/firestore/vector.go @@ -26,8 +26,10 @@ const ( valueKey = "value" ) -// Vector64 is an embedding vector. +// Vector64 is an embedding vector of float64s. type Vector64 []float64 + +// Vector64 is an embedding vector of float32s. type Vector32 []float32 // vectorToProtoValue returns a Firestore [pb.Value] representing the Vector.