From 5f1568b617eefa77963e648514842c6e38c9a779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Mon, 4 Mar 2024 20:33:17 +0100 Subject: [PATCH] Fix metadatas validation in AddConcurrently() --- collection.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/collection.go b/collection.go index d3395cd..86e4627 100644 --- a/collection.go +++ b/collection.go @@ -103,8 +103,13 @@ func (c *Collection) AddConcurrently(ctx context.Context, ids []string, embeddin // Assign empty slice so we can simply access via index later embeddings = make([][]float32, len(ids)) } - if len(metadatas) != 0 && len(ids) != len(metadatas) { - return errors.New("ids, metadatas and contents must have the same length") + if len(metadatas) != 0 { + if len(ids) != len(metadatas) { + return errors.New("when metadatas is not empty it must have the same length as ids") + } + } else { + // Assign empty slice so we can simply access via index later + metadatas = make([]map[string]string, len(ids)) } if len(contents) != 0 { if len(contents) != len(ids) {