---
title: "neighbors(for:maximumCount:distanceType:)"
framework: naturallanguage
role: symbol
role_heading: Instance Method
path: "naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8f1jc"
---

# neighbors(for:maximumCount:distanceType:)

Retrieves a limited number of strings near a string in the vocabulary.

## Declaration

```swift
@nonobjc func neighbors(for string: String, maximumCount maxCount: Int, distanceType: NLDistanceType = .cosine) -> [(String, NLDistance)]
```

## Parameters

- `string`: A string in the embedding vocabulary.
- `maxCount`: The largest number of neighboring strings that the method can return in an array.
- `distanceType`: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from string.

## Return Value

Return Value An array of tuples that contain neighboring strings and their distances.

## See Also

### Finding strings and their distances in an embedding

- [neighbors(for:maximumCount:distanceType:)](naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8lp4z.md)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-72jda.md)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-6dy4x.md)
- [distance(between:and:distanceType:)](naturallanguage/nlembedding/distance(between:and:distancetype:).md)
- [NLDistance](naturallanguage/nldistance.md)
