Skip to content

Commit

Permalink
Fixed TestVectorBase64 (#2017)
Browse files Browse the repository at this point in the history
  • Loading branch information
Likith101 committed Apr 22, 2024
1 parent 757705e commit 24d85e7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions search_knn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package bleve

import (
"archive/zip"
"bytes"
"encoding/base64"
"encoding/binary"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -411,11 +413,20 @@ func TestVectorBase64Index(t *testing.T) {
}

for _, doc := range documents {
vec, err := json.Marshal(doc["vector"])
if err != nil {
t.Fatal(err)
vec, ok := doc["vector"].([]float32)
if !ok {
t.Fatal("Typecasting vector to float array failed")
}

buf := new(bytes.Buffer)
for _, v := range vec {
err := binary.Write(buf, binary.LittleEndian, v)
if err != nil {
t.Fatal(err)
}
}
doc["vectorEncoded"] = base64.StdEncoding.EncodeToString(vec)

doc["vectorEncoded"] = base64.StdEncoding.EncodeToString(buf.Bytes())
}

for _, sr := range searchRequestsCopy {
Expand Down Expand Up @@ -563,7 +574,7 @@ func TestVectorBase64Index(t *testing.T) {
type testDocument struct {
ID string `json:"id"`
Content string `json:"content"`
Vector []float64 `json:"vector"`
Vector []float32 `json:"vector"`
}

func readDatasetAndQueries(fileName string) ([]testDocument, []*SearchRequest, error) {
Expand Down

0 comments on commit 24d85e7

Please sign in to comment.