Skip to content

Commit 5647944

Browse files
committed
Added SetSlice method to HalfVector
1 parent 2fc63af commit 5647944

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

halfvec.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func (v HalfVector) EncodeText(buf []byte) (newBuf []byte, err error) {
6161
return buf, nil
6262
}
6363

64+
// SetSlice sets the underlying slice of float32.
65+
func (v *HalfVector) SetSlice(vec []float32) {
66+
v.vec = vec
67+
}
68+
6469
// statically assert that HalfVector implements sql.Scanner.
6570
var _ sql.Scanner = (*HalfVector)(nil)
6671

@@ -71,9 +76,6 @@ func (v *HalfVector) Scan(src interface{}) (err error) {
7176
return v.Parse(string(src))
7277
case string:
7378
return v.Parse(src)
74-
case []float32:
75-
v.vec = src
76-
return nil
7779
default:
7880
return fmt.Errorf("unsupported data type: %T", src)
7981
}

pgx/halfvec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ func (scanPlanHalfVectorCodecBinary) Scan(src []byte, dst any) error {
9393
vec = append(vec, float16.Frombits(binary.BigEndian.Uint16(buf[offset:offset+2])).Float32())
9494
offset += 2
9595
}
96-
return v.Scan(vec)
96+
v.SetSlice(vec)
97+
return nil
9798
}
9899

99100
type scanPlanHalfVectorCodecText struct{}

0 commit comments

Comments
 (0)