Skip to content

Commit 20e563f

Browse files
committed
Add more unit tests for weighted RRF with skip order by rewrite
1 parent d163287 commit 20e563f

1 file changed

Lines changed: 41 additions & 34 deletions

File tree

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/NonStreamingOrderByQueryTests.cs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -477,32 +477,31 @@ public async Task HybridSearchSkipOrderByRewriteWeightedRRFTests()
477477
weights: new double[] { 1.25, 2.0 },
478478
pageSize: 10,
479479
returnEmptyGlobalStatistics: true),
480-
481-
//MakeHybridSearchSkipOrderByRewriteTest(
482-
// leafPageCount: 4,
483-
// backendPageSize: 10,
484-
// requiresGlobalStatistics: false,
485-
// skip: null,
486-
// take: 100,
487-
// weights: new double[] { -1.0, -1.0 },
488-
// pageSize: 1000),
489-
//MakeHybridSearchSkipOrderByRewriteTest(
490-
// leafPageCount: 4,
491-
// backendPageSize: 100,
492-
// requiresGlobalStatistics: true,
493-
// skip: 7,
494-
// take: 10,
495-
// weights: new double[] { -1.33, -0.45 },
496-
// pageSize: 1),
497-
//MakeHybridSearchSkipOrderByRewriteTest(
498-
// leafPageCount: 0,
499-
// backendPageSize: 10,
500-
// requiresGlobalStatistics: true,
501-
// skip: 0,
502-
// take: 10,
503-
// weights: new double[] { -1.25, -2.0 },
504-
// pageSize: 10,
505-
// returnEmptyGlobalStatistics: true),
480+
MakeHybridSearchSkipOrderByRewriteTest(
481+
leafPageCount: 4,
482+
backendPageSize: 10,
483+
requiresGlobalStatistics: false,
484+
skip: null,
485+
take: 100,
486+
weights: new double[] { -1.0, -1.0 },
487+
pageSize: 1000),
488+
MakeHybridSearchSkipOrderByRewriteTest(
489+
leafPageCount: 4,
490+
backendPageSize: 100,
491+
requiresGlobalStatistics: true,
492+
skip: 7,
493+
take: 10,
494+
weights: new double[] { -1.33, -0.45 },
495+
pageSize: 1),
496+
MakeHybridSearchSkipOrderByRewriteTest(
497+
leafPageCount: 0,
498+
backendPageSize: 10,
499+
requiresGlobalStatistics: true,
500+
skip: 0,
501+
take: 10,
502+
weights: new double[] { -1.25, -2.0 },
503+
pageSize: 10,
504+
returnEmptyGlobalStatistics: true),
506505
};
507506

508507
foreach (HybridSearchTest testCase in testCases)
@@ -544,11 +543,11 @@ private static async Task RunHybridSearchTest(HybridSearchTest testCase)
544543
{
545544
expectedIndices = expectedIndices.Reverse();
546545

547-
feedModes = new PartitionedFeedMode[]
548-
{
549-
PartitionedFeedMode.NonStreaming,
550-
PartitionedFeedMode.NonStreaming,
551-
};
546+
PartitionedFeedMode feedMode = testCase.SkipOrderByRewrite?
547+
PartitionedFeedMode.NonStreamingReversed | PartitionedFeedMode.NegateScores:
548+
PartitionedFeedMode.NonStreaming;
549+
550+
feedModes = new PartitionedFeedMode[] { feedMode, feedMode };
552551
}
553552
}
554553

@@ -1586,6 +1585,8 @@ enum PartitionedFeedMode
15861585
NonStreaming = 1,
15871586
Reversed = 2,
15881587

1588+
NegateScores = 4,
1589+
15891590
StreamingReversed = Streaming | Reversed,
15901591
NonStreamingReversed = NonStreaming | Reversed,
15911592
}
@@ -1654,7 +1655,12 @@ private static IReadOnlyList<IReadOnlyDictionary<FeedRange, IReadOnlyList<IReadO
16541655
pageSize,
16551656
feedModes[componentIndex],
16561657
componentIndex,
1657-
(componentIndex, index) => CreateHybridSearchDocument(componentCount: componentCount, index:index, componentIndex: componentIndex, skipOrderByRewrite));
1658+
(componentIndex, index) => CreateHybridSearchDocument(
1659+
componentCount: componentCount,
1660+
index: index,
1661+
componentIndex: componentIndex,
1662+
skipOrderByRewrite: skipOrderByRewrite,
1663+
negateScores: feedModes[componentIndex].HasFlag(PartitionedFeedMode.NegateScores)));
16581664

16591665
componentPages.Add(pages);
16601666
}
@@ -1784,15 +1790,16 @@ private static CosmosElement CreateHybridSearchGlobalStatistics()
17841790
return globalStatistics;
17851791
}
17861792

1787-
private static CosmosElement CreateHybridSearchDocument(int componentCount, int index, int componentIndex, bool skipOrderByRewrite)
1793+
private static CosmosElement CreateHybridSearchDocument(int componentCount, int index, int componentIndex, bool skipOrderByRewrite, bool negateScores)
17881794
{
17891795
CosmosElement indexElement = CosmosNumber64.Create(index);
17901796
CosmosElement indexStringElement = CosmosString.Create(index.ToString("D4"));
17911797
double[] scores = new double[componentCount];
17921798
double delta = 0.1;
1799+
double factor = negateScores ? -1.0 : 1.0;
17931800
for (int scoreIndex = 0; scoreIndex < componentCount; ++scoreIndex)
17941801
{
1795-
scores[scoreIndex] = index + ((1 + scoreIndex) * delta);
1802+
scores[scoreIndex] = factor * (index + ((1 + scoreIndex) * delta));
17961803
}
17971804

17981805
List<CosmosElement> orderByItems = new List<CosmosElement>

0 commit comments

Comments
 (0)