<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NaturalLanguage",
  "identifier" : "/documentation/NaturalLanguage/NLDistance",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Natural Language"
    ],
    "preciseIdentifier" : "c:@T@NLDistance"
  },
  "title" : "NLDistance"
}
-->

# NLDistance

The distance between two strings in a text embedding.

```
typealias NLDistance = Double
```

## Discussion

The meaning of an [`NLDistance`](/documentation/NaturalLanguage/NLDistance) is directly related to the [`NLDistanceType`](/documentation/NaturalLanguage/NLDistanceType) you use when you call a method that uses it. For example, if you use the [`neighborsForString:maximumCount:distanceType:`](/documentation/NaturalLanguage/NLEmbedding/neighborsForString:maximumCount:distanceType:) method and use [`NLDistanceType.cosine`](/documentation/NaturalLanguage/NLDistanceType/cosine) for the `distanceType` parameter, the method calculates the cosine distance and returns it as an [`NLDistance`](/documentation/NaturalLanguage/NLDistance).

## Topics

### Calculating Distance

[`NLDistanceType`](/documentation/NaturalLanguage/NLDistanceType)

The means of calculating a distance between two locations in a text embedding.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)