Skip to content

Commit

Permalink
feat(firestore): Resolving review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bhshkh committed Jul 22, 2024
1 parent 695b011 commit f93dcd4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions firestore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2851,18 +2851,17 @@ func TestIntegration_FindNearest(t *testing.T) {
t.Cleanup(func() {
cancel()
})

queryField := "EmbeddedField64"
indexNames := createVectorIndexes(adminCtx, t, wantDBPath, []vectorIndex{
{
fieldPath: "EmbeddedField",
fieldPath: queryField,
dimension: 3,
},
})
t.Cleanup(func() {
deleteIndexes(adminCtx, indexNames)
})

queryField := "EmbeddedField64"
type coffeeBean struct {
ID string
EmbeddedField64 Vector64
Expand Down
14 changes: 8 additions & 6 deletions firestore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

Expand All @@ -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 {
Expand All @@ -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,
}
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion firestore/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion firestore/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Check failure on line 32 in firestore/vector.go

View workflow job for this annotation

GitHub Actions / vet

comment on exported type Vector32 should be of the form "Vector32 ..." (with optional leading article)
type Vector32 []float32

// vectorToProtoValue returns a Firestore [pb.Value] representing the Vector.
Expand Down

0 comments on commit f93dcd4

Please sign in to comment.