use external factory for distance function
#include "hnsw_index.h"
#include "random_level_generator.h"
#include "inv_log_level_generator.h"
+#include "distance_function_factory.h"
#include <vespa/searchcommon/attribute/config.h>
namespace search::tensor {
@@ -17,16 +18,6 @@ class LevelZeroGenerator : public RandomLevelGenerator {
uint32_t max_level() override { return 0; }
};
-DistanceFunction::UP
-make_distance_function(ValueType::CellType cell_type)
-{
- if (cell_type == ValueType::CellType::FLOAT) {
- return std::make_unique<SquaredEuclideanDistance<float>>();
- } else {
- return std::make_unique<SquaredEuclideanDistance<double>>();
- }
-}
-
RandomLevelGenerator::UP
make_random_level_generator(uint32_t m)
{
@@ -47,7 +38,10 @@ DefaultNearestNeighborIndexFactory::make(const DocVectorAccess& vectors,
m,
params.neighbors_to_explore_at_insert(),
true);
- return std::make_unique<HnswIndex>(vectors, make_distance_function(cell_type), make_random_level_generator(m), cfg);
+ return std::make_unique<HnswIndex>(vectors,
+ make_distance_function(params.distance_metric(), cell_type),
+ make_random_level_generator(m),
+ cfg);
}
}
