Reference documentation and code samples for the Cloud Firestore V1 Client class FindNearest.
Nearest Neighbors search config. The ordering provided by FindNearest
supersedes the order_by stage. If multiple documents have the same vector
distance, the returned document order is not guaranteed to be stable
between queries.
Generated from protobuf messagegoogle.firestore.v1.StructuredQuery.FindNearest
Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specifieddistance_measurewill affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted. * * For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold * * For DOT_PRODUCT: WHERE distance >= distance_threshold
getVectorField
Required. An indexed vector field to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.
Sets the field by wrapping a primitive type in a Google\Protobuf\Int32Value object.
Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 1000.
Parameter
Name
Description
var
int|null
Returns
Type
Description
$this
getDistanceResultField
Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform todocument field
namelimitations.
Returns
Type
Description
string
setDistanceResultField
Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform todocument field
namelimitations.
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getDistanceThreshold
Optional. Option to specify a threshold for which no less similar
documents will be returned. The behavior of the specifieddistance_measurewill affect the meaning of the distance threshold.
Since DOT_PRODUCT distances increase when the vectors are more similar,
the comparison is inverted.
For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold
For DOT_PRODUCT: WHERE distance >= distance_threshold
Returns the unboxed value fromgetDistanceThreshold()
Optional. Option to specify a threshold for which no less similar
documents will be returned. The behavior of the specifieddistance_measurewill affect the meaning of the distance threshold.
Since DOT_PRODUCT distances increase when the vectors are more similar,
the comparison is inverted.
For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold
For DOT_PRODUCT: WHERE distance >= distance_threshold
Returns
Type
Description
float|null
setDistanceThreshold
Optional. Option to specify a threshold for which no less similar
documents will be returned. The behavior of the specifieddistance_measurewill affect the meaning of the distance threshold.
Since DOT_PRODUCT distances increase when the vectors are more similar,
the comparison is inverted.
For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold
For DOT_PRODUCT: WHERE distance >= distance_threshold
Sets the field by wrapping a primitive type in a Google\Protobuf\DoubleValue object.
Optional. Option to specify a threshold for which no less similar
documents will be returned. The behavior of the specifieddistance_measurewill affect the meaning of the distance threshold.
Since DOT_PRODUCT distances increase when the vectors are more similar,
the comparison is inverted.
For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold
For DOT_PRODUCT: WHERE distance >= distance_threshold
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Firestore V1 Client - Class FindNearest (1.53.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.53.0 (latest)](/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FindNearest)\n- [1.52.0](/php/docs/reference/cloud-firestore/1.52.0/V1.StructuredQuery.FindNearest)\n- [1.51.0](/php/docs/reference/cloud-firestore/1.51.0/V1.StructuredQuery.FindNearest)\n- [1.50.0](/php/docs/reference/cloud-firestore/1.50.0/V1.StructuredQuery.FindNearest)\n- [1.48.1](/php/docs/reference/cloud-firestore/1.48.1/V1.StructuredQuery.FindNearest)\n- [1.47.3](/php/docs/reference/cloud-firestore/1.47.3/V1.StructuredQuery.FindNearest)\n- [1.46.0](/php/docs/reference/cloud-firestore/1.46.0/V1.StructuredQuery.FindNearest)\n- [1.45.2](/php/docs/reference/cloud-firestore/1.45.2/V1.StructuredQuery.FindNearest)\n- [1.44.1](/php/docs/reference/cloud-firestore/1.44.1/V1.StructuredQuery.FindNearest)\n- [1.43.3](/php/docs/reference/cloud-firestore/1.43.3/V1.StructuredQuery.FindNearest)\n- [1.40.0](/php/docs/reference/cloud-firestore/1.40.0/V1.StructuredQuery.FindNearest)\n- [1.39.0](/php/docs/reference/cloud-firestore/1.39.0/V1.StructuredQuery.FindNearest)\n- [1.38.0](/php/docs/reference/cloud-firestore/1.38.0/V1.StructuredQuery.FindNearest)\n- [1.37.7](/php/docs/reference/cloud-firestore/1.37.7/V1.StructuredQuery.FindNearest)\n- [1.36.1](/php/docs/reference/cloud-firestore/1.36.1/V1.StructuredQuery.FindNearest)\n- [1.35.0](/php/docs/reference/cloud-firestore/1.35.0/V1.StructuredQuery.FindNearest)\n- [1.34.0](/php/docs/reference/cloud-firestore/1.34.0/V1.StructuredQuery.FindNearest)\n- [1.33.0](/php/docs/reference/cloud-firestore/1.33.0/V1.StructuredQuery.FindNearest)\n- [1.32.0](/php/docs/reference/cloud-firestore/1.32.0/V1.StructuredQuery.FindNearest)\n- [1.31.0](/php/docs/reference/cloud-firestore/1.31.0/V1.StructuredQuery.FindNearest)\n- [1.30.0](/php/docs/reference/cloud-firestore/1.30.0/V1.StructuredQuery.FindNearest)\n- [1.28.0](/php/docs/reference/cloud-firestore/1.28.0/V1.StructuredQuery.FindNearest)\n- [1.27.3](/php/docs/reference/cloud-firestore/1.27.3/V1.StructuredQuery.FindNearest) \nReference documentation and code samples for the Cloud Firestore V1 Client class FindNearest.\n\nNearest Neighbors search config. The ordering provided by FindNearest\nsupersedes the order_by stage. If multiple documents have the same vector\ndistance, the returned document order is not guaranteed to be stable\nbetween queries.\n\nGenerated from protobuf message `google.firestore.v1.StructuredQuery.FindNearest`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Firestore \\\\ V1 \\\\ StructuredQuery\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getVectorField\n\nRequired. An indexed vector field to search upon. Only documents which\ncontain vectors whose dimensionality match the query_vector can be\nreturned.\n\n### hasVectorField\n\n### clearVectorField\n\n### setVectorField\n\nRequired. An indexed vector field to search upon. Only documents which\ncontain vectors whose dimensionality match the query_vector can be\nreturned.\n\n### getQueryVector\n\nRequired. The query vector that we are searching on. Must be a vector of\nno more than 2048 dimensions.\n\n### hasQueryVector\n\n### clearQueryVector\n\n### setQueryVector\n\nRequired. The query vector that we are searching on. Must be a vector of\nno more than 2048 dimensions.\n\n### getDistanceMeasure\n\nRequired. The distance measure to use, required.\n\n### setDistanceMeasure\n\nRequired. The distance measure to use, required.\n\n### getLimit\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 1000.\n\n### hasLimit\n\n### clearLimit\n\n### getLimitValue\n\nReturns the unboxed value from `getLimit()`\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 1000.\n\n### setLimit\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 1000.\n\n### setLimitValue\n\nSets the field by wrapping a primitive type in a Google\\\\Protobuf\\\\Int32Value object.\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 1000.\n\n### getDistanceResultField\n\nOptional. Optional name of the field to output the result of the vector\ndistance calculation. Must conform to [document field\nname](/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.\n\n### setDistanceResultField\n\nOptional. Optional name of the field to output the result of the vector\ndistance calculation. Must conform to [document field\nname](/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.\n\n### getDistanceThreshold\n\nOptional. Option to specify a threshold for which no less similar\ndocuments will be returned. The behavior of the specified\n`distance_measure` will affect the meaning of the distance threshold.\n\nSince DOT_PRODUCT distances increase when the vectors are more similar,\nthe comparison is inverted.\n\n- For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n- For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### hasDistanceThreshold\n\n### clearDistanceThreshold\n\n### getDistanceThresholdValue\n\nReturns the unboxed value from `getDistanceThreshold()`\n\nOptional. Option to specify a threshold for which no less similar\ndocuments will be returned. The behavior of the specified\n`distance_measure` will affect the meaning of the distance threshold.\nSince DOT_PRODUCT distances increase when the vectors are more similar,\nthe comparison is inverted.\n\n- For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n- For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### setDistanceThreshold\n\nOptional. Option to specify a threshold for which no less similar\ndocuments will be returned. The behavior of the specified\n`distance_measure` will affect the meaning of the distance threshold.\n\nSince DOT_PRODUCT distances increase when the vectors are more similar,\nthe comparison is inverted.\n\n- For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n- For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### setDistanceThresholdValue\n\nSets the field by wrapping a primitive type in a Google\\\\Protobuf\\\\DoubleValue object.\n\nOptional. Option to specify a threshold for which no less similar\ndocuments will be returned. The behavior of the specified\n`distance_measure` will affect the meaning of the distance threshold.\nSince DOT_PRODUCT distances increase when the vectors are more similar,\nthe comparison is inverted.\n\n- For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n- For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold"]]