Skip to content

Commit c84830c

Browse files
committed
remove
1 parent df95602 commit c84830c

File tree

7 files changed

+19
-39
lines changed

7 files changed

+19
-39
lines changed

dist/MiniLM-L6-v2.Q4_K_M.gguf

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/linux-x64/libggml.so

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/linux-x64/libllama.so

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/windows-x64/ggml.dll

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/windows-x64/llama.dll

Lines changed: 0 additions & 3 deletions
This file was deleted.

search/bruteforce.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type Result[T any] struct {
1818
// Index represents a brute-force search index, returning exact results.
1919
type Index[T any] struct {
2020
arr []entry[T]
21-
dim int
2221
}
2322

2423
// NewIndex creates a new exact search index.
@@ -42,7 +41,7 @@ func (b *Index[T]) Search(query Vector, k int) []Result[T] {
4241
return nil
4342
}
4443

45-
var h minheap[T]
44+
dst := make(minheap[T], 0, k)
4645
for _, v := range b.arr {
4746
relevance := Cosine(v.Vector, query)
4847
result := Result[T]{
@@ -53,29 +52,24 @@ func (b *Index[T]) Search(query Vector, k int) []Result[T] {
5352
// If the heap is not full, add the result, otherwise replace
5453
// the minimum element
5554
switch {
56-
case h.Len() < k:
57-
h.Push(result)
58-
case relevance > h[0].Relevance:
59-
h.Pop()
60-
h.Push(result)
55+
case dst.Len() < k:
56+
dst.Push(result)
57+
case relevance > dst[0].Relevance:
58+
dst.Pop()
59+
dst.Push(result)
6160
}
6261
}
6362

6463
// Sort the results by relevance
65-
sort.Sort(&h)
66-
return h
64+
sort.Sort(&dst)
65+
return dst
6766
}
6867

6968
// --------------------------------- Heap ---------------------------------
7069

7170
// minheap is a min-heap of top values, ordered by relevance.
7271
type minheap[T any] []Result[T]
7372

74-
// Reset resets the minheap to an empty state.
75-
func (h *minheap[T]) Reset() {
76-
*h = (*h)[:0]
77-
}
78-
7973
// Len, Less, Swap implement the sort.Interface.
8074
func (h *minheap[T]) Len() int { return len(*h) }
8175
func (h *minheap[T]) Less(i, j int) bool { return (*h)[i].Relevance > (*h)[j].Relevance }

search/bruteforce_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ import (
1010

1111
/*
1212
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
13-
BenchmarkBruteForce-24 4123 301825 ns/op 744 B/op 5 allocs/op
13+
BenchmarkIndex/search-24 4401 265430 ns/op 264 B/op 2 allocs/op
1414
*/
15-
func BenchmarkBruteForce(b *testing.B) {
15+
func BenchmarkIndex(b *testing.B) {
1616
data, err := loadDataset()
1717
assert.NoError(b, err)
1818

19-
bag := NewIndex[string]()
19+
index := NewIndex[string]()
2020
for _, entry := range data {
21-
bag.Add(entry.Vector, entry.Pair[0])
21+
index.Add(entry.Vector, entry.Pair[0])
2222
}
2323

24-
b.ReportAllocs()
25-
b.ResetTimer()
26-
for i := 0; i < b.N; i++ {
27-
for _, v := range bag.Search(data[i%1000].Vector, 5) {
28-
_ = v
24+
b.Run("search", func(b *testing.B) {
25+
b.ReportAllocs()
26+
b.ResetTimer()
27+
for i := 0; i < b.N; i++ {
28+
_ = index.Search(data[i%1000].Vector, 5)
2929
}
30-
}
30+
})
31+
3132
}
3233

3334
func TestIndex(t *testing.T) {

0 commit comments

Comments
 (0)