Skip to content

Commit

Permalink
_example/flat_index_map.go: example test added to demonstrate usage
Browse files Browse the repository at this point in the history
  • Loading branch information
orihabAnyvision committed Jul 28, 2021
1 parent 53ce01f commit c9fed28
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions _example/flat_index_map/flat_index_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
"github.com/DataIntelligenceCrew/go-faiss"
)

func main() {
dimension := 1
dbSize := 5

index, err := faiss.NewIndexFlat(dimension, faiss.MetricL2)
if err != nil {
fmt.Println(err.Error())
}
indexMap, err := faiss.NewIndexIDMap(index)
if err != nil {
fmt.Println(err.Error())
}
xb := []float32{1,2,3,4,5}
ids := make([]int64, dbSize)
for i := 0; i < dbSize; i++ {
ids[i] = int64(i)
}

err = indexMap.AddWithIDs(xb, ids)
if err != nil {
fmt.Println(err.Error())
}
toFind := xb[dimension:2*dimension]
distances1, resultIds, err := indexMap.Search(toFind, 5)
fmt.Println(distances1, resultIds, err)
fmt.Println(resultIds[0] == ids[1])
fmt.Println(distances1[0] == 0)

}

0 comments on commit c9fed28

Please sign in to comment.