findNearest method
Returns a query that can perform vector distance (similarity) search with given parameters.
The returned query, when executed, performs a distance (similarity) search on the specified
vectorField
against the given queryVector
and returns the top documents that are closest
to the queryVector
.
Only documents whose vectorField
field is a VectorValue
of the same dimension as queryVector
participate in the query, all other documents are ignored.
@example
// Returns the closest 10 documents whose Euclidean distance from their 'embedding' fields are closed to [41, 42].
const vectorQuery = col.findNearest('embedding', [41, 42], {limit: 10, distanceMeasure: 'EUCLIDEAN'});
const querySnapshot = await aggregateQuery.get();
querySnapshot.forEach(...);
@param vectorField The field path this vector query executes on.
@param queryVector The vector value used to measure the distance from vectorField
values in the documents.
@param options Options control the vector query. limit
specifies the upper bound of documents to return, must
be a positive integer with a maximum value of 1000. distanceMeasure
specifies what type of distance is
calculated when performing the query.
Implementation
external VectorQuery findNearest(
JSAny vectorField,
JSObject queryVector,
JSObject options,
);