Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosineDistance ¶
Types ¶
type DistanceFn ¶
type NaiveKNN ¶
type NaiveKNN struct {
// contains filtered or unexported fields
}
Example ¶
// Define the input vectors vecs := []Vector{ {ID: "vec1", Point: []float64{1.0, 2.0, 3.0}}, {ID: "vec2", Point: []float64{4.0, 5.0, 6.0}}, {ID: "vec3", Point: []float64{7.0, 8.0, 9.0}}, } // Create a new NaiveKNN instance knn, err := NewNaiveKNN(vecs, CosineDistance) if err != nil { fmt.Println("Failed to create NaiveKNN:", err) return } // Define the target vector target := Vector{ID: "target", Point: []float64{1., 5., 9.}} // Perform the KNN search k := 2 result := knn.Search(k, target) // Print the result for _, vec := range result { fmt.Println(vec.ID, vec.Point) }
Output: vec1 [1 2 3] vec2 [4 5 6]
func NewNaiveKNN ¶
func NewNaiveKNN(vecs []Vector, fn DistanceFn) (*NaiveKNN, error)
Click to show internal directories.
Click to hide internal directories.