Reference documentation and code samples for the Firestore in Datastore mode V1 API module Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure.
The distance measure to use when comparing vectors.
Constants
DISTANCE_MEASURE_UNSPECIFIED
value: 0 Should not be set.
EUCLIDEAN
value: 1 Measures the EUCLIDEAN distance between the vectors. See
Euclidean to learn
more. The resulting distance decreases the more similar two vectors are.
COSINE
value: 2 COSINE distance compares vectors based on the angle between them, which
allows you to measure similarity that isn't based on the vectors
magnitude. We recommend using DOT_PRODUCT with unit normalized vectors
instead of COSINE distance, which is mathematically equivalent with
better performance. See Cosine
Similarity to learn
more about COSINE similarity and COSINE distance. The resulting COSINE
distance decreases the more similar two vectors are.
DOT_PRODUCT
value: 3 Similar to cosine but is affected by the magnitude of the vectors. See
Dot Product to learn more.
The resulting distance increases the more similar two vectors are.
[[["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 - Module Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure (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-DistanceMeasure)\n- [1.4.0](/ruby/docs/reference/google-cloud-datastore-v1/1.4.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [1.3.1](/ruby/docs/reference/google-cloud-datastore-v1/1.3.1/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [1.2.0](/ruby/docs/reference/google-cloud-datastore-v1/1.2.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [1.1.0](/ruby/docs/reference/google-cloud-datastore-v1/1.1.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [1.0.1](/ruby/docs/reference/google-cloud-datastore-v1/1.0.1/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.19.0](/ruby/docs/reference/google-cloud-datastore-v1/0.19.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.18.0](/ruby/docs/reference/google-cloud-datastore-v1/0.18.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.17.0](/ruby/docs/reference/google-cloud-datastore-v1/0.17.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.16.3](/ruby/docs/reference/google-cloud-datastore-v1/0.16.3/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.15.0](/ruby/docs/reference/google-cloud-datastore-v1/0.15.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.14.0](/ruby/docs/reference/google-cloud-datastore-v1/0.14.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.13.1](/ruby/docs/reference/google-cloud-datastore-v1/0.13.1/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.12.0](/ruby/docs/reference/google-cloud-datastore-v1/0.12.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.11.1](/ruby/docs/reference/google-cloud-datastore-v1/0.11.1/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.10.0](/ruby/docs/reference/google-cloud-datastore-v1/0.10.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.9.0](/ruby/docs/reference/google-cloud-datastore-v1/0.9.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.8.0](/ruby/docs/reference/google-cloud-datastore-v1/0.8.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.7.0](/ruby/docs/reference/google-cloud-datastore-v1/0.7.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.6.0](/ruby/docs/reference/google-cloud-datastore-v1/0.6.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.5.0](/ruby/docs/reference/google-cloud-datastore-v1/0.5.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.4.0](/ruby/docs/reference/google-cloud-datastore-v1/0.4.0/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure)\n- [0.3.5](/ruby/docs/reference/google-cloud-datastore-v1/0.3.5/Google-Cloud-Datastore-V1-FindNearest-DistanceMeasure) \nReference documentation and code samples for the Firestore in Datastore mode V1 API module Google::Cloud::Datastore::V1::FindNearest::DistanceMeasure.\n\nThe distance measure to use when comparing vectors.\n\nConstants\n---------\n\n### DISTANCE_MEASURE_UNSPECIFIED\n\n**value:** 0 \nShould not be set.\n\n### EUCLIDEAN\n\n**value:** 1 \nMeasures the EUCLIDEAN distance between the vectors. See\n[Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn\nmore. The resulting distance decreases the more similar two vectors are.\n\n### COSINE\n\n**value:** 2 \nCOSINE distance compares vectors based on the angle between them, which\nallows you to measure similarity that isn't based on the vectors\nmagnitude. We recommend using DOT_PRODUCT with unit normalized vectors\ninstead of COSINE distance, which is mathematically equivalent with\nbetter performance. See [Cosine\nSimilarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn\nmore about COSINE similarity and COSINE distance. The resulting COSINE\ndistance decreases the more similar two vectors are.\n\n### DOT_PRODUCT\n\n**value:** 3 \nSimilar to cosine but is affected by the magnitude of the vectors. See\n[Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more.\nThe resulting distance increases the more similar two vectors are."]]