# Cloud Firestore V1 Client - Class FindNearest (2.2.0-RC1)

2.2.0-RC1 2.1.0 (latest) 2.0.2-RC1 1.55.0 1.54.4 1.53.1 1.52.0 1.51.0 1.50.0 1.48.1 1.47.3 1.46.0 1.45.2 1.44.1 1.43.3 1.40.0 1.39.0 1.38.0 1.37.7 1.36.1 1.35.0 1.34.0 1.33.0 1.32.0 1.31.0 1.30.0 1.28.0 1.27.3 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 message `google.firestore.v1.StructuredQuery.FindNearest`

## Namespace

Google \\ Cloud \\ Firestore \\ V1 \\ StructuredQuery

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` Optional. Data for populating the Message object. |
| `↳ vector_field` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FieldReference` Required. An indexed vector field to search upon. Only documents which contain vectors whose dimensionality match the query_vector can be returned. |
| `↳ query_vector` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Value` Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions. |
| `↳ distance_measure` | `int` Required. The distance measure to use, required. |
| `↳ limit` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value` Required. The number of nearest neighbors to return. Must be a positive integer of no more than 1000. |
| `↳ distance_result_field` | `string` Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to [document field name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations. |
| `↳ distance_threshold` | `https://protobuf.dev/reference/php/api-docs/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` |

### getVectorField

Required. An indexed vector field to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FieldReference|null` |   |

### hasVectorField

### clearVectorField

### setVectorField

Required. An indexed vector field to search upon. Only documents which
contain vectors whose dimensionality match the query_vector can be
returned.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FieldReference` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getQueryVector

Required. The query vector that we are searching on. Must be a vector of
no more than 2048 dimensions.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Value|null` |   |

### hasQueryVector

### clearQueryVector

### setQueryVector

Required. The query vector that we are searching on. Must be a vector of
no more than 2048 dimensions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Value` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getDistanceMeasure

Required. The distance measure to use, required.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | Enum of type [DistanceMeasure](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FindNearest.DistanceMeasure). |

### setDistanceMeasure

Required. The distance measure to use, required.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `int` Enum of type [DistanceMeasure](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredQuery.FindNearest.DistanceMeasure). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getLimit

Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 1000.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value|null` |   |

### hasLimit

### clearLimit

### getLimitValue

Returns the unboxed value from `getLimit()`

Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 1000.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int|null` |   |

### setLimit

Required. The number of nearest neighbors to return. Must be a positive
integer of no more than 1000.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### setLimitValue

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 to [document field
name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setDistanceResultField

Optional. Optional name of the field to output the result of the vector
distance calculation. Must conform to [document field
name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.

| **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 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** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/DoubleValue|null` |   |

### hasDistanceThreshold

### clearDistanceThreshold

### getDistanceThresholdValue

Returns the unboxed value from `getDistanceThreshold()`

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** ||
|---|---|
| **Type** | **Description** |
| `float|null` |   |

### setDistanceThreshold

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`

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/DoubleValue` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### setDistanceThresholdValue

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 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`

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `float|null` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |