Skip to content

Prefix vector impl table has its own settings #18132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,9 @@ namespace NSchemeShardUT_Private {
if (cfg.GlobalIndexSettings.size() > 1) {
cfg.GlobalIndexSettings[1].SerializeTo(*settings.mutable_posting_table_settings());
}
if (cfg.GlobalIndexSettings.size() > 2) {
cfg.GlobalIndexSettings[2].SerializeTo(*settings.mutable_prefix_table_settings());
}
}
} break;
default:
Expand Down
40 changes: 32 additions & 8 deletions ydb/core/tx/schemeshard/ut_index/ut_vector_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using namespace NKikimr;
using namespace NSchemeShard;
using namespace NSchemeShardUT_Private;
using namespace NKikimr::NTableIndex;
using namespace NKikimr::NTableIndex::NTableVectorKmeansTreeIndex;

Y_UNIT_TEST_SUITE(TVectorIndexTests) {
Expand Down Expand Up @@ -241,7 +242,7 @@ Y_UNIT_TEST_SUITE(TVectorIndexTests) {
NLs::CheckColumns(PostingTable, {ParentColumn, "id1", "id2", "covered1", "covered2"}, {}, {ParentColumn, "id1", "id2"}, true) });
}

Y_UNIT_TEST(VectorKmeansTreePostingImplTable) {
Y_UNIT_TEST(VectorKmeansTreeImplTable) {
// partition
NKikimrSchemeOp::TPartitionConfig baseTablePartitionConfig;
NKikimrSchemeOp::TTableDescription indexTableDesc;
Expand All @@ -258,15 +259,38 @@ Y_UNIT_TEST_SUITE(TVectorIndexTests) {
{
auto* data2 = baseTableDescr.AddColumns();
*data2->MutableName() = "data2";
}
{
auto* prefix = baseTableDescr.AddColumns();
*prefix->MutableName() = "prefix";
}

{
auto desc = CalcVectorKmeansTreeLevelImplTableDesc(baseTablePartitionConfig, indexTableDesc);
std::string_view expected[] = {ParentColumn, IdColumn, CentroidColumn};
for (size_t i = 0; auto& column : desc.GetColumns()) {
UNIT_ASSERT_STRINGS_EQUAL(column.GetName(), expected[i]);
++i;
}
}
NTableIndex::TTableColumns implTableColumns = {{"data2", "data1"}, {}};
auto desc = CalcVectorKmeansTreePostingImplTableDesc({}, baseTableDescr, baseTablePartitionConfig, implTableColumns, indexTableDesc, "something");
std::string_view expected[] = {NTableIndex::NTableVectorKmeansTreeIndex::ParentColumn, "data1", "data2"};
for (size_t i = 0; auto& column : desc.GetColumns()) {
UNIT_ASSERT_STRINGS_EQUAL(column.GetName(), expected[i]);
++i;
{
NTableIndex::TTableColumns implTableColumns = {{"data2", "data1"}, {}};
auto desc = CalcVectorKmeansTreePostingImplTableDesc({}, baseTableDescr, baseTablePartitionConfig, implTableColumns, indexTableDesc, "something");
std::string_view expected[] = {ParentColumn, "data1", "data2"};
for (size_t i = 0; auto& column : desc.GetColumns()) {
UNIT_ASSERT_STRINGS_EQUAL(column.GetName(), expected[i]);
++i;
}
}
{
NTableIndex::TTableColumns implTableColumns = {{"prefix"}, {}};
auto desc = CalcVectorKmeansTreePrefixImplTableDesc({}, baseTableDescr, baseTablePartitionConfig, implTableColumns, indexTableDesc);
std::string_view expected[] = {IdColumn};
for (size_t i = 0; auto& column : desc.GetColumns()) {
UNIT_ASSERT_STRINGS_EQUAL(column.GetName(), expected[i]);
++i;
}
}
}

Y_UNIT_TEST(CreateTableWithError) {
Expand All @@ -288,7 +312,7 @@ Y_UNIT_TEST_SUITE(TVectorIndexTests) {
Type: EIndexTypeGlobalVectorKmeansTree
VectorIndexKmeansTreeDescription: { Settings: { settings: { metric: DISTANCE_COSINE, vector_type: VECTOR_TYPE_FLOAT, vector_dimension: 1024 } } }
}
)", NTableIndex::NTableVectorKmeansTreeIndex::ParentColumn, NTableIndex::NTableVectorKmeansTreeIndex::ParentColumn), {NKikimrScheme::StatusInvalidParameter});
)", ParentColumn, ParentColumn), {NKikimrScheme::StatusInvalidParameter});

// pk should not be covered
TestCreateIndexedTable(runtime, ++txId, "/MyRoot", R"(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
UNIT_ASSERT_VALUES_EQUAL(billRecords.size(), 0);
}

Y_UNIT_TEST(VectorIndexDescriptionIsPersisted) {
Y_UNIT_TEST_FLAG(VectorIndexDescriptionIsPersisted, prefixed) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
ui64 txId = 100;
Expand All @@ -239,6 +239,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
Name: "vectors"
Columns { Name: "id" Type: "Uint64" }
Columns { Name: "embedding" Type: "String" }
Columns { Name: "prefix" Type: "Uint64" }
Columns { Name: "covered" Type: "String" }
KeyColumnNames: [ "id" ]
)");
Expand Down Expand Up @@ -288,9 +289,13 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
});

