Instance Method

distance(between:and:distanceType:)

Calculates the distance between two strings.

Declaration

@nonobjc func distance(between firstString: String, and secondString: String, distanceType: NLDistanceType = .cosine) -> NLDistance

Parameters

firstString

A string in the embedding vocabulary.

secondString

Another string in the embedding vocabulary.

distanceType

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

Return Value

An NLDistance (double) value.

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.

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.