summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2020-04-06 17:38:22 +0200
committerGitHub <noreply@github.com>2020-04-06 17:38:22 +0200
commit5a8ca01510284386dac769e80222ee7e79dfd5ad (patch)
treefd7aabec14097af38d3d83bfb1a30326cd5bd8c9 /searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp
parente169f4da3356176f2626b41a8819ee7176c28e7d (diff)
parent5dd5309752463d86ced60b2ce0eb10de8f01414d (diff)
Merge pull request #12854 from vespa-engine/geirst/hnsw-index-params-in-attribute-header
Hnsw index params in attribute header
Diffstat (limited to 'searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp')
-rw-r--r--searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp b/searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp
new file mode 100644
index 00000000000..0f542d016a9
--- /dev/null
+++ b/searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp
@@ -0,0 +1,77 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/eval/eval/value_type.h>
+#include <vespa/searchcommon/attribute/config.h>
+#include <vespa/searchlib/attribute/attribute_header.h>
+#include <vespa/vespalib/data/fileheader.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+#include <vespa/log/log.h>
+LOG_SETUP("attribute_header_test");
+
+using namespace search;
+using namespace search::attribute;
+
+using HnswIPO = std::optional<HnswIndexParams>;
+using vespalib::eval::ValueType;
+
+const Config tensor_cfg(BasicType::TENSOR, CollectionType::SINGLE);
+const vespalib::string file_name = "my_file_name";
+const ValueType tensor_type = ValueType::from_spec("tensor<float>(x[4])");
+constexpr uint32_t num_docs = 23;
+constexpr uint64_t unique_value_count = 11;
+constexpr uint64_t total_value_count = 13;
+constexpr uint64_t create_serial_num = 17;
+constexpr uint32_t version = 19;
+
+vespalib::GenericHeader
+populate_header(const HnswIPO& hnsw_params)
+{
+ AttributeHeader header(file_name,
+ tensor_cfg.basicType(),
+ tensor_cfg.collectionType(),
+ tensor_type,
+ false,
+ PersistentPredicateParams(),
+ hnsw_params,
+ num_docs,
+ unique_value_count,
+ total_value_count,
+ create_serial_num,
+ version);
+
+ vespalib::GenericHeader result;
+ header.addTags(result);
+ return result;
+}
+
+void
+verify_roundtrip_serialization(const HnswIPO& hnsw_params_in)
+{
+ auto gen_header = populate_header(hnsw_params_in);
+ auto attr_header = AttributeHeader::extractTags(gen_header);
+
+ EXPECT_EQ(tensor_cfg.basicType(), attr_header.getBasicType());
+ EXPECT_EQ(tensor_cfg.collectionType(), attr_header.getCollectionType());
+ EXPECT_EQ(tensor_type, attr_header.getTensorType());
+ EXPECT_EQ(num_docs, attr_header.getNumDocs());
+ EXPECT_EQ(create_serial_num, attr_header.getCreateSerialNum());
+ EXPECT_EQ(version, attr_header.getVersion());
+ EXPECT_EQ(false, attr_header.getPredicateParamsSet());
+ const auto& hnsw_params_out = attr_header.get_hnsw_index_params();
+ EXPECT_EQ(hnsw_params_in.has_value(), hnsw_params_out.has_value());
+ if (hnsw_params_in.has_value()) {
+ EXPECT_EQ(hnsw_params_in.value(), hnsw_params_out.value());
+ }
+}
+
+TEST(AttributeHeaderTest, can_be_added_to_and_extracted_from_generic_header)
+{
+ verify_roundtrip_serialization(HnswIPO({16, 100, DistanceMetric::Euclidean}));
+ verify_roundtrip_serialization(HnswIPO({16, 100, DistanceMetric::Angular}));
+ verify_roundtrip_serialization(HnswIPO({16, 100, DistanceMetric::GeoDegrees}));
+ verify_roundtrip_serialization(HnswIPO());
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()
+