Skip to content

Commit 12c7ddb

Browse files
Fix all golangci-lint warnings
1 parent 1de154b commit 12c7ddb

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

‎collection_test.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,10 @@ func benchmarkCollection_Query(b *testing.B, n int, withContent bool) {
604604
// Let's say we embed 500 tokens, that's ~375 words, ~1875 characters
605605
doc.Content = randomString(r, 1875)
606606
}
607-
c.AddDocument(ctx, doc)
607+
608+
if err := c.AddDocument(ctx, doc); err != nil {
609+
b.Fatal(err)
610+
}
608611
}
609612

610613
b.ResetTimer()

‎db_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func TestDB_DeleteCollection(t *testing.T) {
394394
}
395395

396396
// Delete collection
397-
db.DeleteCollection(name)
397+
db.DeleteCollection(name) // nolint: errcheck
398398

399399
// Check expectations
400400
// We don't have access to the documents field, but we can rely on DB.ListCollections()
@@ -426,7 +426,7 @@ func TestDB_Reset(t *testing.T) {
426426
}
427427

428428
// Reset DB
429-
db.Reset()
429+
db.Reset() // nolint: errcheck
430430

431431
// Check expectations
432432
// We don't have access to the documents field, but we can rely on DB.ListCollections()

‎persistence_test.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func TestPersistenceWrite(t *testing.T) {
2828

2929
t.Run("gob", func(t *testing.T) {
3030
tempFilePath := tempDir + ".gob"
31-
persistToFile(tempFilePath, obj, false, "")
31+
if err := persistToFile(tempFilePath, obj, false, ""); err != nil {
32+
t.Fatal("expected nil, got", err)
33+
}
3234

3335
// Check if the file exists.
3436
_, err = os.Stat(tempFilePath)
@@ -57,7 +59,9 @@ func TestPersistenceWrite(t *testing.T) {
5759

5860
t.Run("gob gzipped", func(t *testing.T) {
5961
tempFilePath := tempDir + ".gob.gz"
60-
persistToFile(tempFilePath, obj, true, "")
62+
if err := persistToFile(tempFilePath, obj, true, ""); err != nil {
63+
t.Fatal("expected nil, got", err)
64+
}
6165

6266
// Check if the file exists.
6367
_, err = os.Stat(tempFilePath)

‎vector.go‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,11 @@ package chromem
22

33
import (
44
"errors"
5-
"fmt"
65
"math"
76
)
87

98
const isNormalizedPrecisionTolerance = 1e-6
109

11-
// cosineSimilarity calculates the cosine similarity between two vectors.
12-
// Vectors are normalized first.
13-
// The resulting value represents the similarity, so a higher value means the
14-
// vectors are more similar.
15-
func cosineSimilarity(a, b []float32) (float32, error) {
16-
// The vectors must have the same length
17-
if len(a) != len(b) {
18-
return 0, errors.New("vectors must have the same length")
19-
}
20-
21-
if !isNormalized(a) || !isNormalized(b) {
22-
a, b = normalizeVector(a), normalizeVector(b)
23-
}
24-
dotProduct, err := dotProduct(a, b)
25-
if err != nil {
26-
return 0, fmt.Errorf("couldn't calculate dot product: %w", err)
27-
}
28-
29-
// Vectors are already normalized, so no need to divide by magnitudes
30-
31-
return dotProduct, nil
32-
}
33-
3410
// dotProduct calculates the dot product between two vectors.
3511
// It's the same as cosine similarity for normalized vectors.
3612
// The resulting value represents the similarity, so a higher value means the

0 commit comments

Comments
 (0)