Reference documentation and code samples for the Cloud Datastore 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.datastore.v1.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
getVectorProperty
Required. An indexed vector property 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 100.
Parameter
Name
Description
var
int|null
Returns
Type
Description
$this
getDistanceResultProperty
Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform toentity
propertylimitations.
Returns
Type
Description
string
setDistanceResultProperty
Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform toentity
propertylimitations.
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-04 UTC."],[],[],null,["# Cloud Datastore V1 Client - Class FindNearest (1.33.1)\n\nVersion latestkeyboard_arrow_down\n\n- [1.33.1 (latest)](/php/docs/reference/cloud-datastore/latest/V1.FindNearest)\n- [1.33.0](/php/docs/reference/cloud-datastore/1.33.0/V1.FindNearest)\n- [1.32.3](/php/docs/reference/cloud-datastore/1.32.3/V1.FindNearest)\n- [1.31.0](/php/docs/reference/cloud-datastore/1.31.0/V1.FindNearest)\n- [1.30.0](/php/docs/reference/cloud-datastore/1.30.0/V1.FindNearest)\n- [1.29.2](/php/docs/reference/cloud-datastore/1.29.2/V1.FindNearest)\n- [1.28.2](/php/docs/reference/cloud-datastore/1.28.2/V1.FindNearest)\n- [1.26.0](/php/docs/reference/cloud-datastore/1.26.0/V1.FindNearest)\n- [1.25.0](/php/docs/reference/cloud-datastore/1.25.0/V1.FindNearest)\n- [1.24.4](/php/docs/reference/cloud-datastore/1.24.4/V1.FindNearest)\n- [1.23.0](/php/docs/reference/cloud-datastore/1.23.0/V1.FindNearest)\n- [1.22.1](/php/docs/reference/cloud-datastore/1.22.1/V1.FindNearest)\n- [1.21.2](/php/docs/reference/cloud-datastore/1.21.2/V1.FindNearest)\n- [1.19.0](/php/docs/reference/cloud-datastore/1.19.0/V1.FindNearest)\n- [1.18.1](/php/docs/reference/cloud-datastore/1.18.1/V1.FindNearest)\n- [1.17.1](/php/docs/reference/cloud-datastore/1.17.1/V1.FindNearest) \nReference documentation and code samples for the Cloud Datastore 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 between\nqueries.\n\nGenerated from protobuf message `google.datastore.v1.FindNearest`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Datastore \\\\ V1\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getVectorProperty\n\nRequired. An indexed vector property to search upon. Only documents which\ncontain vectors whose dimensionality match the query_vector can be\nreturned.\n\n### hasVectorProperty\n\n### clearVectorProperty\n\n### setVectorProperty\n\nRequired. An indexed vector property 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 no\nmore 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 no\nmore 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 100.\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 100.\n\n### setLimit\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 100.\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 100.\n\n### getDistanceResultProperty\n\nOptional. Optional name of the field to output the result of the vector\ndistance calculation. Must conform to [entity\nproperty](/php/docs/reference/cloud-datastore/latest/V1.Entity#_Google_Cloud_Datastore_V1_Entity__getProperties__) limitations.\n\n### setDistanceResultProperty\n\nOptional. Optional name of the field to output the result of the vector\ndistance calculation. Must conform to [entity\nproperty](/php/docs/reference/cloud-datastore/latest/V1.Entity#_Google_Cloud_Datastore_V1_Entity__getProperties__) limitations.\n\n### getDistanceThreshold\n\nOptional. Option to specify a threshold for which no less similar documents\nwill be returned. The behavior of the specified `distance_measure` will\naffect the meaning of the distance threshold. Since DOT_PRODUCT distances\nincrease when the vectors are more similar, the comparison is inverted.\n\nFor EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\nFor 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 documents\nwill be returned. The behavior of the specified `distance_measure` will\naffect the meaning of the distance threshold. Since DOT_PRODUCT distances\nincrease when the vectors are more similar, the comparison is inverted.\nFor EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\nFor DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### setDistanceThreshold\n\nOptional. Option to specify a threshold for which no less similar documents\nwill be returned. The behavior of the specified `distance_measure` will\naffect the meaning of the distance threshold. Since DOT_PRODUCT distances\nincrease when the vectors are more similar, the comparison is inverted.\n\nFor EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\nFor 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 documents\nwill be returned. The behavior of the specified `distance_measure` will\naffect the meaning of the distance threshold. Since DOT_PRODUCT distances\nincrease when the vectors are more similar, the comparison is inverted.\nFor EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\nFor DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold"]]