From c7e5285618074a8b3ba418382ede1b7e2cdeeef7 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Thu, 10 Aug 2023 20:50:57 +0530 Subject: [PATCH] Add additional test. --- test/collection_vector_search_test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp index b55bb085..c15161ae 100644 --- a/test/collection_vector_search_test.cpp +++ b/test/collection_vector_search_test.cpp @@ -1069,6 +1069,32 @@ TEST_F(CollectionVectorTest, UpdateOfCollWithNonOptionalEmbeddingField) { ASSERT_TRUE(update_op.ok()); } +TEST_F(CollectionVectorTest, FreshEmplaceWithOptionalEmbeddingReferencedField) { + auto schema = R"({ + "name": "objects", + "fields": [ + {"name": "name", "type": "string", "optional": true}, + {"name": "about", "type": "string"}, + {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "ts/e5-small"}}} + ] + })"_json; + + TextEmbedderManager::set_model_dir("/tmp/typesense_test/models"); + + auto op = collectionManager.create_collection(schema); + ASSERT_TRUE(op.ok()); + Collection* coll = op.get(); + + nlohmann::json object; + object["id"] = "0"; + object["about"] = "about butter"; + + auto add_op = coll->add(object.dump(), EMPLACE); + ASSERT_FALSE(add_op.ok()); + ASSERT_EQ("No valid fields found to create embedding for `embedding`, please provide at least one valid field " + "or make the embedding field optional.", add_op.error()); +} + TEST_F(CollectionVectorTest, SkipEmbeddingOpWhenValueExists) { nlohmann::json schema = R"({ "name": "objects",