Reference documentation and code samples for the Firestore in Datastore mode V1 API class Google::Cloud::Datastore::V1::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.
(::String) — Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform to [entity
property][google.datastore.v1.Entity.properties] limitations.
#distance_result_property=
defdistance_result_property=(value)->::String
Parameter
value (::String) — Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform to [entity
property][google.datastore.v1.Entity.properties] limitations.
Returns
(::String) — Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform to [entity
property][google.datastore.v1.Entity.properties] limitations.
(::Google::Protobuf::DoubleValue) — Optional. Option to specify a threshold for which no less similar documents
will be returned. The behavior of the specified distance_measure will
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
value (::Google::Protobuf::DoubleValue) — Optional. Option to specify a threshold for which no less similar documents
will be returned. The behavior of the specified distance_measure will
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
(::Google::Protobuf::DoubleValue) — Optional. Option to specify a threshold for which no less similar documents
will be returned. The behavior of the specified distance_measure will
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
#limit
deflimit()->::Google::Protobuf::Int32Value
Returns
(::Google::Protobuf::Int32Value) — Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 100.
#limit=
deflimit=(value)->::Google::Protobuf::Int32Value
Parameter
value (::Google::Protobuf::Int32Value) — Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 100.
Returns
(::Google::Protobuf::Int32Value) — Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 100.
(::Google::Cloud::Datastore::V1::PropertyReference) — Required. An indexed vector property to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.
value (::Google::Cloud::Datastore::V1::PropertyReference) — Required. An indexed vector property to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.
Returns
(::Google::Cloud::Datastore::V1::PropertyReference) — Required. An indexed vector property to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.
[[["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,["# Firestore in Datastore mode V1 API - Class Google::Cloud::Datastore::V1::FindNearest (v1.4.1)\n\nVersion latestkeyboard_arrow_down\n\n- [1.4.1 (latest)](/ruby/docs/reference/google-cloud-datastore-v1/latest/Google-Cloud-Datastore-V1-FindNearest)\n- [1.4.0](/ruby/docs/reference/google-cloud-datastore-v1/1.4.0/Google-Cloud-Datastore-V1-FindNearest)\n- [1.3.1](/ruby/docs/reference/google-cloud-datastore-v1/1.3.1/Google-Cloud-Datastore-V1-FindNearest)\n- [1.2.0](/ruby/docs/reference/google-cloud-datastore-v1/1.2.0/Google-Cloud-Datastore-V1-FindNearest)\n- [1.1.0](/ruby/docs/reference/google-cloud-datastore-v1/1.1.0/Google-Cloud-Datastore-V1-FindNearest)\n- [1.0.1](/ruby/docs/reference/google-cloud-datastore-v1/1.0.1/Google-Cloud-Datastore-V1-FindNearest)\n- [0.19.0](/ruby/docs/reference/google-cloud-datastore-v1/0.19.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.18.0](/ruby/docs/reference/google-cloud-datastore-v1/0.18.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.17.0](/ruby/docs/reference/google-cloud-datastore-v1/0.17.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.16.3](/ruby/docs/reference/google-cloud-datastore-v1/0.16.3/Google-Cloud-Datastore-V1-FindNearest)\n- [0.15.0](/ruby/docs/reference/google-cloud-datastore-v1/0.15.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.14.0](/ruby/docs/reference/google-cloud-datastore-v1/0.14.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.13.1](/ruby/docs/reference/google-cloud-datastore-v1/0.13.1/Google-Cloud-Datastore-V1-FindNearest)\n- [0.12.0](/ruby/docs/reference/google-cloud-datastore-v1/0.12.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.11.1](/ruby/docs/reference/google-cloud-datastore-v1/0.11.1/Google-Cloud-Datastore-V1-FindNearest)\n- [0.10.0](/ruby/docs/reference/google-cloud-datastore-v1/0.10.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.9.0](/ruby/docs/reference/google-cloud-datastore-v1/0.9.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.8.0](/ruby/docs/reference/google-cloud-datastore-v1/0.8.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.7.0](/ruby/docs/reference/google-cloud-datastore-v1/0.7.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.6.0](/ruby/docs/reference/google-cloud-datastore-v1/0.6.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.5.0](/ruby/docs/reference/google-cloud-datastore-v1/0.5.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.4.0](/ruby/docs/reference/google-cloud-datastore-v1/0.4.0/Google-Cloud-Datastore-V1-FindNearest)\n- [0.3.5](/ruby/docs/reference/google-cloud-datastore-v1/0.3.5/Google-Cloud-Datastore-V1-FindNearest) \nReference documentation and code samples for the Firestore in Datastore mode V1 API class Google::Cloud::Datastore::V1::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\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- Google::Protobuf::MessageExts::ClassMethods \n\nIncludes\n--------\n\n- Google::Protobuf::MessageExts\n\nMethods\n-------\n\n### #distance_measure\n\n def distance_measure() -\u003e ::Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure\n\n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure](./Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)) --- Required. The Distance Measure to use, required.\n\n### #distance_measure=\n\n def distance_measure=(value) -\u003e ::Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure\n\n**Parameter**\n\n- **value** ([::Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure](./Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)) --- Required. The Distance Measure to use, required. \n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure](./Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)) --- Required. The Distance Measure to use, required.\n\n### #distance_result_property\n\n def distance_result_property() -\u003e ::String\n\n**Returns**\n\n- (::String) --- Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to \\[entity property\\]\\[google.datastore.v1.Entity.properties\\] limitations.\n\n### #distance_result_property=\n\n def distance_result_property=(value) -\u003e ::String\n\n**Parameter**\n\n- **value** (::String) --- Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to \\[entity property\\]\\[google.datastore.v1.Entity.properties\\] limitations. \n**Returns**\n\n- (::String) --- Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to \\[entity property\\]\\[google.datastore.v1.Entity.properties\\] limitations.\n\n### #distance_threshold\n\n def distance_threshold() -\u003e ::Google::Protobuf::DoubleValue\n\n**Returns**\n\n- ([::Google::Protobuf::DoubleValue](./Google-Protobuf-DoubleValue)) --- Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specified `distance_measure` will affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted.\n\n\n For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### #distance_threshold=\n\n def distance_threshold=(value) -\u003e ::Google::Protobuf::DoubleValue\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::DoubleValue](./Google-Protobuf-DoubleValue)) --- Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specified `distance_measure` will affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted.\n\n\n For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\nFor DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold \n**Returns**\n\n- ([::Google::Protobuf::DoubleValue](./Google-Protobuf-DoubleValue)) --- Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specified `distance_measure` will affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted.\n\n\n For EUCLIDEAN, COSINE: WHERE distance \\\u003c= distance_threshold\n For DOT_PRODUCT: WHERE distance \\\u003e= distance_threshold\n\n### #limit\n\n def limit() -\u003e ::Google::Protobuf::Int32Value\n\n**Returns**\n\n- ([::Google::Protobuf::Int32Value](./Google-Protobuf-Int32Value)) --- Required. The number of nearest neighbors to return. Must be a positive integer of no more than 100.\n\n### #limit=\n\n def limit=(value) -\u003e ::Google::Protobuf::Int32Value\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Int32Value](./Google-Protobuf-Int32Value)) --- Required. The number of nearest neighbors to return. Must be a positive integer of no more than 100. \n**Returns**\n\n- ([::Google::Protobuf::Int32Value](./Google-Protobuf-Int32Value)) --- Required. The number of nearest neighbors to return. Must be a positive integer of no more than 100.\n\n### #query_vector\n\n def query_vector() -\u003e ::Google::Cloud::Datastore::V1::Value\n\n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::Value](./Google-Cloud-Datastore-V1-Value)) --- Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions.\n\n### #query_vector=\n\n def query_vector=(value) -\u003e ::Google::Cloud::Datastore::V1::Value\n\n**Parameter**\n\n- **value** ([::Google::Cloud::Datastore::V1::Value](./Google-Cloud-Datastore-V1-Value)) --- Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions. \n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::Value](./Google-Cloud-Datastore-V1-Value)) --- Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions.\n\n### #vector_property\n\n def vector_property() -\u003e ::Google::Cloud::Datastore::V1::PropertyReference\n\n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::PropertyReference](./Google-Cloud-Datastore-V1-PropertyReference)) --- Required. An indexed vector property to search upon. Only documents which contain vectors whose dimensionality match the query_vector can be returned.\n\n### #vector_property=\n\n def vector_property=(value) -\u003e ::Google::Cloud::Datastore::V1::PropertyReference\n\n**Parameter**\n\n- **value** ([::Google::Cloud::Datastore::V1::PropertyReference](./Google-Cloud-Datastore-V1-PropertyReference)) --- Required. An indexed vector property to search upon. Only documents which contain vectors whose dimensionality match the query_vector can be returned. \n**Returns**\n\n- ([::Google::Cloud::Datastore::V1::PropertyReference](./Google-Cloud-Datastore-V1-PropertyReference)) --- Required. An indexed vector property to search upon. Only documents which contain vectors whose dimensionality match the query_vector can be returned."]]