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

Commit

Permalink
fix (postgres/breaking): change postgres document content columns to …
Browse files Browse the repository at this point in the history
…bytea to avoid encoding issue (#155)
  • Loading branch information
iwilltry42 authored Oct 23, 2024
1 parent 8a7aea3 commit e4bd7fb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/vectorstore/pgvector/pgvector.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (v VectorStore) createEmbeddingTableIfNotExists(ctx context.Context, tx pgx
sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s (
collection_id uuid,
embedding vector%s,
document varchar,
document bytea,
cmetadata json,
"uuid" uuid NOT NULL,
CONSTRAINT knowledge_pg_embedding_collection_id_fkey
Expand Down Expand Up @@ -312,7 +312,7 @@ func (v VectorStore) AddDocuments(ctx context.Context, docs []vs.Document, colle
return
}

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

}(doc)

Expand Down Expand Up @@ -395,9 +395,11 @@ LIMIT $3`, v.embeddingTableName,
docs := make([]vs.Document, 0)
for rows.Next() {
doc := vs.Document{}
if err := rows.Scan(&doc.ID, &doc.Content, &doc.Metadata, &doc.SimilarityScore); err != nil {
var contentB []byte
if err := rows.Scan(&doc.ID, &contentB, &doc.Metadata, &doc.SimilarityScore); err != nil {
return nil, err
}
doc.Content = string(contentB)
docs = append(docs, doc)
}
return docs, rows.Err()
Expand Down

0 comments on commit e4bd7fb

Please sign in to comment.