Skip to content

Commit

Permalink
Unify the def of max vector dims
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Aug 13, 2024
1 parent 61d05ff commit 6458415
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions dbms/src/Storages/DeltaMerge/Index/VectorIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Storages/DeltaMerge/File/dtpb/dmfile.pb.h>
#include <Storages/DeltaMerge/Index/VectorIndex.h>
#include <Storages/DeltaMerge/Index/VectorIndexHNSW/Index.h>
#include <TiDB/Schema/VectorIndex.h>
#include <tipb/executor.pb.h>

namespace DB::ErrorCodes
Expand All @@ -41,15 +42,15 @@ bool VectorIndexBuilder::isSupportedType(const IDataType & type)
VectorIndexBuilderPtr VectorIndexBuilder::create(const TiDB::VectorIndexDefinitionPtr & definition)
{
RUNTIME_CHECK(definition->dimension > 0);
RUNTIME_CHECK(definition->dimension <= std::numeric_limits<UInt32>::max());
RUNTIME_CHECK(definition->dimension <= TiDB::MAX_VECTOR_DIMENSION);

switch (definition->kind)
{
case tipb::VectorIndexKind::HNSW:
return std::make_shared<VectorIndexHNSWBuilder>(definition);
default:
throw Exception(
ErrorCodes::INCORRECT_QUERY,
ErrorCodes::BAD_ARGUMENTS,
"Unsupported vector index {}",
tipb::VectorIndexKind_Name(definition->kind));
}
Expand All @@ -58,7 +59,7 @@ VectorIndexBuilderPtr VectorIndexBuilder::create(const TiDB::VectorIndexDefiniti
VectorIndexViewerPtr VectorIndexViewer::view(const dtpb::VectorIndexFileProps & file_props, std::string_view path)
{
RUNTIME_CHECK(file_props.dimensions() > 0);
RUNTIME_CHECK(file_props.dimensions() <= std::numeric_limits<UInt32>::max());
RUNTIME_CHECK(file_props.dimensions() <= TiDB::MAX_VECTOR_DIMENSION);

tipb::VectorIndexKind kind;
RUNTIME_CHECK(tipb::VectorIndexKind_Parse(file_props.index_kind(), &kind));
Expand All @@ -68,7 +69,7 @@ VectorIndexViewerPtr VectorIndexViewer::view(const dtpb::VectorIndexFileProps &
case tipb::VectorIndexKind::HNSW:
return VectorIndexHNSWViewer::view(file_props, path);
default:
throw Exception(ErrorCodes::INCORRECT_QUERY, "Unsupported vector index {}", file_props.index_kind());
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unsupported vector index {}", file_props.index_kind());
}
}

Expand Down
3 changes: 2 additions & 1 deletion dbms/src/TiDB/Schema/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <algorithm>
#include <cmath>
#include <magic_enum.hpp>
#include "TiDB/Schema/VectorIndex.h"

namespace DB
{
Expand Down Expand Up @@ -481,7 +482,7 @@ try

auto dimension = vector_index_json->getValue<UInt64>("dimension");
RUNTIME_CHECK(dimension > 0);
RUNTIME_CHECK(dimension <= 16383); // Just a protection
RUNTIME_CHECK(dimension <= TiDB::MAX_VECTOR_DIMENSION); // Just a protection

tipb::VectorDistanceMetric distance_metric = tipb::VectorDistanceMetric::INVALID_DISTANCE_METRIC;
auto distance_metric_field = vector_index_json->getValue<String>("distance_metric");
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/TiDB/Schema/VectorIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct VectorIndexDefinition
// ever try to modify it anyway.
using VectorIndexDefinitionPtr = std::shared_ptr<const VectorIndexDefinition>;

// Defined in TiDB pkg/types/vector.go
static constexpr Int64 MAX_VECTOR_DIMENSION = 16383;

} // namespace TiDB

template <>
Expand Down

0 comments on commit 6458415

Please sign in to comment.