Change the serviceInterop call that was missed in the previous PR (#4550)

This commit is contained in:
neildsh 2024-06-14 15:04:05 -07:00 коммит произвёл GitHub
Родитель 20d678b60d
Коммит 2b01585990
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 180 добавлений и 15 удалений

Просмотреть файл

@ -270,13 +270,15 @@ namespace Microsoft.Azure.Cosmos.Query.Core.QueryPlan
fixed (byte* bytePtr2 = buffer)
{
errorCode = ServiceInteropWrapper.GetPartitionKeyRangesFromQuery3(
errorCode = ServiceInteropWrapper.GetPartitionKeyRangesFromQuery4(
this.serviceProvider,
querySpecJsonString,
partitionKeyRangesApiOptions,
allParts,
partsLengths,
(uint)partitionKeyDefinition.Paths.Count,
vectorEmbeddingPolicyString,
vectorEmbeddingPolicyString?.Length ?? 0,
new IntPtr(bytePtr2),
(uint)buffer.Length,
out serializedQueryExecutionInfoResultLength);

Просмотреть файл

@ -1,7 +1,7 @@
<Results>
<Result>
<Input>
<Description>Euclidean Distance</Description>
<Description>Euclidean Distance with query parameter</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, @vectorEmbedding, true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)</Query>
@ -59,7 +59,7 @@ ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)]]></RewrittenQuery>
</Result>
<Result>
<Input>
<Description>Cosine Similarity</Description>
<Description>Cosine Similarity with query parameter</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, @vectorEmbedding, true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)</Query>
@ -117,7 +117,7 @@ ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)]]></RewrittenQuery>
</Result>
<Result>
<Input>
<Description>Dot Product</Description>
<Description>Dot Product with query parameter</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, @vectorEmbedding, true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)</Query>
@ -173,4 +173,133 @@ ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)]]></RewrittenQuery>
</PartitionedQueryExecutionInfoInternal>
</Output>
</Result>
<Result>
<Input>
<Description>Euclidean Distance with inline vector</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true)</Query>
<PartitionKeys>
<Key>/PartitionKey</Key>
</PartitionKeys>
<PartitionKeyType>Hash</PartitionKeyType>
<GeospatialType>Geography</GeospatialType>
</Input>
<Output>
<PartitionedQueryExecutionInfoInternal>
<QueryInfo>
<DistinctType>None</DistinctType>
<Top>10</Top>
<Offset />
<Limit />
<GroupByExpressions />
<OrderBy>
<SortOrder>Ascending</SortOrder>
</OrderBy>
<OrderByExpressions>
<OrderByExpression>VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)</OrderByExpression>
</OrderByExpressions>
<Aggregates />
<GroupByAliasToAggregateType />
<GroupByAliases />
<HasSelectValue>False</HasSelectValue>
</QueryInfo>
<QueryRanges>
<Range>
<Range>[[],"Infinity")</Range>
</Range>
</QueryRanges>
<RewrittenQuery><![CDATA[SELECT TOP 10 c._rid, [{"item": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)}] AS orderByItems, {"Title": c.title, "SimilarityScore": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)} AS payload
FROM c
WHERE ({documentdb-formattableorderbyquery-filter})
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)]]></RewrittenQuery>
</PartitionedQueryExecutionInfoInternal>
</Output>
</Result>
<Result>
<Input>
<Description>Cosine Similarity with inline vector</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true)</Query>
<PartitionKeys>
<Key>/PartitionKey</Key>
</PartitionKeys>
<PartitionKeyType>Hash</PartitionKeyType>
<GeospatialType>Geography</GeospatialType>
</Input>
<Output>
<PartitionedQueryExecutionInfoInternal>
<QueryInfo>
<DistinctType>None</DistinctType>
<Top>10</Top>
<Offset />
<Limit />
<GroupByExpressions />
<OrderBy>
<SortOrder>Descending</SortOrder>
</OrderBy>
<OrderByExpressions>
<OrderByExpression>VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)</OrderByExpression>
</OrderByExpressions>
<Aggregates />
<GroupByAliasToAggregateType />
<GroupByAliases />
<HasSelectValue>False</HasSelectValue>
</QueryInfo>
<QueryRanges>
<Range>
<Range>[[],"Infinity")</Range>
</Range>
</QueryRanges>
<RewrittenQuery><![CDATA[SELECT TOP 10 c._rid, [{"item": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)}] AS orderByItems, {"Title": c.title, "SimilarityScore": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)} AS payload
FROM c
WHERE ({documentdb-formattableorderbyquery-filter})
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)]]></RewrittenQuery>
</PartitionedQueryExecutionInfoInternal>
</Output>
</Result>
<Result>
<Input>
<Description>Dot Product with inline vector</Description>
<Query>SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true)</Query>
<PartitionKeys>
<Key>/PartitionKey</Key>
</PartitionKeys>
<PartitionKeyType>Hash</PartitionKeyType>
<GeospatialType>Geography</GeospatialType>
</Input>
<Output>
<PartitionedQueryExecutionInfoInternal>
<QueryInfo>
<DistinctType>None</DistinctType>
<Top>10</Top>
<Offset />
<Limit />
<GroupByExpressions />
<OrderBy>
<SortOrder>Descending</SortOrder>
</OrderBy>
<OrderByExpressions>
<OrderByExpression>VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)</OrderByExpression>
</OrderByExpressions>
<Aggregates />
<GroupByAliasToAggregateType />
<GroupByAliases />
<HasSelectValue>False</HasSelectValue>
</QueryInfo>
<QueryRanges>
<Range>
<Range>[[],"Infinity")</Range>
</Range>
</QueryRanges>
<RewrittenQuery><![CDATA[SELECT TOP 10 c._rid, [{"item": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)}] AS orderByItems, {"Title": c.title, "SimilarityScore": VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)} AS payload
FROM c
WHERE ({documentdb-formattableorderbyquery-filter})
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true)]]></RewrittenQuery>
</PartitionedQueryExecutionInfoInternal>
</Output>
</Result>
</Results>

