---
title: "distance(between:and:distanceType:)"
framework: createml
role: symbol
role_heading: Instance Method
path: "createml/mlwordembedding/distance(between:and:distancetype:)"
---

# distance(between:and:distanceType:)

Calculates the distance between two strings in the vocabulary space.

## Declaration

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

Return Value The distance

## See Also

### Testing a word embedding

- [prediction(from:maxCount:maxDistance:distanceType:)](createml/mlwordembedding/prediction(from:maxcount:maxdistance:distancetype:).md)
- [NLDistanceType](naturallanguage/nldistancetype.md)
- [contains(_:)](createml/mlwordembedding/contains(_:).md)
- [vector(for:)](createml/mlwordembedding/vector(for:).md)
