<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLWordEmbedding/distance(between:and:distanceType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Create ML",
      "CreateML"
    ],
    "preciseIdentifier" : "s:8CreateML15MLWordEmbeddingV8distance7between3and0E4TypeSdSS_SSSo010NLDistanceH0VtF"
  },
  "title" : "distance(between:and:distanceType:)"
}
-->

# distance(between:and:distanceType:)

Calculates the distance between two strings in the vocabulary space.

```
func distance(between first: String, and second: String, distanceType: NLDistanceType = .cosine) -> Double
```

## Parameters

`first`

A string in the embedding vocabulary.

`second`

Another string in the embedding vocabulary.

`distanceType`

The metric to use to calculate the distance between the first and second strings.

## Return Value

The distance

---

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)