Instance Method

neighbors(for:maximumCount:distanceType:)

Retrieves the nearest neighbors of a string, given a number of neighbors and a distance type.

Declaration

@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 to find.

distanceType

The type of distance, which determines the formula the method uses to calculate distance.

Return Value

An array of terms and their distances.

See Also

Finding Strings in an Embedding

typealias NLDistance

The distance between two strings in a text embedding.

func neighbors(for: [Double], maximumCount: Int, distanceType: NLDistanceType) -> [(String, NLDistance)]

Retrieves the nearest strings to a vector, given a number of neighbors and a distance type.

func enumerateNeighbors(for: String, maximumCount: Int, distanceType: NLDistanceType, using: (String, NLDistance) -> Bool)

Enumerates the nearest neighbors of a string, given a closure, a number of neighbors, and a distance type.

func enumerateNeighbors(for: [Double], maximumCount: Int, distanceType: NLDistanceType, using: (String, NLDistance) -> Bool)

Enumerates the nearest strings of a vector, given a closure, a number of neighbors, and a distance type.