Skip to content

Commit 5e2ca44

Browse files
Google APIscopybara-github
authored andcommitted
feat: add VectorSearch API
PiperOrigin-RevId: 617982192
1 parent 463998e commit 5e2ca44

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

google/firestore/v1/query.proto

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,51 @@ message StructuredQuery {
263263
repeated FieldReference fields = 2;
264264
}
265265

266+
// Nearest Neighbors search config.
267+
message FindNearest {
268+
// The distance measure to use when comparing vectors.
269+
enum DistanceMeasure {
270+
// Should not be set.
271+
DISTANCE_MEASURE_UNSPECIFIED = 0;
272+
273+
// Measures the EUCLIDEAN distance between the vectors. See
274+
// [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn
275+
// more
276+
EUCLIDEAN = 1;
277+
278+
// Compares vectors based on the angle between them, which allows you to
279+
// measure similarity that isn't based on the vectors magnitude.
280+
// We recommend using DOT_PRODUCT with unit normalized vectors instead of
281+
// COSINE distance, which is mathematically equivalent with better
282+
// performance. See [Cosine
283+
// Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn
284+
// more.
285+
COSINE = 2;
286+
287+
// Similar to cosine but is affected by the magnitude of the vectors. See
288+
// [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more.
289+
DOT_PRODUCT = 3;
290+
}
291+
292+
// Required. An indexed vector field to search upon. Only documents which
293+
// contain vectors whose dimensionality match the query_vector can be
294+
// returned.
295+
FieldReference vector_field = 1 [(google.api.field_behavior) = REQUIRED];
296+
297+
// Required. The query vector that we are searching on. Must be a vector of
298+
// no more than 2048 dimensions.
299+
Value query_vector = 2 [(google.api.field_behavior) = REQUIRED];
300+
301+
// Required. The Distance Measure to use, required.
302+
DistanceMeasure distance_measure = 3
303+
[(google.api.field_behavior) = REQUIRED];
304+
305+
// Required. The number of nearest neighbors to return. Must be a positive
306+
// integer of no more than 1000.
307+
google.protobuf.Int32Value limit = 4
308+
[(google.api.field_behavior) = REQUIRED];
309+
}
310+
266311
// Optional sub-set of the fields to return.
267312
//
268313
// This acts as a [DocumentMask][google.firestore.v1.DocumentMask] over the
@@ -360,6 +405,13 @@ message StructuredQuery {
360405
//
361406
// * The value must be greater than or equal to zero if specified.
362407
google.protobuf.Int32Value limit = 5;
408+
409+
// Optional. A potential Nearest Neighbors Search.
410+
//
411+
// Applies after all other filters and ordering.
412+
//
413+
// Finds the closest vector embeddings to the given query vector.
414+
FindNearest find_nearest = 9 [(google.api.field_behavior) = OPTIONAL];
363415
}
364416

365417
// Firestore query for running an aggregation over a

0 commit comments

Comments
 (0)