Skip to content

Commit b23568f

Browse files
_example/flat_index_map.go: example test added to demonstrate usage
1 parent f5ec593 commit b23568f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/orihabAnyvision/go-faiss"
6+
)
7+
8+
func main() {
9+
dimension := 1
10+
dbSize := 5
11+
12+
index, err := faiss.NewIndexFlat(dimension, faiss.MetricL2)
13+
if err != nil {
14+
fmt.Println(err.Error())
15+
}
16+
indexMap, err := faiss.NewIndexIDMap(index)
17+
if err != nil {
18+
fmt.Println(err.Error())
19+
}
20+
xb := []float32{1,2,3,4,5}
21+
ids := make([]int64, dbSize)
22+
for i := 0; i < dbSize; i++ {
23+
ids[i] = int64(i)
24+
}
25+
26+
err = indexMap.AddWithIDs(xb, ids)
27+
if err != nil {
28+
fmt.Println(err.Error())
29+
}
30+
toFind := xb[dimension:2*dimension]
31+
distances1, resultIds, err := indexMap.Search(toFind, 5)
32+
fmt.Println(distances1, resultIds, err)
33+
fmt.Println(resultIds[0] == ids[1])
34+
fmt.Println(distances1[0] == 0)
35+
36+
}

0 commit comments

Comments
 (0)