|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Diagnostics.CodeAnalysis; |
| 5 | + |
4 | 6 | namespace Microsoft.EntityFrameworkCore.Cosmos.Extensions;
|
5 | 7 |
|
6 | 8 | /// <summary>
|
@@ -47,4 +49,145 @@ public static T CoalesceUndefined<T>(
|
47 | 49 | T expression1,
|
48 | 50 | T expression2)
|
49 | 51 | => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(CoalesceUndefined)));
|
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Returns the distance between two vectors, using the distance function and data type defined using |
| 55 | + /// <see cref="CosmosPropertyBuilderExtensions.IsVector(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder,Microsoft.Azure.Cosmos.DistanceFunction,int)"/>. |
| 56 | + /// </summary> |
| 57 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 58 | + /// <param name="vector1">The first vector.</param> |
| 59 | + /// <param name="vector2">The second vector.</param> |
| 60 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 61 | + public static double VectorDistance(this DbFunctions _, ReadOnlyMemory<byte> vector1, ReadOnlyMemory<byte> vector2) |
| 62 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 66 | + /// </summary> |
| 67 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 68 | + /// <param name="vector1">The first vector.</param> |
| 69 | + /// <param name="vector2">The second vector.</param> |
| 70 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 71 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 72 | + /// property is leveraged.</param> |
| 73 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 74 | + public static double VectorDistance( |
| 75 | + this DbFunctions _, |
| 76 | + ReadOnlyMemory<byte> vector1, |
| 77 | + ReadOnlyMemory<byte> vector2, |
| 78 | + [NotParameterized] bool useBruteForce) |
| 79 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 83 | + /// </summary> |
| 84 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 85 | + /// <param name="vector1">The first vector.</param> |
| 86 | + /// <param name="vector2">The second vector.</param> |
| 87 | + /// <param name="distanceFunction">The distance function to use.</param> |
| 88 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 89 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 90 | + /// property is leveraged.</param> |
| 91 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 92 | + public static double VectorDistance( |
| 93 | + this DbFunctions _, |
| 94 | + ReadOnlyMemory<byte> vector1, |
| 95 | + ReadOnlyMemory<byte> vector2, |
| 96 | + [NotParameterized] bool useBruteForce, |
| 97 | + [NotParameterized] DistanceFunction distanceFunction) |
| 98 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Returns the distance between two vectors, using the distance function and data type defined using |
| 102 | + /// <see cref="CosmosPropertyBuilderExtensions.IsVector(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder,Microsoft.Azure.Cosmos.DistanceFunction,int)"/>. |
| 103 | + /// </summary> |
| 104 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 105 | + /// <param name="vector1">The first vector.</param> |
| 106 | + /// <param name="vector2">The second vector.</param> |
| 107 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 108 | + public static double VectorDistance(this DbFunctions _, ReadOnlyMemory<sbyte> vector1, ReadOnlyMemory<sbyte> vector2) |
| 109 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 113 | + /// </summary> |
| 114 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 115 | + /// <param name="vector1">The first vector.</param> |
| 116 | + /// <param name="vector2">The second vector.</param> |
| 117 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 118 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 119 | + /// property is leveraged.</param> |
| 120 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 121 | + public static double VectorDistance( |
| 122 | + this DbFunctions _, |
| 123 | + ReadOnlyMemory<sbyte> vector1, |
| 124 | + ReadOnlyMemory<sbyte> vector2, |
| 125 | + [NotParameterized] bool useBruteForce) |
| 126 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 127 | + |
| 128 | + /// <summary> |
| 129 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 130 | + /// </summary> |
| 131 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 132 | + /// <param name="vector1">The first vector.</param> |
| 133 | + /// <param name="vector2">The second vector.</param> |
| 134 | + /// <param name="distanceFunction">The distance function to use.</param> |
| 135 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 136 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 137 | + /// property is leveraged.</param> |
| 138 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 139 | + public static double VectorDistance( |
| 140 | + this DbFunctions _, |
| 141 | + ReadOnlyMemory<sbyte> vector1, |
| 142 | + ReadOnlyMemory<sbyte> vector2, |
| 143 | + [NotParameterized] bool useBruteForce, |
| 144 | + [NotParameterized] DistanceFunction distanceFunction) |
| 145 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 146 | + |
| 147 | + /// <summary> |
| 148 | + /// Returns the distance between two vectors, using the distance function and data type defined using |
| 149 | + /// <see cref="CosmosPropertyBuilderExtensions.IsVector(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder,Microsoft.Azure.Cosmos.DistanceFunction,int)"/>. |
| 150 | + /// </summary> |
| 151 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 152 | + /// <param name="vector1">The first vector.</param> |
| 153 | + /// <param name="vector2">The second vector.</param> |
| 154 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 155 | + public static double VectorDistance(this DbFunctions _, ReadOnlyMemory<float> vector1, ReadOnlyMemory<float> vector2) |
| 156 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 157 | + |
| 158 | + /// <summary> |
| 159 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 160 | + /// </summary> |
| 161 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 162 | + /// <param name="vector1">The first vector.</param> |
| 163 | + /// <param name="vector2">The second vector.</param> |
| 164 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 165 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 166 | + /// property is leveraged.</param> |
| 167 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 168 | + public static double VectorDistance( |
| 169 | + this DbFunctions _, |
| 170 | + ReadOnlyMemory<float> vector1, |
| 171 | + ReadOnlyMemory<float> vector2, |
| 172 | + [NotParameterized] bool useBruteForce) |
| 173 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
| 174 | + |
| 175 | + /// <summary> |
| 176 | + /// Returns the distance between two vectors, given a distance function (aka similarity measure). |
| 177 | + /// </summary> |
| 178 | + /// <param name="_">The <see cref="DbFunctions" /> instance.</param> |
| 179 | + /// <param name="vector1">The first vector.</param> |
| 180 | + /// <param name="vector2">The second vector.</param> |
| 181 | + /// <param name="distanceFunction">The distance function to use.</param> |
| 182 | + /// <param name="useBruteForce">A <see langword="bool"/> specifying how the computed value is used in an ORDER BY |
| 183 | + /// expression. If <see langword="true"/>, then brute force is used, otherwise any index defined on the vector |
| 184 | + /// property is leveraged.</param> |
| 185 | + [Experimental(EFDiagnostics.CosmosVectorSearchExperimental)] |
| 186 | + public static double VectorDistance( |
| 187 | + this DbFunctions _, |
| 188 | + ReadOnlyMemory<float> vector1, |
| 189 | + ReadOnlyMemory<float> vector2, |
| 190 | + [NotParameterized] bool useBruteForce, |
| 191 | + [NotParameterized] DistanceFunction distanceFunction) |
| 192 | + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(VectorDistance))); |
50 | 193 | }
|
0 commit comments