@@ -1006,6 +1006,105 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
1006
1006
});
1007
1007
}
1008
1008
1009
+ Y_UNIT_TEST (VectorIndexDescriptionIsPersisted) {
1010
+ TTestBasicRuntime runtime;
1011
+ TTestEnv env (runtime);
1012
+ ui64 txId = 100 ;
1013
+
1014
+ TestCreateTable (runtime, ++txId, " /MyRoot" , R"(
1015
+ Name: "vectors"
1016
+ Columns { Name: "id" Type: "Uint64" }
1017
+ Columns { Name: "embedding" Type: "String" }
1018
+ Columns { Name: "covered" Type: "String" }
1019
+ KeyColumnNames: [ "id" ]
1020
+ )" );
1021
+ env.TestWaitNotification (runtime, txId);
1022
+
1023
+ const auto globalIndexSettings = []{
1024
+ Ydb::Table::GlobalIndexSettings globalIndexSettings;
1025
+ UNIT_ASSERT (google::protobuf::TextFormat::ParseFromString (R"(
1026
+ partition_at_keys {
1027
+ split_points {
1028
+ type { tuple_type { elements { optional_type { item { type_id: UINT32 } } } } }
1029
+ value { items { uint32_value: 12345 } }
1030
+ }
1031
+ split_points {
1032
+ type { tuple_type { elements { optional_type { item { type_id: UINT32 } } } } }
1033
+ value { items { uint32_value: 54321 } }
1034
+ }
1035
+ }
1036
+ partitioning_settings {
1037
+ min_partitions_count: 3
1038
+ max_partitions_count: 3
1039
+ }
1040
+ )" , &globalIndexSettings));
1041
+ return NYdb::NTable::TGlobalIndexSettings::FromProto (globalIndexSettings);
1042
+ }();
1043
+
1044
+ auto vectorIndexSettings = []{
1045
+ Ydb::Table::VectorIndexSettings vectorIndexSettings;
1046
+ UNIT_ASSERT (google::protobuf::TextFormat::ParseFromString (R"(
1047
+ distance: DISTANCE_COSINE,
1048
+ vector_type: VECTOR_TYPE_FLOAT,
1049
+ vector_dimension: 1024
1050
+ )" , &vectorIndexSettings));
1051
+ using T = NYdb::NTable::TVectorIndexSettings;
1052
+ return std::make_unique<T>(T::FromProto (vectorIndexSettings));
1053
+ }();
1054
+
1055
+ TBlockEvents<TEvSchemeShard::TEvModifySchemeTransaction> indexCreationBlocker (runtime, [](const auto & ev) {
1056
+ const auto & modifyScheme = ev->Get ()->Record .GetTransaction (0 );
1057
+ return modifyScheme.GetOperationType () == NKikimrSchemeOp::ESchemeOpCreateIndexBuild;
1058
+ });
1059
+
1060
+ const ui64 buildIndexTx = ++txId;
1061
+ TestBuildIndex (runtime, buildIndexTx, TTestTxConfig::SchemeShard, " /MyRoot" , " /MyRoot/vectors" , TBuildIndexConfig{
1062
+ " by_embedding" , NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree, { " embedding" }, { " covered" },
1063
+ { globalIndexSettings, globalIndexSettings }, std::move (vectorIndexSettings)
1064
+ });
1065
+
1066
+ RebootTablet (runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor ());
1067
+
1068
+ indexCreationBlocker.Stop ().Unblock ();
1069
+ env.TestWaitNotification (runtime, buildIndexTx);
1070
+
1071
+ auto buildIndexOperation = TestGetBuildIndex (runtime, TTestTxConfig::SchemeShard, " /MyRoot" , buildIndexTx);
1072
+ UNIT_ASSERT_VALUES_EQUAL_C (
1073
+ buildIndexOperation.GetIndexBuild ().GetState (), Ydb::Table::IndexBuildState::STATE_DONE,
1074
+ buildIndexOperation.DebugString ()
1075
+ );
1076
+
1077
+ TestDescribeResult (DescribePrivatePath (runtime, " /MyRoot/vectors/by_embedding" ), {
1078
+ NLs::PathExist,
1079
+ NLs::IndexState (NKikimrSchemeOp::EIndexStateReady),
1080
+ NLs::IndexType (NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree),
1081
+ NLs::IndexKeys ({" embedding" }),
1082
+ NLs::IndexDataColumns ({" covered" }),
1083
+ NLs::VectorIndexDescription (
1084
+ Ydb::Table::VectorIndexSettings::DISTANCE_COSINE,
1085
+ Ydb::Table::VectorIndexSettings::SIMILARITY_UNSPECIFIED,
1086
+ Ydb::Table::VectorIndexSettings::VECTOR_TYPE_FLOAT,
1087
+ 1024
1088
+ )
1089
+ });
1090
+
1091
+ using namespace NKikimr ::NTableIndex::NTableVectorKmeansTreeIndex;
1092
+ TestDescribeResult (DescribePrivatePath (runtime, JoinFsPaths (" /MyRoot/vectors/by_embedding" , LevelTable), true , true ), {
1093
+ NLs::IsTable,
1094
+ NLs::PartitionCount (3 ),
1095
+ NLs::MinPartitionsCountEqual (3 ),
1096
+ NLs::MaxPartitionsCountEqual (3 ),
1097
+ NLs::SplitBoundaries<ui32>({12345 , 54321 })
1098
+ });
1099
+ TestDescribeResult (DescribePrivatePath (runtime, JoinFsPaths (" /MyRoot/vectors/by_embedding" , PostingTable), true , true ), {
1100
+ NLs::IsTable,
1101
+ NLs::PartitionCount (3 ),
1102
+ NLs::MinPartitionsCountEqual (3 ),
1103
+ NLs::MaxPartitionsCountEqual (3 ),
1104
+ NLs::SplitBoundaries<ui32>({12345 , 54321 })
1105
+ });
1106
+ }
1107
+
1009
1108
Y_UNIT_TEST (DropIndex) {
1010
1109
TTestBasicRuntime runtime;
1011
1110
TTestEnv env (runtime);
0 commit comments