Instance Method

enumerateNeighbors(for:maximumCount:distanceType:using:)

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

Declaration

@nonobjc func enumerateNeighbors(for vector: [Double], maximumCount maxCount: Int, distanceType: NLDistanceType = .cosine, using block: (String, NLDistance) -> Bool)

Parameters

vector

A location in the vocabulary space.

maxCount

The largest number of neighboring strings to find.

distanceType

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

block

A closure that enumerates the nearest neighbors of the given vector.

String

A neighboring string.

NLDistance

The distance of the neighboring string

See Also

Finding Strings in an Embedding

typealias NLDistance

The distance between two strings in a text embedding.

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

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

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.