public sealed class StructuredQuery.Types.FindNearest : IMessage<StructuredQuery.Types.FindNearest>, IEquatable<StructuredQuery.Types.FindNearest>, IDeepCloneable<StructuredQuery.Types.FindNearest>, IBufferMessage, IMessage
Reference documentation and code samples for the Firestore v1 API class StructuredQuery.Types.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.
Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform to [document field
name][google.firestore.v1.Document.fields] limitations.
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
[[["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-08-28 UTC."],[[["\u003cp\u003eThis document provides reference information for the \u003ccode\u003eStructuredQuery.Types.FindNearest\u003c/code\u003e class within the Firestore v1 API, focusing on its use in nearest neighbors searches.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eStructuredQuery.Types.FindNearest\u003c/code\u003e enables searching for documents with vectors closest to a specified query vector, overriding any existing \u003ccode\u003eorder_by\u003c/code\u003e stage in a query.\u003c/p\u003e\n"],["\u003cp\u003eThe class allows specifying a required \u003ccode\u003edistance_measure\u003c/code\u003e, an optional \u003ccode\u003edistance_result_field\u003c/code\u003e to store distance calculations, a \u003ccode\u003edistance_threshold\u003c/code\u003e to filter results, a \u003ccode\u003elimit\u003c/code\u003e on the number of returned results, a \u003ccode\u003equery_vector\u003c/code\u003e, and a required \u003ccode\u003evector_field\u003c/code\u003e to search on.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eFindNearest\u003c/code\u003e function is available in various versions of the Google.Cloud.Firestore.V1 library, ranging from 2.3.0 to the latest 3.10.0, and is implemented through multiple interfaces like IMessage, IEquatable, IDeepCloneable, and IBufferMessage.\u003c/p\u003e\n"]]],[],null,["# Firestore v1 API - Class StructuredQuery.Types.FindNearest (3.10.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.10.0 (latest)](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.9.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.8.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.7.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.6.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.5.1](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.5.1/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.4.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.3.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.2.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.1.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.1.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [3.0.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.0.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [2.5.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.5.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [2.4.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.4.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest)\n- [2.3.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.3.0/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest) \n\n public sealed class StructuredQuery.Types.FindNearest : IMessage\u003cStructuredQuery.Types.FindNearest\u003e, IEquatable\u003cStructuredQuery.Types.FindNearest\u003e, IDeepCloneable\u003cStructuredQuery.Types.FindNearest\u003e, IBufferMessage, IMessage\n\nReference documentation and code samples for the Firestore v1 API class StructuredQuery.Types.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\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e StructuredQuery.Types.FindNearest \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery)[Types](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types)[FindNearest](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery)[Types](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types)[FindNearest](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery)[Types](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types)[FindNearest](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery.Types.FindNearest), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Firestore.V1](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.Firestore.V1.dll\n\nConstructors\n------------\n\n### FindNearest()\n\n public FindNearest()\n\n### FindNearest(FindNearest)\n\n public FindNearest(StructuredQuery.Types.FindNearest other)\n\nProperties\n----------\n\n### DistanceMeasure\n\n public StructuredQuery.Types.FindNearest.Types.DistanceMeasure DistanceMeasure { get; set; }\n\nRequired. The distance measure to use, required.\n\n### DistanceResultField\n\n public string DistanceResultField { get; set; }\n\nOptional. Optional name of the field to output the result of the vector\ndistance calculation. Must conform to \\[document field\nname\\]\\[google.firestore.v1.Document.fields\\] limitations.\n\n### DistanceThreshold\n\n public double? DistanceThreshold { get; set; }\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### Limit\n\n public int? Limit { get; set; }\n\nRequired. The number of nearest neighbors to return. Must be a positive\ninteger of no more than 1000.\n\n### QueryVector\n\n public Value QueryVector { get; set; }\n\nRequired. The query vector that we are searching on. Must be a vector of\nno more than 2048 dimensions.\n\n### VectorField\n\n public StructuredQuery.Types.FieldReference VectorField { get; set; }\n\nRequired. An indexed vector field to search upon. Only documents which\ncontain vectors whose dimensionality match the query_vector can be\nreturned."]]