diff options
author | Geir Storli <geirst@verizonmedia.com> | 2020-04-06 13:54:22 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2020-04-06 13:54:22 +0000 |
commit | 5dd5309752463d86ced60b2ce0eb10de8f01414d (patch) | |
tree | 02916c6d93b8eb5248243732df4c84eb1e0cdf0f /searchlib/src/tests/attribute/attribute_header/attribute_header_test.cpp | |
parent | 2539844cda5a0b8bfbac36ffe127fce27b6f5591 (diff) |
Add hnsw index params to attribute header if set.
Also extract num docs (aka docid limit) when reading 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.cpp | 77 |
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() + |