70 instantiations of Embedding
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (1)
224
return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new
Embedding
<float>(floats))));
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (1)
271
return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new
Embedding
<float>(floats))));
Microsoft.Extensions.AI.Abstractions (6)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingByte.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<byte>((global::System.ReadOnlyMemory<byte>)args[0]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingDouble.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<double>((global::System.ReadOnlyMemory<double>)args[0]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingHalf.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>((global::System.ReadOnlyMemory<global::System.Half>)args[0]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingInt32.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<int>((global::System.ReadOnlyMemory<int>)args[0]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingSByte.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<sbyte>((global::System.ReadOnlyMemory<sbyte>)args[0]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingSingle.g.cs (1)
34
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<float>((global::System.ReadOnlyMemory<float>)args[0]),
Microsoft.Extensions.AI.Abstractions.Tests (35)
Embeddings\DelegatingEmbeddingGeneratorTests.cs (1)
28
var expectedEmbedding = new GeneratedEmbeddings<Embedding<float>>([
new
(new float[] { 1.0f, 2.0f, 3.0f })]);
Embeddings\EmbeddingGeneratorExtensionsTests.cs (2)
89
Embedding<float> result =
new
(new float[] { 1f, 2f, 3f });
110
.Select(i => new
Embedding
<float>(Enumerable.Range(i, 4).Select(i => (float)i).ToArray()))
Embeddings\EmbeddingTests.cs (5)
23
Embedding<float> e =
new
(floats)
43
Embedding<byte> e =
new
(bytes);
56
Embedding<sbyte> e =
new
(bytes);
84
Embedding<float> e =
new
(floats);
97
Embedding<double> e =
new
(floats);
Embeddings\GeneratedEmbeddingsTests.cs (23)
42
Assert.False(instance.Contains(new
Embedding
<float>(new float[] { 1, 2, 3 })));
45
Assert.Equal(-1, instance.IndexOf(new
Embedding
<float>(new float[] { 1, 2, 3 })));
60
new
(new float[] { 1, 2, 3 }),
61
new
(new float[] { 4, 5, 6 }),
86
var e = new
Embedding
<float>(new float[] { 7, 8, 9 });
117
var e = new
Embedding
<float>(new float[] { 1, 2, 3 });
129
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
130
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
144
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
145
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
160
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
161
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
183
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
184
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
202
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
203
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
208
var e3 = new
Embedding
<float>(new float[] { 7, 8, 9 });
220
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
221
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
226
var e3 = new
Embedding
<float>(new float[] { 7, 8, 9 });
238
var e1 = new
Embedding
<float>(new float[] { 1, 2, 3 });
239
var e2 = new
Embedding
<float>(new float[] { 4, 5, 6 });
251
var expectedGeneratedEmbeddings = new GeneratedEmbeddings<Embedding<float>>([new
Embedding
<float>(new float[] { 1, 2, 3 })]);
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingByte.g.cs (1)
32
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<byte>((global::System.ReadOnlyMemory<byte>)args[0]),
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingDouble.g.cs (1)
32
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<double>((global::System.ReadOnlyMemory<double>)args[0]),
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSByte.g.cs (1)
32
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<sbyte>((global::System.ReadOnlyMemory<sbyte>)args[0]),
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSingle.g.cs (1)
32
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<float>((global::System.ReadOnlyMemory<float>)args[0]),
Microsoft.Extensions.AI.OpenAI (1)
OpenAIEmbeddingGenerator.cs (1)
86
new
Embedding
<float>(e.ToFloats())
Microsoft.Extensions.AI.Tests (15)
ChatRouting\SemanticRoutingChatClientTests.cs (3)
94
[.. inputs.Select(input => new
Embedding
<float>(vectors[input]))]));
144
[.. values.Select(input => new
Embedding
<float>(vectors[input]))])),
187
[.. values.Select(input => new
Embedding
<float>(vectors[input]))])),
Embeddings\DistributedCachingEmbeddingGeneratorTest.cs (8)
18
private readonly Embedding<float> _expectedEmbedding =
new
(new float[] { 1.0f, 2.0f, 3.0f })
90
new
Embedding
<float>(new[] { 1.0f, 2.0f, 3.0f })
254
return [
new
(((string)options!.AdditionalProperties!["someKey"]!).Select(c => (float)c).ToArray())];
274
AssertEmbeddingsEqual(
new
("value 1".Select(c => (float)c).ToArray()), result1);
275
AssertEmbeddingsEqual(
new
("value 1".Select(c => (float)c).ToArray()), result2);
289
AssertEmbeddingsEqual(
new
("value 1".Select(c => (float)c).ToArray()), result3);
290
AssertEmbeddingsEqual(
new
("value 2".Select(c => (float)c).ToArray()), result4);
305
return new(new Embedding<float>[] { new
Embedding
<float>(new float[] { innerCallCount }) });
Embeddings\LoggingEmbeddingGeneratorTests.cs (1)
58
return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>([new
Embedding
<float>(new float[] { 1f, 2f, 3f })]));
Embeddings\OpenTelemetryEmbeddingGeneratorTests.cs (1)
38
return new GeneratedEmbeddings<Embedding<float>>([new
Embedding
<float>(new float[] { 1, 2, 3 })])
Embeddings\UseDelegateEmbeddingGeneratorTests.cs (1)
53
e.Add(new
Embedding
<float>(default));
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSingle.g.cs (1)
32
ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.
Embedding
<float>((global::System.ReadOnlyMemory<float>)args[0]),
Microsoft.Extensions.DataIngestion.Tests (7)
Chunkers\SemanticSimilarityChunkerTests.cs (6)
50
new
Embedding
<float>(new float[] { 1.0f, 2.0f, 3.0f, 4.0f }))
88
0 => new
Embedding
<float>(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }),
89
1 => new
Embedding
<float>(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }),
90
2 => new
Embedding
<float>(new float[] { -1.0f, -1.0f, -1.0f, -1.0f }),
165
<= 3 => new
Embedding
<float>(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }),
166
>= 4 and <= 7 => new
Embedding
<float>(new float[] { -1.0f, -1.0f, -1.0f, -1.0f }),
Utils\TestEmbeddingGenerator.cs (1)
28
[
new
(new float[] { 0, 1, 2, 3 })]));
Microsoft.Extensions.VectorData.ConformanceTests (4)
EmbeddingGenerationTests.cs (2)
597
results.Add(new
Embedding
<float>(vector));
614
=> Task.FromResult(new GeneratedEmbeddings<Embedding<float>> {
new
(embedding) });
TypeTests\EmbeddingTypeTests.cs (2)
31
new
Embedding
<float>(new ReadOnlyMemory<float>([1, 2, 3])),
186
=> Task.FromResult(new GeneratedEmbeddings<Embedding<T>>([
new
(data)]));
491 references to Embedding
Aspire.Azure.AI.Inference (5)
AspireAzureAIInferenceExtensions.cs (5)
477
public static EmbeddingGeneratorBuilder<string,
Embedding
<float>> AddEmbeddingGenerator(this AspireEmbeddingsClientBuilder builder, string? deploymentName = null)
506
public static EmbeddingGeneratorBuilder<string,
Embedding
<float>> AddKeyedEmbeddingGenerator(this AspireEmbeddingsClientBuilder builder, string serviceKey, string? deploymentName = null)
517
private static IEmbeddingGenerator<string,
Embedding
<float>> CreateInnerEmbeddingGenerator(AspireEmbeddingsClientBuilder builder, IServiceProvider services, string? deploymentName)
531
return new OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>(result, loggerFactory?.CreateLogger(typeof(OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>)))
Aspire.Azure.AI.Inference.Tests (2)
AspireAzureAIInferenceEmbeddingsExtensionTests.cs (2)
108
host.Services.GetKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("embedding") :
109
host.Services.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>();
Aspire.Azure.AI.OpenAI.Tests (18)
AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (18)
36
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
37
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
66
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
67
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
94
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
95
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
125
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
126
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
156
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
157
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
187
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
188
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
190
Assert.Equal(disableOpenTelemetry, generator.GetService<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>() is null);
214
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
215
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
221
private Task<GeneratedEmbeddings<
Embedding
<float>>> TestMiddleware(IEnumerable<string> inputs, EmbeddingGenerationOptions? options, IEmbeddingGenerator<string,
Embedding
<float>> nextAsync, CancellationToken cancellationToken)
224
return Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(inputs.Select(i => new Embedding<float>(floats))));
Aspire.OpenAI (5)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensions.cs (5)
23
public static EmbeddingGeneratorBuilder<string,
Embedding
<float>> AddEmbeddingGenerator(
40
public static EmbeddingGeneratorBuilder<string,
Embedding
<float>> AddKeyedEmbeddingGenerator(
58
private static IEmbeddingGenerator<string,
Embedding
<float>> CreateInnerEmbeddingGenerator(
76
return new OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>(
78
loggerFactory?.CreateLogger(typeof(OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>)))
Aspire.OpenAI.Tests (20)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (20)
39
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
40
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
69
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
70
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
97
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
98
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
128
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
129
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
159
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
160
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
190
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
191
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
193
Assert.Equal(disableOpenTelemetry, generator.GetService<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>() is null);
217
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
218
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
250
host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("openai_embeddinggenerator") :
251
host.Services.GetRequiredService<IEmbeddingGenerator<string,
Embedding
<float>>>();
268
private Task<GeneratedEmbeddings<
Embedding
<float>>> TestMiddleware(IEnumerable<string> inputs, EmbeddingGenerationOptions? options, IEmbeddingGenerator<string,
Embedding
<float>> nextAsync, CancellationToken cancellationToken)
271
return Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(inputs.Select(i => new Embedding<float>(floats))));
Microsoft.Extensions.AI (5)
ChatRouting\SemanticRoutingChatClient.cs (4)
48
private readonly IEmbeddingGenerator<string,
Embedding
<float>> _embeddingGenerator;
88
IEmbeddingGenerator<string,
Embedding
<float>> embeddingGenerator,
185
GeneratedEmbeddings<
Embedding
<float>> generated =
316
GeneratedEmbeddings<
Embedding
<float>> embeddings =
Embeddings\CachingEmbeddingGenerator.cs (1)
119
/// <summary>Returns a previously cached <see cref="
Embedding
{TEmbedding}"/>, if available.</summary>
Microsoft.Extensions.AI.Abstractions (129)
Embeddings\Embedding.cs (5)
14
[JsonDerivedType(typeof(
Embedding
<byte>), typeDiscriminator: "uint8")]
15
[JsonDerivedType(typeof(
Embedding
<sbyte>), typeDiscriminator: "int8")]
17
[JsonDerivedType(typeof(
Embedding
<Half>), typeDiscriminator: "float16")]
19
[JsonDerivedType(typeof(
Embedding
<float>), typeDiscriminator: "float32")]
20
[JsonDerivedType(typeof(
Embedding
<double>), typeDiscriminator: "float64")]
Embeddings\Embedding{T}.cs (1)
14
/// <summary>Initializes a new instance of the <see cref="
Embedding
{T}"/> class with the embedding vector.</summary>
Embeddings\EmbeddingGeneratorExtensions.cs (4)
100
/// resulting <see cref="
Embedding
{T}"/>'s <see cref="
Embedding
{T}.Vector"/> property.
103
this IEmbeddingGenerator<TInput,
Embedding
<TEmbeddingElement>> generator,
108
var
embedding = await GenerateAsync(generator, value, options, cancellationToken).ConfigureAwait(false);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingByte.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>? _EmbeddingByte;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> EmbeddingByte
24
get => _EmbeddingByte ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> Create_EmbeddingByte(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<byte>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<byte>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<byte>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<byte>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<byte>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<byte>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingByteSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<byte>? value)
169
global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::Microsoft.Extensions.AI.
Embedding
<byte>)value).Vector, ReadOnlyMemoryByte);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingDouble.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>? _EmbeddingDouble;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> EmbeddingDouble
24
get => _EmbeddingDouble ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<double>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> Create_EmbeddingDouble(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<double>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<double>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<double>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<double>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<double>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<double>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<double>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<double>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingDoubleSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<double>? value)
169
ReadOnlyMemoryDoubleSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<double>)value).Vector);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingHalf.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>>? _EmbeddingHalf;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>> EmbeddingHalf
24
get => _EmbeddingHalf ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>> Create_EmbeddingHalf(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<global::System.Half>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<global::System.Half>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingHalfSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>? value)
169
ReadOnlyMemoryHalfSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>)value).Vector);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingInt32.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<int>>? _EmbeddingInt32;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<int>> EmbeddingInt32
24
get => _EmbeddingInt32 ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<int>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<int>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<int>> Create_EmbeddingInt32(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<int>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<int>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<int>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<int>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<int>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<int>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<int>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<int>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<int>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<int>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<int>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<int>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<int>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingInt32SerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<int>? value)
169
ReadOnlyMemoryInt32SerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<int>)value).Vector);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingSByte.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>? _EmbeddingSByte;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> EmbeddingSByte
24
get => _EmbeddingSByte ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> Create_EmbeddingSByte(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<sbyte>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<sbyte>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingSByteSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<sbyte>? value)
169
ReadOnlyMemorySByteSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)value).Vector);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.EmbeddingSingle.g.cs (18)
15
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>? _EmbeddingSingle;
21
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> EmbeddingSingle
24
get => _EmbeddingSingle ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<float>));
27
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> Create_EmbeddingSingle(global::System.Text.Json.JsonSerializerOptions options)
29
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> jsonTypeInfo))
31
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<float>>
37
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<float>)}, modifiers: null),
41
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, objectInfo);
58
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
60
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector,
61
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector = value!,
68
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<float>), global::System.Array.Empty<global::System.Type>(), null),
78
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
88
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
158
private void EmbeddingSingleSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<float>? value)
169
ReadOnlyMemorySingleSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<float>)value).Vector);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (6)
160
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>))
164
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<double>))
168
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<float>))
172
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<global::System.Half>))
176
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<int>))
180
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>))
Utilities\AIJsonUtilities.Defaults.cs (5)
116
[JsonSerializable(typeof(
Embedding
<byte>))]
117
[JsonSerializable(typeof(
Embedding
<int>))]
119
[JsonSerializable(typeof(
Embedding
<Half>))]
121
[JsonSerializable(typeof(
Embedding
<float>))]
122
[JsonSerializable(typeof(
Embedding
<double>))]
Microsoft.Extensions.AI.Abstractions.Tests (142)
Embeddings\DelegatingEmbeddingGeneratorTests.cs (6)
27
var expectedResult = new TaskCompletionSource<GeneratedEmbeddings<
Embedding
<float>>>();
28
var expectedEmbedding = new GeneratedEmbeddings<
Embedding
<float>>([new(new float[] { 1.0f, 2.0f, 3.0f })]);
67
var service = delegating.GetService<DelegatingEmbeddingGenerator<string,
Embedding
<float>>>();
87
var service = delegating.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>(expectedKey);
115
private sealed class NoOpDelegatingEmbeddingGenerator(IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator) :
116
DelegatingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator);
Embeddings\EmbeddingGeneratorExtensionsTests.cs (6)
31
using IEmbeddingGenerator<string,
Embedding
<float>> generator = new TestEmbeddingGenerator
40
if (serviceType == typeof(IEmbeddingGenerator<string,
Embedding
<float>>))
89
Embedding
<float> result = new(new float[] { 1f, 2f, 3f });
94
Task.FromResult<GeneratedEmbeddings<
Embedding
<float>>>([result])
108
Embedding
<float>[] embeddings = Enumerable
116
Task.FromResult<GeneratedEmbeddings<
Embedding
<float>>>(new(embeddings))
Embeddings\EmbeddingTests.cs (15)
23
Embedding
<float> e = new(floats)
43
Embedding
<byte> e = new(bytes);
48
Embedding
<byte> result = Assert.IsType<
Embedding
<byte>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding));
56
Embedding
<sbyte> e = new(bytes);
61
Embedding
<sbyte> result = Assert.IsType<
Embedding
<sbyte>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding));
84
Embedding
<float> e = new(floats);
89
Embedding
<float> result = Assert.IsType<
Embedding
<float>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding));
97
Embedding
<double> e = new(floats);
102
Embedding
<double> result = Assert.IsType<
Embedding
<double>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding));
124
var
floatEmbedding = Assert.IsType<
Embedding
<float>>(result);
Embeddings\GeneratedEmbeddingsTests.cs (38)
20
Assert.Throws<ArgumentNullException>("embeddings", () => new GeneratedEmbeddings<
Embedding
<float>>(null!));
21
Assert.Throws<ArgumentOutOfRangeException>("capacity", () => new GeneratedEmbeddings<
Embedding
<float>>(-1));
27
GeneratedEmbeddings<
Embedding
<float>>[] instances =
39
Assert.False(((ICollection<
Embedding
<float>>)instance).IsReadOnly);
48
instance.CopyTo(Array.Empty<
Embedding
<float>>(), 0);
58
List<
Embedding
<float>> embeddings =
64
var generatedEmbeddings = new GeneratedEmbeddings<
Embedding
<float>>(embeddings);
86
var
e = new Embedding<float>(new float[] { 7, 8, 9 });
95
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
116
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
117
var
e = new Embedding<float>(new float[] { 1, 2, 3 });
127
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
129
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
130
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
142
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
144
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
145
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
158
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
160
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
161
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
181
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
183
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
184
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
200
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
202
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
203
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
208
var
e3 = new Embedding<float>(new float[] { 7, 8, 9 });
218
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
220
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
221
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
226
var
e3 = new Embedding<float>(new float[] { 7, 8, 9 });
236
GeneratedEmbeddings<
Embedding
<float>> embeddings = [];
238
var
e1 = new Embedding<float>(new float[] { 1, 2, 3 });
239
var
e2 = new Embedding<float>(new float[] { 4, 5, 6 });
251
var expectedGeneratedEmbeddings = new GeneratedEmbeddings<
Embedding
<float>>([new Embedding<float>(new float[] { 1, 2, 3 })]);
253
using IEmbeddingGenerator<object,
Embedding
<float>> acceptsObject = new TestEmbeddingGenerator<object,
Embedding
<float>>
258
IEmbeddingGenerator<string,
Embedding
<float>> acceptsString = acceptsObject;
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingByte.g.cs (18)
13
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>? _EmbeddingByte;
19
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> EmbeddingByte
22
get => _EmbeddingByte ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>));
25
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> Create_EmbeddingByte(global::System.Text.Json.JsonSerializerOptions options)
27
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<byte>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>> jsonTypeInfo))
29
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<byte>>
35
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<byte>)}, modifiers: null),
39
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<byte>>(options, objectInfo);
56
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>),
58
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<byte>)obj).Vector,
59
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<byte>)obj).Vector = value!,
66
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<byte>), global::System.Array.Empty<global::System.Type>(), null),
76
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>),
86
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
156
private void EmbeddingByteSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<byte>? value)
167
global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::Microsoft.Extensions.AI.
Embedding
<byte>)value).Vector, ReadOnlyMemoryByte);
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingDouble.g.cs (18)
13
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>? _EmbeddingDouble;
19
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> EmbeddingDouble
22
get => _EmbeddingDouble ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<double>));
25
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> Create_EmbeddingDouble(global::System.Text.Json.JsonSerializerOptions options)
27
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<double>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<double>> jsonTypeInfo))
29
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<double>>
35
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<double>)}, modifiers: null),
39
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<double>>(options, objectInfo);
56
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<double>),
58
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<double>)obj).Vector,
59
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<double>)obj).Vector = value!,
66
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<double>), global::System.Array.Empty<global::System.Type>(), null),
76
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<double>),
86
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<double>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
156
private void EmbeddingDoubleSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<double>? value)
167
ReadOnlyMemoryDoubleSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<double>)value).Vector);
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSByte.g.cs (18)
13
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>? _EmbeddingSByte;
19
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> EmbeddingSByte
22
get => _EmbeddingSByte ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>));
25
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> Create_EmbeddingSByte(global::System.Text.Json.JsonSerializerOptions options)
27
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>> jsonTypeInfo))
29
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>
35
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<sbyte>)}, modifiers: null),
39
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<sbyte>>(options, objectInfo);
56
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>),
58
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)obj).Vector,
59
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)obj).Vector = value!,
66
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<sbyte>), global::System.Array.Empty<global::System.Type>(), null),
76
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>),
86
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
156
private void EmbeddingSByteSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<sbyte>? value)
167
ReadOnlyMemorySByteSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<sbyte>)value).Vector);
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSingle.g.cs (18)
13
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>? _EmbeddingSingle;
19
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> EmbeddingSingle
22
get => _EmbeddingSingle ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<float>));
25
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> Create_EmbeddingSingle(global::System.Text.Json.JsonSerializerOptions options)
27
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> jsonTypeInfo))
29
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<float>>
35
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<float>)}, modifiers: null),
39
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, objectInfo);
56
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
58
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector,
59
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector = value!,
66
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<float>), global::System.Array.Empty<global::System.Type>(), null),
76
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
86
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
156
private void EmbeddingSingleSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<float>? value)
167
ReadOnlyMemorySingleSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<float>)value).Vector);
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (4)
154
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<byte>))
158
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<double>))
162
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<float>))
166
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<sbyte>))
TestEmbeddingGenerator.cs (1)
41
public sealed class TestEmbeddingGenerator : TestEmbeddingGenerator<string,
Embedding
<float>>;
Microsoft.Extensions.AI.Integration.Tests (14)
CallCountingEmbeddingGenerator.cs (5)
13
internal sealed class CallCountingEmbeddingGenerator(IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator)
14
: DelegatingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator)
20
public override Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(
30
public static EmbeddingGeneratorBuilder<string,
Embedding
<float>> UseCallCounting(
31
this EmbeddingGeneratorBuilder<string,
Embedding
<float>> builder) =>
EmbeddingGeneratorIntegrationTests.cs (6)
29
private readonly IEmbeddingGenerator<string,
Embedding
<float>>? _embeddingGenerator;
42
protected abstract IEmbeddingGenerator<string,
Embedding
<float>>? CreateEmbeddingGenerator();
93
var
embedding1 = await generator.GenerateAsync(input);
94
var
embedding2 = await generator.GenerateAsync(input);
95
var
embedding3 = await generator.GenerateAsync(input + "... and Green");
96
var
embedding4 = await generator.GenerateAsync(input);
QuantizationEmbeddingGenerator.cs (3)
22
private readonly IEmbeddingGenerator<string,
Embedding
<float>> _floatService;
24
public QuantizationEmbeddingGenerator(IEmbeddingGenerator<string,
Embedding
<float>> floatService)
46
private static BinaryEmbedding QuantizeToBinary(
Embedding
<float> embedding)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (1)
OllamaSharpEmbeddingGeneratorIntegrationTests.cs (1)
13
protected override IEmbeddingGenerator<string,
Embedding
<float>>? CreateEmbeddingGenerator() =>
Microsoft.Extensions.AI.OpenAI (3)
OpenAIClientExtensions.cs (1)
192
public static IEmbeddingGenerator<string,
Embedding
<float>> AsIEmbeddingGenerator(this EmbeddingClient embeddingClient, int? defaultModelDimensions = null) =>
OpenAIEmbeddingGenerator.cs (2)
21
internal sealed class OpenAIEmbeddingGenerator : IEmbeddingGenerator<string,
Embedding
<float>>
68
public async Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.OpenAI.Tests (29)
OpenAIEmbeddingGeneratorIntegrationTests.cs (1)
8
protected override IEmbeddingGenerator<string,
Embedding
<float>>? CreateEmbeddingGenerator() =>
OpenAIEmbeddingGeneratorTests.cs (27)
35
IEmbeddingGenerator<string,
Embedding
<float>> embeddingGenerator = client.GetEmbeddingClient(model).AsIEmbeddingGenerator();
51
IEmbeddingGenerator<string,
Embedding
<float>> embeddingGenerator = openAIClient.AsIEmbeddingGenerator();
53
Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>());
59
using IEmbeddingGenerator<string,
Embedding
<float>> pipeline = embeddingGenerator
65
Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>>());
66
Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string,
Embedding
<float>>>());
67
Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>());
70
Assert.IsType<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>(pipeline.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>());
77
IEmbeddingGenerator<string,
Embedding
<float>> embeddingGenerator = openAIClient.AsIEmbeddingGenerator();
79
Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>());
82
using IEmbeddingGenerator<string,
Embedding
<float>> pipeline = embeddingGenerator
88
Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>>());
89
Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string,
Embedding
<float>>>());
90
Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>());
93
Assert.IsType<OpenTelemetryEmbeddingGenerator<string,
Embedding
<float>>>(pipeline.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>());
128
using IEmbeddingGenerator<string,
Embedding
<float>> generator = CreateEmbeddingGenerator(httpClient, "text-embedding-3-small");
141
foreach (
Embedding
<float> e in response)
188
using IEmbeddingGenerator<string,
Embedding
<float>> generator = CreateEmbeddingGenerator(httpClient, "text-embedding-3-small");
210
foreach (
Embedding
<float> e in response)
246
using IEmbeddingGenerator<string,
Embedding
<float>> generator = CreateEmbeddingGenerator(httpClient, "text-embedding-3-small");
253
foreach (
Embedding
<float> e in response)
289
using IEmbeddingGenerator<string,
Embedding
<float>> generator = CreateEmbeddingGenerator(httpClient, "text-embedding-3-small");
296
foreach (
Embedding
<float> e in response)
309
using IEmbeddingGenerator<string,
Embedding
<float>> generator = CreateEmbeddingGenerator(httpClient, "text-embedding-3-small");
317
private static IEmbeddingGenerator<string,
Embedding
<float>> CreateEmbeddingGenerator(HttpClient httpClient, string modelId) =>
OpenAIRequestPoliciesTests.cs (1)
53
IEmbeddingGenerator<string,
Embedding
<float>> generator =
Microsoft.Extensions.AI.Tests (100)
ChatCompletion\DependencyInjectionPatterns.cs (6)
172
Assert.Equal(typeof(IEmbeddingGenerator<string,
Embedding
<float>>), sd.ServiceType);
194
IEmbeddingGenerator<string,
Embedding
<float>>? g = sp.GetService<IEmbeddingGenerator<string,
Embedding
<float>>>();
217
Assert.Equal(typeof(IEmbeddingGenerator<string,
Embedding
<float>>), sd.ServiceType);
240
IEmbeddingGenerator<string,
Embedding
<float>>? g = sp.GetKeyedService<IEmbeddingGenerator<string,
Embedding
<float>>>("key");
ChatRouting\SemanticRoutingChatClientTests.cs (5)
93
return Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(
143
Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(
186
Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(
262
IEmbeddingGenerator<string,
Embedding
<float>>
266
public Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(
Embeddings\ConfigureOptionsEmbeddingGeneratorTests.cs (4)
16
Assert.Throws<ArgumentNullException>("innerGenerator", () => new ConfigureOptionsEmbeddingGenerator<string,
Embedding
<float>>(null!, _ => { }));
17
Assert.Throws<ArgumentNullException>("configure", () => new ConfigureOptionsEmbeddingGenerator<string,
Embedding
<float>>(new TestEmbeddingGenerator(), null!));
35
GeneratedEmbeddings<
Embedding
<float>> expectedEmbeddings = [];
38
using IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator = new TestEmbeddingGenerator
Embeddings\DistributedCachingEmbeddingGeneratorTest.cs (35)
18
private readonly
Embedding
<float> _expectedEmbedding = new(new float[] { 1.0f, 2.0f, 3.0f })
29
using DistributedCachingEmbeddingGenerator<string,
Embedding
<float>> generator = new(innerGenerator, _storage);
56
return Task.FromResult<GeneratedEmbeddings<
Embedding
<float>>>([_expectedEmbedding]);
59
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(testGenerator, _storage)
65
var
result1 = await outer.GenerateAsync("abc");
70
var
result2 = await outer.GenerateAsync("abc");
89
Embedding
<float>[] expected = Enumerable.Range(0, 10).Select(i =>
102
return Task.FromResult<GeneratedEmbeddings<
Embedding
<float>>>(new(values.Select(i => expected[int.Parse(i)])));
105
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(testGenerator, _storage)
150
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, _storage)
168
var
result3 = await outer.GenerateAsync("abc");
186
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, _storage)
223
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, _storage)
237
var
result2 = await outer.GenerateAsync("abc");
257
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, _storage)
263
var
result1 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
267
var
result2 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
278
var
result3 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
282
var
result4 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
305
return new(new
Embedding
<float>[] { new Embedding<float>(new float[] { innerCallCount }) });
308
using var outer = new DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, _storage)
313
var
result1 = await outer.GenerateAsync("abc");
314
var
result2 = await outer.GenerateAsync("abc");
317
var
result3 = await outer.GenerateAsync("abc");
323
var
result4 = await outer.GenerateAsync("abc");
326
var
result5 = await outer.GenerateAsync("abc");
332
var
result6 = await outer.GenerateAsync("abc");
357
var
result1 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
361
var
result2 = await outer.GenerateAsync("abc", new EmbeddingGenerationOptions
383
return Task.FromResult<GeneratedEmbeddings<
Embedding
<float>>>([_expectedEmbedding]);
396
var
result = await outer.GenerateAsync("abc");
403
private static void AssertEmbeddingsEqual(
Embedding
<float> expected,
Embedding
<float> actual)
413
private sealed class CachingEmbeddingGeneratorWithCustomKey(IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator, IDistributedCache storage)
414
: DistributedCachingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator, storage)
Embeddings\EmbeddingGeneratorBuilderTests.cs (9)
19
var builder = new EmbeddingGeneratorBuilder<string,
Embedding
<float>>(services =>
60
Assert.Throws<ArgumentNullException>("innerGenerator", () => new EmbeddingGeneratorBuilder<string,
Embedding
<float>>((IEmbeddingGenerator<string,
Embedding
<float>>)null!));
61
Assert.Throws<ArgumentNullException>("innerGenerator", () => ((IEmbeddingGenerator<string,
Embedding
<float>>)null!).AsBuilder());
68
() => new EmbeddingGeneratorBuilder<string,
Embedding
<float>>((Func<IServiceProvider, IEmbeddingGenerator<string,
Embedding
<float>>>)null!));
81
private sealed class InnerServiceCapturingEmbeddingGenerator(string name, IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator) :
82
DelegatingEmbeddingGenerator<string,
Embedding
<float>>(innerGenerator)
87
public new IEmbeddingGenerator<string,
Embedding
<float>> InnerGenerator => base.InnerGenerator;
Embeddings\LoggingEmbeddingGeneratorTests.cs (11)
19
Assert.Throws<ArgumentNullException>("innerGenerator", () => new LoggingEmbeddingGenerator<string,
Embedding
<float>>(null!, NullLogger.Instance));
20
Assert.Throws<ArgumentNullException>("logger", () => new LoggingEmbeddingGenerator<string,
Embedding
<float>>(new TestEmbeddingGenerator(), null!));
28
Assert.Null(innerGenerator.AsBuilder().UseLogging(NullLoggerFactory.Instance).Build().GetService(typeof(LoggingEmbeddingGenerator<string,
Embedding
<float>>)));
29
Assert.Same(innerGenerator, innerGenerator.AsBuilder().UseLogging(NullLoggerFactory.Instance).Build().GetService(typeof(IEmbeddingGenerator<string,
Embedding
<float>>)));
32
Assert.NotNull(innerGenerator.AsBuilder().UseLogging(factory).Build().GetService(typeof(LoggingEmbeddingGenerator<string,
Embedding
<float>>)));
37
Assert.NotNull(innerGenerator.AsBuilder().UseLogging().Build(services).GetService(typeof(LoggingEmbeddingGenerator<string,
Embedding
<float>>)));
38
Assert.NotNull(innerGenerator.AsBuilder().UseLogging(null).Build(services).GetService(typeof(LoggingEmbeddingGenerator<string,
Embedding
<float>>)));
39
Assert.Null(innerGenerator.AsBuilder().UseLogging(NullLoggerFactory.Instance).Build(services).GetService(typeof(LoggingEmbeddingGenerator<string,
Embedding
<float>>)));
54
using IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator = new TestEmbeddingGenerator
58
return Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>([new Embedding<float>(new float[] { 1f, 2f, 3f })]));
62
using IEmbeddingGenerator<string,
Embedding
<float>> generator = innerGenerator
Embeddings\OpenTelemetryEmbeddingGeneratorTests.cs (1)
38
return new GeneratedEmbeddings<
Embedding
<float>>([new Embedding<float>(new float[] { 1, 2, 3 })])
Embeddings\UseDelegateEmbeddingGeneratorTests.cs (8)
18
EmbeddingGeneratorBuilder<string,
Embedding
<float>> builder = new(generator);
21
builder.Use((Func<IEnumerable<string>, EmbeddingGenerationOptions?, IEmbeddingGenerator<string,
Embedding
<float>>, CancellationToken, Task<GeneratedEmbeddings<
Embedding
<float>>>>)null!));
27
GeneratedEmbeddings<
Embedding
<float>> expectedEmbeddings = [];
33
using IEmbeddingGenerator<string,
Embedding
<float>> innerGenerator = new TestEmbeddingGenerator
45
using IEmbeddingGenerator<string,
Embedding
<float>> generator = new EmbeddingGeneratorBuilder<string,
Embedding
<float>>(innerGenerator)
60
GeneratedEmbeddings<
Embedding
<float>> actual = await generator.GenerateAsync(expectedValues, expectedOptions, expectedCts.Token);
Generated\361d1da7f942c932\TestJsonSerializerContext.EmbeddingSingle.g.cs (18)
13
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>? _EmbeddingSingle;
19
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> EmbeddingSingle
22
get => _EmbeddingSingle ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.
Embedding
<float>));
25
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> Create_EmbeddingSingle(global::System.Text.Json.JsonSerializerOptions options)
27
if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.
Embedding
<float>> jsonTypeInfo))
29
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.
Embedding
<float>>
35
ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(global::System.ReadOnlyMemory<float>)}, modifiers: null),
39
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.
Embedding
<float>>(options, objectInfo);
56
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
58
Getter = static obj => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector,
59
Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.
Embedding
<float>)obj).Vector = value!,
66
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Vector", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<float>), global::System.Array.Empty<global::System.Type>(), null),
76
DeclaringType = typeof(global::Microsoft.Extensions.AI.
Embedding
<float>),
86
AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.
Embedding
<float>).GetProperty("Dimensions", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty<global::System.Type>(), null),
156
private void EmbeddingSingleSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.
Embedding
<float>? value)
167
ReadOnlyMemorySingleSerializeHandler(writer, ((global::Microsoft.Extensions.AI.
Embedding
<float>)value).Vector);
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (1)
130
if (type == typeof(global::Microsoft.Extensions.AI.
Embedding
<float>))
parent\Microsoft.Extensions.AI.Abstractions.Tests\TestEmbeddingGenerator.cs (1)
41
public sealed class TestEmbeddingGenerator : TestEmbeddingGenerator<string,
Embedding
<float>>;
TestJsonSerializerContext.cs (1)
21
[JsonSerializable(typeof(
Embedding
<float>))]
Microsoft.Extensions.DataIngestion (2)
Chunkers\SemanticSimilarityChunker.cs (2)
21
private readonly IEmbeddingGenerator<string,
Embedding
<float>> _embeddingGenerator;
31
IEmbeddingGenerator<string,
Embedding
<float>> embeddingGenerator,
Microsoft.Extensions.DataIngestion.Tests (4)
parent\Microsoft.Extensions.AI.Abstractions.Tests\TestEmbeddingGenerator.cs (1)
41
public sealed class TestEmbeddingGenerator : TestEmbeddingGenerator<string,
Embedding
<float>>;
Utils\TestEmbeddingGenerator.cs (3)
12
public sealed class TestEmbeddingGenerator<T> : IEmbeddingGenerator<T,
Embedding
<float>>
23
public Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(IEnumerable<T> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
27
return Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>>(
Microsoft.Extensions.VectorData.Abstractions (3)
ProviderServices\CollectionModelBuilder.cs (2)
373
/// Override this property in providers that support additional embedding types beyond <see cref="
Embedding
{T}"/> of <see langword="float"/>.
376
= [EmbeddingGenerationDispatcher.Create<
Embedding
<float>>()];
ProviderServices\VectorPropertyModel.cs (1)
86
/// (e.g., <see cref="ReadOnlyMemory{T}"/> of <see langword="float"/>, <see langword="float"/>[], <see cref="
Embedding
{T}"/>),
Microsoft.Extensions.VectorData.ConformanceTests (9)
EmbeddingGenerationTests.cs (6)
579
protected sealed class FakeEmbeddingGenerator(int? replaceLast = null) : IEmbeddingGenerator<string,
Embedding
<float>>
581
public Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(
586
var results = new GeneratedEmbeddings<
Embedding
<float>>();
611
private sealed class FakeCustomerEmbeddingGenerator(float[] embedding) : IEmbeddingGenerator<Customer,
Embedding
<float>>
613
public Task<GeneratedEmbeddings<
Embedding
<float>>> GenerateAsync(IEnumerable<Customer> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
614
=> Task.FromResult(new GeneratedEmbeddings<
Embedding
<float>> { new(embedding) });
TypeTests\EmbeddingTypeTests.cs (3)
180
protected sealed class ReadOnlyMemoryEmbeddingGenerator<T>(T[] data) : IEmbeddingGenerator<string,
Embedding
<T>>
182
public Task<GeneratedEmbeddings<
Embedding
<T>>> GenerateAsync(
186
=> Task.FromResult(new GeneratedEmbeddings<
Embedding
<T>>([new(data)]));