const ui64 buildIndexTx = ++txId;
const TVector<TString> indexColumns = prefixed
? TVector<TString>{"prefix", "embedding"}
: TVector<TString>{"embedding"};
const TVector<TString> dataColumns = { "covered" };
TestBuildIndex(runtime, buildIndexTx, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", TBuildIndexConfig{
"by_embedding", NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree, { "embedding" }, { "covered" },
{ globalIndexSettings, globalIndexSettings }, std::move(kmeansTreeSettings)
"by_embedding", NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree, indexColumns, dataColumns,
{ globalIndexSettings, globalIndexSettings, globalIndexSettings }, std::move(kmeansTreeSettings)
});

RebootTablet(runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor());
Expand Down Expand Up @@ -319,6 +324,15 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
NLs::MaxPartitionsCountEqual(3),
NLs::SplitBoundaries<ui64>({12345, 54321})
});
if (prefixed) {
TestDescribeResult(DescribePrivatePath(runtime, JoinFsPaths("/MyRoot/vectors/by_embedding", PrefixTable), true, true), {
NLs::IsTable,
NLs::PartitionCount(3),
NLs::MinPartitionsCountEqual(3),
NLs::MaxPartitionsCountEqual(3),
NLs::SplitBoundaries<ui64>({12345, 54321})
});
}

