Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit e4bd7fb

Browse files
authored
fix (postgres/breaking): change postgres document content columns to bytea to avoid encoding issue (#155)
1 parent 8a7aea3 commit e4bd7fb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/vectorstore/pgvector/pgvector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (v VectorStore) createEmbeddingTableIfNotExists(ctx context.Context, tx pgx
192192
sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s (
193193
collection_id uuid,
194194
embedding vector%s,
195-
document varchar,
195+
document bytea,
196196
cmetadata json,
197197
"uuid" uuid NOT NULL,
198198
CONSTRAINT knowledge_pg_embedding_collection_id_fkey
@@ -312,7 +312,7 @@ func (v VectorStore) AddDocuments(ctx context.Context, docs []vs.Document, colle
312312
return
313313
}
314314

315-
b.Queue(sql, doc.ID, doc.Content, pgvector.NewVector(vec), doc.Metadata, cid)
315+
b.Queue(sql, doc.ID, []byte(doc.Content), pgvector.NewVector(vec), doc.Metadata, cid)
316316

317317
}(doc)
318318

@@ -395,9 +395,11 @@ LIMIT $3`, v.embeddingTableName,
395395
docs := make([]vs.Document, 0)
396396
for rows.Next() {
397397
doc := vs.Document{}
398-
if err := rows.Scan(&doc.ID, &doc.Content, &doc.Metadata, &doc.SimilarityScore); err != nil {
398+
var contentB []byte
399+
if err := rows.Scan(&doc.ID, &contentB, &doc.Metadata, &doc.SimilarityScore); err != nil {
399400
return nil, err
400401
}
402+
doc.Content = string(contentB)
401403
docs = append(docs, doc)
402404
}
403405
return docs, rows.Err()

0 commit comments

Comments
 (0)