File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,45 @@ def encode_array(arr)
9595end
9696```
9797
98+ ** Go**
99+ ```
100+ import(
101+ "math"
102+ "encoding/binary"
103+ "encoding/base64"
104+ )
105+
106+ func convertArrayToBase64(array []float64) string {
107+ bytes := make([]byte, 0, 8*len(array))
108+ for _, a := range array {
109+ bits := math.Float64bits(a)
110+ b := make([]byte, 8)
111+ binary.BigEndian.PutUint64(b, bits)
112+ bytes = append(bytes, b...)
113+ }
114+
115+ encoded := base64.StdEncoding.EncodeToString(bytes)
116+ return encoded
117+ }
118+
119+ func convertBase64ToArray(base64Str string) ([]float64, error) {
120+ decoded, err := base64.StdEncoding.DecodeString(base64Str)
121+ if err != nil {
122+ return nil, err
123+ }
124+
125+ length := len(decoded)
126+ array := make([]float64, 0, length/8)
127+
128+ for i := 0; i < len(decoded); i += 8 {
129+ bits := binary.BigEndian.Uint64(decoded[i : i+8])
130+ f := math.Float64frombits(bits)
131+ array = append(array, f)
132+ }
133+ return array, nil
134+ }
135+ ```
136+
98137### Querying
99138* For querying the 100 KNN documents use this POST message on your ES index:
100139
You can’t perform that action at this time.
0 commit comments