for (size_t i = 0; i != 3; ++i) {
if (i != 0) {
Expand All @@ -329,8 +343,8 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
NLs::PathExist,
NLs::IndexState(NKikimrSchemeOp::EIndexStateReady),
NLs::IndexType(NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree),
NLs::IndexKeys({"embedding"}),
NLs::IndexDataColumns({"covered"}),
NLs::IndexKeys(indexColumns),
NLs::IndexDataColumns(dataColumns),
NLs::KMeansTreeDescription(
Ydb::Table::VectorIndexSettings::DISTANCE_COSINE,
Ydb::Table::VectorIndexSettings::VECTOR_TYPE_FLOAT,
Expand Down
10 changes: 9 additions & 1 deletion ydb/core/ydb_convert/table_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ void FillIndexDescriptionImpl(TYdbProto& out, const NKikimrSchemeOp::TTableDescr
tableIndex.GetIndexImplTableDescriptions(0)
);
break;
case NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree:
case NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree: {
case NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree:

FillGlobalIndexSettings(
*index->mutable_global_vector_kmeans_tree_index()->mutable_level_table_settings(),
tableIndex.GetIndexImplTableDescriptions(0)
Expand All @@ -1064,10 +1064,18 @@ void FillIndexDescriptionImpl(TYdbProto& out, const NKikimrSchemeOp::TTableDescr
*index->mutable_global_vector_kmeans_tree_index()->mutable_posting_table_settings(),
tableIndex.GetIndexImplTableDescriptions(1)
);
const bool prefixVectorIndex = tableIndex.GetKeyColumnNames().size() > 1;
if (prefixVectorIndex) {
FillGlobalIndexSettings(
*index->mutable_global_vector_kmeans_tree_index()->mutable_prefix_table_settings(),
tableIndex.GetIndexImplTableDescriptions(2)
);
}
Comment on lines +1067 to +1073
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bool prefixVectorIndex = tableIndex.GetKeyColumnNames().size() > 1;
if (prefixVectorIndex) {
FillGlobalIndexSettings(
*index->mutable_global_vector_kmeans_tree_index()->mutable_prefix_table_settings(),
tableIndex.GetIndexImplTableDescriptions(2)
);
}
if (tableIndex.GetKeyColumnNames().size() > 1) { // prefixVectorIndex
FillGlobalIndexSettings(
*index->mutable_global_vector_kmeans_tree_index()->mutable_prefix_table_settings(),
tableIndex.GetIndexImplTableDescriptions(2)
);
}


*index->mutable_global_vector_kmeans_tree_index()->mutable_vector_settings() = tableIndex.GetVectorIndexKmeansTreeDescription().GetSettings();

break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}

default:
break;
};
Expand Down
10 changes: 8 additions & 2 deletions ydb/core/ydb_convert/table_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,21 @@ bool FillIndexTablePartitioning(
}
break;

case Ydb::Table::TableIndex::kGlobalVectorKmeansTreeIndex:
case Ydb::Table::TableIndex::kGlobalVectorKmeansTreeIndex: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case Ydb::Table::TableIndex::kGlobalVectorKmeansTreeIndex: {
case Ydb::Table::TableIndex::kGlobalVectorKmeansTreeIndex:

if (!fillIndexPartitioning(index.global_vector_kmeans_tree_index().level_table_settings(), indexImplTableDescriptions)) {
return false;
}
if (!fillIndexPartitioning(index.global_vector_kmeans_tree_index().posting_table_settings(), indexImplTableDescriptions)) {
return false;
}
const bool prefixVectorIndex = index.index_columns().size() > 1;
if (prefixVectorIndex) {
if (!fillIndexPartitioning(index.global_vector_kmeans_tree_index().prefix_table_settings(), indexImplTableDescriptions)) {
return false;
}
}
Comment on lines +471 to +476
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bool prefixVectorIndex = index.index_columns().size() > 1;
if (prefixVectorIndex) {
if (!fillIndexPartitioning(index.global_vector_kmeans_tree_index().prefix_table_settings(), indexImplTableDescriptions)) {
return false;
}
}
if (index.index_columns().size() > 1) { // prefix vector index
if (!fillIndexPartitioning(index.global_vector_kmeans_tree_index().prefix_table_settings(), indexImplTableDescriptions)) {
return false;
}
}

break;

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}

case Ydb::Table::TableIndex::TYPE_NOT_SET:
break;
}
Expand Down
1 change: 1 addition & 0 deletions ydb/public/api/protos/ydb_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ message GlobalUniqueIndex {
message GlobalVectorKMeansTreeIndex {
GlobalIndexSettings level_table_settings = 1;
GlobalIndexSettings posting_table_settings = 2;
GlobalIndexSettings prefix_table_settings = 4;
KMeansTreeSettings vector_settings = 3;
}

Expand Down
4 changes: 4 additions & 0 deletions ydb/public/sdk/cpp/client/ydb_table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,10 @@ TIndexDescription TIndexDescription::FromProto(const TProto& proto) {
const auto &vectorProto = proto.global_vector_kmeans_tree_index();
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.level_table_settings()));
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.posting_table_settings()));
const bool prefixVectorIndex = indexColumns.size() > 1;
if (prefixVectorIndex) {
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.prefix_table_settings()));
}
specializedIndexSettings = TKMeansTreeSettings::FromProto(vectorProto.vector_settings());
break;
}
Expand Down
4 changes: 4 additions & 0 deletions ydb/public/sdk/cpp/src/client/table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,10 @@ TIndexDescription TIndexDescription::FromProto(const TProto& proto) {
const auto &vectorProto = proto.global_vector_kmeans_tree_index();
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.level_table_settings()));
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.posting_table_settings()));
const bool prefixVectorIndex = indexColumns.size() > 1;
if (prefixVectorIndex) {
globalIndexSettings.emplace_back(TGlobalIndexSettings::FromProto(vectorProto.prefix_table_settings()));
}
specializedIndexSettings = TKMeansTreeSettings::FromProto(vectorProto.vector_settings());
break;
}
Expand Down
Loading