-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(firestore): Adding distance threshold and result field #10802
Conversation
62ad34e
to
ab60ebc
Compare
I believe a distance threshold of 0 is the same as unset, since distances can never be negative. |
@jba It yields different results: If vectors are like below and the query vector is {3.0, 1.0, 2.0} docs := []CoffeeBean{
{
Name: "Kahawa coffee beans",
Description: "Information about the Kahawa coffee beans.",
EmbeddingField: []float32{1.0, 2.0, 3.0},
Color: "red",
},
{
Name: "Onyx coffee beans",
Description: "Information about the Onyx coffee beans.",
EmbeddingField: []float32{4.0, 5.0, 6.0},
Color: "brown",
},
{
Name: "SleepyOwl coffee beans",
Description: "Information about the Kahawa coffee beans.",
EmbeddingField: []float32{3.0, 1.0, 2.0},
Color: "red",
},
} then:
-- distance threshold unset returns:
|
OK, but I still think we should put them in the options struct. They are actually options for FindNearest, that is the right place for them. |
This is awesome! Thanks for sharing. |
Looks pretty good. We should not submit until this whole feature goes GA. |
}, | ||
{ | ||
desc: "FindNearest threshold and resultField", | ||
vq: collRef.FindNearest(queryField, []float64{1, 2, 3}, 3, DistanceMeasureEuclidean, &FindNearestOptions{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be an example for this in examples_test.go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we maintain examples_test.go. Don't the sample snippets in golang-samples repo serve the same purpose ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally there'd be one source of truth, but now they serve different purposes. The ones in example_test.go appear in pkgsite: https://pkg.go.dev/cloud.google.com/go/firestore#pkg-examples. The samples are linked from the GCP documentation.
9c4c7c3
to
0e47cc5
Compare
0e47cc5
to
aaf18bd
Compare
Removed do not merge label, since feature is now GA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
// DistanceResultField specifies name of the document field to output the result of | ||
// the vector distance calculation. | ||
// If the field already exists in the document, its value get overwritten with the distance calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/get/gets/
The proposed changes in current PR can be used like below:
Two new fields have been added to FindNearest proto:
google-cloud-go/firestore/apiv1/firestorepb/query.pb.go
Lines 1325 to 1337 in 9a5144e
'DistanceThreshold' is included in 'FindNearestOptions' as a pointer to a float64 (*float64) rather than a simple float64. This distinction allows us to differentiate between cases where the value is explicitly set and cases where it defaults to 0.
If vectors are like below and the query vector is {3.0, 1.0, 2.0}
then:
-- distance threshold 0 returns:
-- distance threshold unset returns: