Skip to content

Commit 48fdcf2

Browse files
committed
Added test for Postgres arrays with pg
1 parent 5feb8e5 commit 48fdcf2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pg_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type PgItem struct {
1919
HalfEmbedding pgvector.HalfVector `pg:"type:halfvec(3)"`
2020
BinaryEmbedding string `pg:"type:bit(3)"`
2121
SparseEmbedding pgvector.SparseVector `pg:"type:sparsevec(3)"`
22+
Embeddings []pgvector.Vector `pg:"type:vector(3)[]"`
2223
}
2324

2425
func CreatePgItems(db *pg.DB) {
@@ -28,18 +29,21 @@ func CreatePgItems(db *pg.DB) {
2829
HalfEmbedding: pgvector.NewHalfVector([]float32{1, 1, 1}),
2930
BinaryEmbedding: "000",
3031
SparseEmbedding: pgvector.NewSparseVector([]float32{1, 1, 1}),
32+
Embeddings: []pgvector.Vector{pgvector.NewVector([]float32{1, 1, 1})},
3133
},
3234
PgItem{
3335
Embedding: pgvector.NewVector([]float32{2, 2, 2}),
3436
HalfEmbedding: pgvector.NewHalfVector([]float32{2, 2, 2}),
3537
BinaryEmbedding: "101",
3638
SparseEmbedding: pgvector.NewSparseVector([]float32{2, 2, 2}),
39+
Embeddings: []pgvector.Vector{pgvector.NewVector([]float32{2, 2, 2})},
3740
},
3841
PgItem{
3942
Embedding: pgvector.NewVector([]float32{1, 1, 2}),
4043
HalfEmbedding: pgvector.NewHalfVector([]float32{1, 1, 2}),
4144
BinaryEmbedding: "111",
4245
SparseEmbedding: pgvector.NewSparseVector([]float32{1, 1, 2}),
46+
Embeddings: []pgvector.Vector{pgvector.NewVector([]float32{1, 1, 2})},
4347
},
4448
}
4549

@@ -93,6 +97,9 @@ func TestPg(t *testing.T) {
9397
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
9498
t.Error()
9599
}
100+
if !reflect.DeepEqual(items[1].Embeddings, []pgvector.Vector{pgvector.NewVector([]float32{1, 1, 2})}) {
101+
t.Error()
102+
}
96103

97104
var distances []float64
98105
err = db.Model(&items).ColumnExpr("embedding <-> ?", pgvector.NewVector([]float32{1, 1, 1})).Order("id").Select(&distances)

0 commit comments

Comments
 (0)