@@ -5840,6 +5840,7 @@ Y_UNIT_TEST_SUITE(DataShardReadIteratorVectorTopK) {
58405840 Y_UNIT_TEST (BadRequest) {
58415841 TTestHelper helper;
58425842 TVector<TShardedTableOptions::TColumn> columns = {
5843+ {" parent" , " Uint32" , true , false },
58435844 {" key" , " Uint32" , true , false },
58445845 {" emb" , " String" , false , false }};
58455846 helper.CreateCustomTable (" table-vector" , columns);
@@ -5848,9 +5849,10 @@ Y_UNIT_TEST_SUITE(DataShardReadIteratorVectorTopK) {
58485849 auto request1 = helper.GetBaseReadRequest (" table-vector" , 1 , NKikimrDataEvents::FORMAT_CELLVEC);
58495850 AddRangeQuery<ui32>(*request1, { 1 }, true , { 20 }, true );
58505851 auto topK = request1->Record .MutableVectorTopK ();
5851- topK->SetColumn (1 );
5852+ topK->SetColumn (2 );
58525853 topK->SetTargetVector (" \xE4\x16\x02 " );
58535854 topK->SetLimit (3 );
5855+ topK->AddDistinctColumns (1 );
58545856 auto idx = topK->MutableSettings ();
58555857 idx->set_metric (Ydb::Table::VectorIndexSettings::DISTANCE_COSINE);
58565858 idx->set_vector_type (Ydb::Table::VectorIndexSettings::VECTOR_TYPE_UINT8);
@@ -5866,7 +5868,7 @@ Y_UNIT_TEST_SUITE(DataShardReadIteratorVectorTopK) {
58665868 UNIT_ASSERT (readResult1->Record .GetStatus ().GetIssues (0 ).message ().Contains (" limit is 0" ));
58675869
58685870 request1 = createRequest ();
5869- request1->Record .MutableVectorTopK ()->SetColumn (2 );
5871+ request1->Record .MutableVectorTopK ()->SetColumn (3 );
58705872 readResult1 = helper.SendRead (" table-vector" , request1.release ());
58715873 UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().GetCode (), Ydb::StatusIds::BAD_REQUEST);
58725874 UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().IssuesSize (), 1 );
@@ -5892,57 +5894,68 @@ Y_UNIT_TEST_SUITE(DataShardReadIteratorVectorTopK) {
58925894 UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().GetCode (), Ydb::StatusIds::BAD_REQUEST);
58935895 UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().IssuesSize (), 1 );
58945896 UNIT_ASSERT (readResult1->Record .GetStatus ().GetIssues (0 ).message ().Contains (" either distance or similarity" ));
5897+
5898+ request1 = createRequest ();
5899+ request1->Record .MutableVectorTopK ()->AddDistinctColumns (3 );
5900+ readResult1 = helper.SendRead (" table-vector" , request1.release ());
5901+ UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().GetCode (), Ydb::StatusIds::BAD_REQUEST);
5902+ UNIT_ASSERT_VALUES_EQUAL (readResult1->Record .GetStatus ().IssuesSize (), 1 );
5903+ UNIT_ASSERT (readResult1->Record .GetStatus ().GetIssues (0 ).message ().Contains (" Too large unique column index" ));
58955904 }
58965905
58975906 Y_UNIT_TEST_TWIN (Simple, Batch) {
58985907 TTestHelper helper;
58995908 TVector<TShardedTableOptions::TColumn> columns = {
5909+ {" parent" , " Uint32" , true , false },
59005910 {" key" , " Uint32" , true , false },
59015911 {" emb" , " String" , false , false }};
59025912 helper.CreateCustomTable (" table-vector" , columns);
59035913
59045914 // Insert initial data
5905- ExecSQL (helper.Server , helper.Sender , R"( UPSERT INTO `/Root/table-vector` (key, emb) VALUES
5906- ( 1, "\x00\xFF\x02"),
5907- ( 2, "\x10\xF0\x02"),
5908- ( 3, "\x20\xE0\x02"),
5909- ( 4, "\x30\xD0\x02"),
5910- ( 5, "\x40\xC0\x02"),
5911- ( 6, "\x50\xB0\x02"),
5912- ( 7, "\x60\xA0\x02"),
5913- ( 8, "\x70\x90\x02"),
5914- ( 9, "\x80\x80\x02"),
5915- (10, "\x90\x70\x02"),
5916- (11, "\xA0\x60\x02"),
5917- (12, "\xB0\x50\x02"),
5918- (13, "\xC0\x40\x02"),
5919- (14, "\xD0\x30\x02"),
5920- (15, "\xE0\x20\x02"),
5921- (16, "\xF0\x10\x02"),
5922- (17, "\xFF\x00\x02");)" );
5915+ ExecSQL (helper.Server , helper.Sender , R"( UPSERT INTO `/Root/table-vector` (parent, key, emb) VALUES
5916+ (1, 1, "\x00\xFF\x02"),
5917+ (1, 2, "\x10\xF0\x02"),
5918+ (1, 3, "\x20\xE0\x02"),
5919+ (1, 4, "\x30\xD0\x02"),
5920+ (1, 5, "\x40\xC0\x02"),
5921+ (1, 6, "\x50\xB0\x02"),
5922+ (1, 7, "\x60\xA0\x02"),
5923+ (1, 8, "\x70\x90\x02"),
5924+ (1, 9, "\x80\x80\x02"),
5925+ (1, 10, "\x90\x70\x02"),
5926+ (1, 11, "\xA0\x60\x02"),
5927+ (1, 12, "\xB0\x50\x02"),
5928+ (1, 13, "\xC0\x40\x02"),
5929+ (1, 14, "\xD0\x30\x02"),
5930+ (1, 15, "\xE0\x20\x02"),
5931+ (1, 16, "\xF0\x10\x02"),
5932+ (2, 16, "\xF0\x10\x02"),
5933+ (1, 17, "\xFF\x00\x02");)" );
59235934
59245935 auto request1 = helper.GetBaseReadRequest (" table-vector" , 1 , NKikimrDataEvents::FORMAT_CELLVEC);
59255936 if (Batch) {
59265937 request1->Record .SetHints (TEvDataShard::TEvRead::HINT_BATCH);
59275938 }
5928- AddRangeQuery<ui32>(*request1, { 1 }, true , { 20 }, true );
5939+ AddRangeQuery<ui32>(*request1, { 1 , 1 }, true , { 2 , 20 }, true );
59295940 auto topK = request1->Record .MutableVectorTopK ();
5930- topK->SetColumn (1 );
5941+ topK->SetColumn (2 );
59315942 topK->SetTargetVector (" \xE4\x16\x02 " );
59325943 topK->SetLimit (3 );
5944+ topK->AddDistinctColumns (1 );
59335945 auto idx = topK->MutableSettings ();
59345946 idx->set_metric (Ydb::Table::VectorIndexSettings::DISTANCE_COSINE);
59355947 idx->set_vector_type (Ydb::Table::VectorIndexSettings::VECTOR_TYPE_UINT8);
59365948 idx->set_vector_dimension (2 );
59375949 auto readResult1 = helper.SendRead (" table-vector" , request1.release ());
59385950 UNIT_ASSERT (readResult1->Record .GetFinished ());
5939- UNIT_ASSERT (readResult1->Record .GetStats ().GetRows () == 17 );
5940- UNIT_ASSERT (readResult1->Record .GetStats ().GetBytes () == 544 );
5951+ UNIT_ASSERT_C (readResult1->Record .GetStats ().GetRows () == 18 , TStringBuilder () << " Rows: " << readResult1-> Record . GetStats (). GetRows () );
5952+ UNIT_ASSERT_C (readResult1->Record .GetStats ().GetBytes () == 864 , TStringBuilder () << " Bytes: " << readResult1-> Record . GetStats (). GetBytes () );
59415953 CheckResult (helper.Tables .at (" table-vector" ).UserTable , *readResult1, {
5942- {TCell::Make (16 ), TCell (" \xF0\x10\x02 " , 3 )},
5943- {TCell::Make (15 ), TCell (" \xE0\x20\x02 " , 3 )},
5944- {TCell::Make (17 ), TCell (" \xFF\x00\x02 " , 3 )},
5954+ {TCell::Make (1 ), TCell::Make ( 16 ), TCell (" \xF0\x10\x02 " , 3 )},
5955+ {TCell::Make (1 ), TCell::Make ( 15 ), TCell (" \xE0\x20\x02 " , 3 )},
5956+ {TCell::Make (1 ), TCell::Make ( 17 ), TCell (" \xFF\x00\x02 " , 3 )},
59455957 }, {
5958+ NScheme::TTypeInfo (NScheme::NTypeIds::Uint32),
59465959 NScheme::TTypeInfo(NScheme::NTypeIds::Uint32),
59475960 NScheme::TTypeInfo(NScheme::NTypeIds::String)
59485961 });
0 commit comments