From 0ea04271947e338e60f0bad85291f149599cb3c3 Mon Sep 17 00:00:00 2001 From: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:39:15 -0700 Subject: [PATCH] log, won't return on failure to write db (#165) --- pkg/store/postgres/documentstore.go | 2 +- pkg/store/postgres/documentstore_test.go | 47 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pkg/store/postgres/documentstore_test.go diff --git a/pkg/store/postgres/documentstore.go b/pkg/store/postgres/documentstore.go index 8a03adce..edfad313 100644 --- a/pkg/store/postgres/documentstore.go +++ b/pkg/store/postgres/documentstore.go @@ -385,7 +385,7 @@ func (ds *DocumentStore) documentEmbeddingUpdater( docs := documentsFromEmbeddingUpdates(updates) err := dbCollection.UpdateDocuments(ctx, docs) if err != nil { - return fmt.Errorf("failed to update document embedding: %w", err) + log.Errorf("failed to update document embedding: %s", err) } log.Debugf("Document embedding updater updated %d documents", len(updates)) diff --git a/pkg/store/postgres/documentstore_test.go b/pkg/store/postgres/documentstore_test.go new file mode 100644 index 00000000..3e461c8e --- /dev/null +++ b/pkg/store/postgres/documentstore_test.go @@ -0,0 +1,47 @@ +package postgres + +import ( + "testing" + + "github.com/google/uuid" + + "github.com/getzep/zep/pkg/models" + "github.com/stretchr/testify/assert" +) + +func TestDocumentsFromEmbeddingUpdates(t *testing.T) { + uuid1 := uuid.New() + uuid2 := uuid.New() + + updates := []models.DocEmbeddingUpdate{ + { + UUID: uuid1, + Embedding: []float32{0.1, 0.2, 0.3}, + }, + { + UUID: uuid2, + Embedding: []float32{0.4, 0.5, 0.6}, + }, + } + + expectedDocs := []models.Document{ + { + DocumentBase: models.DocumentBase{ + UUID: uuid1, + IsEmbedded: true, + }, + Embedding: []float32{0.1, 0.2, 0.3}, + }, + { + DocumentBase: models.DocumentBase{ + UUID: uuid2, + IsEmbedded: true, + }, + Embedding: []float32{0.4, 0.5, 0.6}, + }, + } + + docs := documentsFromEmbeddingUpdates(updates) + + assert.Equal(t, expectedDocs, docs) +}