Просмотреть файл

@ -1357,28 +1357,62 @@
{
List<QueryPlanBaselineTestInput> testCases = new List<QueryPlanBaselineTestInput>
{
MakeVectorTest("Euclidean Distance", Cosmos.DistanceFunction.Euclidean),
MakeVectorTest("Cosine Similarity", Cosmos.DistanceFunction.Cosine),
MakeVectorTest("Dot Product", Cosmos.DistanceFunction.DotProduct),
MakeVectorTest("Euclidean Distance with query parameter", Cosmos.DistanceFunction.Euclidean),
MakeVectorTest("Cosine Similarity with query parameter", Cosmos.DistanceFunction.Cosine),
MakeVectorTest("Dot Product with query parameter", Cosmos.DistanceFunction.DotProduct),
MakeInlineVectorQueryTest("Euclidean Distance with inline vector", Cosmos.DistanceFunction.Euclidean),
MakeInlineVectorQueryTest("Cosine Similarity with inline vector", Cosmos.DistanceFunction.Cosine),
MakeInlineVectorQueryTest("Dot Product with inline vector", Cosmos.DistanceFunction.DotProduct),
};
this.ExecuteTestSuite(testCases);
}
private static QueryPlanBaselineTestInput MakeInlineVectorQueryTest(string description, Cosmos.DistanceFunction distanceFunction)
{
PartitionKeyDefinition partitionKeyDefinition = CreateHashPartitionKey("/PartitionKey");
Cosmos.VectorEmbeddingPolicy vectorEmbeddingPolicy = new Cosmos.VectorEmbeddingPolicy(new Collection<Cosmos.Embedding>
{
new Cosmos.Embedding
{
Path = "/embedding",
DataType = Cosmos.VectorDataType.Float32,
Dimensions = 8,
DistanceFunction = distanceFunction
}
});
string queryText = @"SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true) AS SimilarityScore
FROM c
ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.005676387343555689, -0.013547309674322605, -0.002445543883368373, 0.01579204574227333, -0.016796082258224487, -0.012471556663513184], true)";
SqlQuerySpec sqlQuerySpec = new SqlQuerySpec(queryText);
QueryPlanBaselineTestInput testInput = new QueryPlanBaselineTestInput(
description,
partitionKeyDefinition,
vectorEmbeddingPolicy,
sqlQuerySpec,
Cosmos.GeospatialType.Geography);
return testInput;
}
private static QueryPlanBaselineTestInput MakeVectorTest(string description, Cosmos.DistanceFunction distanceFunction)
{
PartitionKeyDefinition partitionKeyDefinition = CreateHashPartitionKey("/PartitionKey");
Cosmos.VectorEmbeddingPolicy vectorEmbeddingPolicy = new Cosmos.VectorEmbeddingPolicy(new Collection<Cosmos.Embedding>
{
new Cosmos.Embedding
{
new Cosmos.Embedding
{
Path = "/embedding",
DataType = Cosmos.VectorDataType.Float32,
Dimensions = 8,
DistanceFunction = distanceFunction
}
});
Path = "/embedding",
DataType = Cosmos.VectorDataType.Float32,
Dimensions = 8,
DistanceFunction = distanceFunction
}
});
string queryText = @"SELECT TOP 10 c.title AS Title, VectorDistance(c.embedding, @vectorEmbedding, true) AS SimilarityScore
FROM c