34 instantiations of Embedding
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (1)
224return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new Embedding<float>(floats))));
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (1)
225return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new Embedding<float>(floats))));
Microsoft.Extensions.AI.Abstractions.Tests (26)
Embeddings\EmbeddingGeneratorExtensionsTests.cs (2)
31Embedding<float> result = new(new float[] { 1f, 2f, 3f }); 52.Select(i => new Embedding<float>(Enumerable.Range(i, 4).Select(i => (float)i).ToArray()))
Embeddings\EmbeddingTests.cs (4)
22Embedding<float> e = new(floats) 43Embedding<Half> e = new(halfs); 57Embedding<float> e = new(floats); 70Embedding<double> e = new(floats);
Embeddings\GeneratedEmbeddingsTests.cs (20)
41Assert.False(instance.Contains(new Embedding<float>(new float[] { 1, 2, 3 }))); 44Assert.Equal(-1, instance.IndexOf(new Embedding<float>(new float[] { 1, 2, 3 }))); 85var e = new Embedding<float>(new float[] { 7, 8, 9 }); 116var e = new Embedding<float>(new float[] { 1, 2, 3 }); 128var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 129var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 143var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 144var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 159var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 160var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 182var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 183var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 201var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 202var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 207var e3 = new Embedding<float>(new float[] { 7, 8, 9 }); 219var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 220var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 225var e3 = new Embedding<float>(new float[] { 7, 8, 9 }); 237var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 238var e2 = new Embedding<float>(new float[] { 4, 5, 6 });
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceEmbeddingGenerator.cs (1)
93new Embedding<float>(ParseBase64Floats(e.Embedding))
Microsoft.Extensions.AI.Integration.Tests (1)
QuantizationEmbeddingGenerator.cs (1)
85return new(result)
Microsoft.Extensions.AI.OpenAI (1)
OpenAIEmbeddingGenerator.cs (1)
119new Embedding<float>(e.ToFloats())
Microsoft.Extensions.AI.Tests (3)
Embeddings\DistributedCachingEmbeddingGeneratorTest.cs (1)
17private readonly Embedding<float> _expectedEmbedding = new(new float[] { 1.0f, 2.0f, 3.0f })
Embeddings\LoggingEmbeddingGeneratorTests.cs (1)
39return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>([new Embedding<float>(new float[] { 1f, 2f, 3f })]));
Embeddings\UseDelegateEmbeddingGeneratorTests.cs (1)
60e.Add(new Embedding<float>(default));
219 references to Embedding
Aspire.Azure.AI.OpenAI.Tests (18)
AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (18)
36host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 37host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 66host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 67host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 94host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 95host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 125host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 126host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 156host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 157host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 187host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 188host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 190Assert.Equal(disableOpenTelemetry, generator.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>() is null); 214host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 215host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 221private Task<GeneratedEmbeddings<Embedding<float>>> TestMiddleware(IEnumerable<string> inputs, EmbeddingGenerationOptions? options, IEmbeddingGenerator<string, Embedding<float>> nextAsync, CancellationToken cancellationToken) 224return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new Embedding<float>(floats))));
Aspire.OpenAI (4)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensions.cs (4)
22public static EmbeddingGeneratorBuilder<string, Embedding<float>> AddEmbeddingGenerator( 37public static EmbeddingGeneratorBuilder<string, Embedding<float>> AddKeyedEmbeddingGenerator( 47private static IEmbeddingGenerator<string, Embedding<float>> CreateInnerEmbeddingGenerator( 61: new OpenTelemetryEmbeddingGenerator<string, Embedding<float>>(result);
Aspire.OpenAI.Tests (18)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (18)
37host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 38host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 67host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 68host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 95host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 96host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 126host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 127host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 157host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 158host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 188host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 189host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 191Assert.Equal(disableOpenTelemetry, generator.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>() is null); 215host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") : 216host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>(); 222private Task<GeneratedEmbeddings<Embedding<float>>> TestMiddleware(IEnumerable<string> inputs, EmbeddingGenerationOptions? options, IEmbeddingGenerator<string, Embedding<float>> nextAsync, CancellationToken cancellationToken) 225return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(inputs.Select(i => new Embedding<float>(floats))));
Microsoft.Extensions.AI (1)
Embeddings\CachingEmbeddingGenerator.cs (1)
114/// <summary>Returns a previously cached <see cref="Embedding{TEmbedding}"/>, if available.</summary>
Microsoft.Extensions.AI.Abstractions (17)
Embeddings\Embedding.cs (5)
13[JsonDerivedType(typeof(Embedding<Half>), typeDiscriminator: "halves")] 15[JsonDerivedType(typeof(Embedding<float>), typeDiscriminator: "floats")] 16[JsonDerivedType(typeof(Embedding<double>), typeDiscriminator: "doubles")] 17[JsonDerivedType(typeof(Embedding<byte>), typeDiscriminator: "bytes")] 18[JsonDerivedType(typeof(Embedding<sbyte>), typeDiscriminator: "sbytes")]
Embeddings\Embedding{T}.cs (1)
13/// <summary>Initializes a new instance of the <see cref="Embedding{T}"/> class with the embedding vector.</summary>
Embeddings\EmbeddingGeneratorExtensions.cs (6)
52public static TService? GetService<TService>(this IEmbeddingGenerator<string, Embedding<float>> generator, object? serviceKey = null) => 53GetService<string, Embedding<float>, TService>(generator, serviceKey); 65/// resulting <see cref="Embedding{T}"/>'s <see cref="Embedding{T}.Vector"/> property. 68this IEmbeddingGenerator<TInput, Embedding<TEmbedding>> generator, 73var embedding = await GenerateEmbeddingAsync(generator, value, options, cancellationToken).ConfigureAwait(false);
Utilities\AIJsonUtilities.Defaults.cs (5)
77[JsonSerializable(typeof(Embedding<byte>))] 78[JsonSerializable(typeof(Embedding<int>))] 80[JsonSerializable(typeof(Embedding<Half>))] 82[JsonSerializable(typeof(Embedding<float>))] 83[JsonSerializable(typeof(Embedding<double>))]
Microsoft.Extensions.AI.Abstractions.Tests (59)
Embeddings\DelegatingEmbeddingGeneratorTests.cs (7)
36var expectedResult = new TaskCompletionSource<GeneratedEmbeddings<Embedding<float>>>(); 37var expectedEmbedding = new GeneratedEmbeddings<Embedding<float>>([new(new float[] { 1.0f, 2.0f, 3.0f })]); 76var service = delegating.GetService<DelegatingEmbeddingGenerator<string, Embedding<float>>>(); 96var service = delegating.GetService<IEmbeddingGenerator<string, Embedding<float>>>(expectedKey); 124private sealed class NoOpDelegatingEmbeddingGenerator(IEmbeddingGenerator<string, Embedding<float>> innerGenerator) : 125DelegatingEmbeddingGenerator<string, Embedding<float>>(innerGenerator);
Embeddings\EmbeddingGeneratorExtensionsTests.cs (5)
17Assert.Throws<ArgumentNullException>("generator", () => EmbeddingGeneratorExtensions.GetService<string, Embedding<double>, object>(null!)); 31Embedding<float> result = new(new float[] { 1f, 2f, 3f }); 36Task.FromResult<GeneratedEmbeddings<Embedding<float>>>([result]) 50Embedding<float>[] embeddings = Enumerable 58Task.FromResult<GeneratedEmbeddings<Embedding<float>>>(new(embeddings))
Embeddings\EmbeddingTests.cs (10)
22Embedding<float> e = new(floats) 43Embedding<Half> e = new(halfs); 48Embedding<Half> result = Assert.IsType<Embedding<Half>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding)); 57Embedding<float> e = new(floats); 62Embedding<float> result = Assert.IsType<Embedding<float>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding)); 70Embedding<double> e = new(floats); 75Embedding<double> result = Assert.IsType<Embedding<double>>(JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.Embedding));
Embeddings\GeneratedEmbeddingsTests.cs (34)
19Assert.Throws<ArgumentNullException>("embeddings", () => new GeneratedEmbeddings<Embedding<float>>(null!)); 20Assert.Throws<ArgumentOutOfRangeException>("capacity", () => new GeneratedEmbeddings<Embedding<float>>(-1)); 26GeneratedEmbeddings<Embedding<float>>[] instances = 38Assert.False(((ICollection<Embedding<float>>)instance).IsReadOnly); 47instance.CopyTo(Array.Empty<Embedding<float>>(), 0); 57List<Embedding<float>> embeddings = 63var generatedEmbeddings = new GeneratedEmbeddings<Embedding<float>>(embeddings); 85var e = new Embedding<float>(new float[] { 7, 8, 9 }); 94GeneratedEmbeddings<Embedding<float>> embeddings = []; 115GeneratedEmbeddings<Embedding<float>> embeddings = []; 116var e = new Embedding<float>(new float[] { 1, 2, 3 }); 126GeneratedEmbeddings<Embedding<float>> embeddings = []; 128var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 129var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 141GeneratedEmbeddings<Embedding<float>> embeddings = []; 143var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 144var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 157GeneratedEmbeddings<Embedding<float>> embeddings = []; 159var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 160var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 180GeneratedEmbeddings<Embedding<float>> embeddings = []; 182var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 183var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 199GeneratedEmbeddings<Embedding<float>> embeddings = []; 201var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 202var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 207var e3 = new Embedding<float>(new float[] { 7, 8, 9 }); 217GeneratedEmbeddings<Embedding<float>> embeddings = []; 219var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 220var e2 = new Embedding<float>(new float[] { 4, 5, 6 }); 225var e3 = new Embedding<float>(new float[] { 7, 8, 9 }); 235GeneratedEmbeddings<Embedding<float>> embeddings = []; 237var e1 = new Embedding<float>(new float[] { 1, 2, 3 }); 238var e2 = new Embedding<float>(new float[] { 4, 5, 6 });
TestEmbeddingGenerator.cs (3)
11public sealed class TestEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>> 15public Func<IEnumerable<string>, EmbeddingGenerationOptions?, CancellationToken, Task<GeneratedEmbeddings<Embedding<float>>>>? GenerateAsyncCallback { get; set; } 19public Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.AzureAIInference (4)
AzureAIInferenceEmbeddingGenerator.cs (3)
26IEmbeddingGenerator<string, Embedding<float>> 85public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync( 92GeneratedEmbeddings<Embedding<float>> result = new(embeddings.Data.Select(e =>
AzureAIInferenceExtensions.cs (1)
24public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(
Microsoft.Extensions.AI.AzureAIInference.Tests (11)
AzureAIInferenceEmbeddingGeneratorIntegrationTests.cs (1)
10protected override IEmbeddingGenerator<string, Embedding<float>>? CreateEmbeddingGenerator() =>
AzureAIInferenceEmbeddingGeneratorTests.cs (10)
51IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = client.AsEmbeddingGenerator(model); 63Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 66using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator 72Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string, Embedding<float>>>()); 73Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string, Embedding<float>>>()); 74Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>()); 77Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 112using IEmbeddingGenerator<string, Embedding<float>> generator = new EmbeddingsClient(new("http://somewhere"), new AzureKeyCredential("key"), new() 128foreach (Embedding<float> e in response)
Microsoft.Extensions.AI.Integration.Tests (14)
CallCountingEmbeddingGenerator.cs (3)
13internal sealed class CallCountingEmbeddingGenerator(IEmbeddingGenerator<string, Embedding<float>> innerGenerator) 14: DelegatingEmbeddingGenerator<string, Embedding<float>>(innerGenerator) 20public override Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(
EmbeddingGeneratorIntegrationTests.cs (3)
27private readonly IEmbeddingGenerator<string, Embedding<float>>? _embeddingGenerator; 40protected abstract IEmbeddingGenerator<string, Embedding<float>>? CreateEmbeddingGenerator(); 176using IEmbeddingGenerator<string, Embedding<Half>> generator =
QuantizationEmbeddingGenerator.cs (8)
18, IEmbeddingGenerator<string, Embedding<Half>> 21private readonly IEmbeddingGenerator<string, Embedding<float>> _floatService; 23public QuantizationEmbeddingGenerator(IEmbeddingGenerator<string, Embedding<float>> floatService) 47private static BinaryEmbedding QuantizeToBinary(Embedding<float> embedding) 69async Task<GeneratedEmbeddings<Embedding<Half>>> IEmbeddingGenerator<string, Embedding<Half>>.GenerateAsync( 80private static Embedding<Half> QuantizeToHalf(Embedding<float> embedding)
Microsoft.Extensions.AI.Ollama (2)
OllamaEmbeddingGenerator.cs (2)
16public sealed class OllamaEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>> 79public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(
Microsoft.Extensions.AI.Ollama.Tests (11)
OllamaEmbeddingGeneratorIntegrationTests.cs (1)
10protected override IEmbeddingGenerator<string, Embedding<float>>? CreateEmbeddingGenerator() =>
OllamaEmbeddingGeneratorTests.cs (10)
30Assert.Same(generator, generator.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 32using IEmbeddingGenerator<string, Embedding<float>> pipeline = generator 38Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string, Embedding<float>>>()); 39Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string, Embedding<float>>>()); 40Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>()); 43Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 52using IEmbeddingGenerator<string, Embedding<float>> chatClient = new OllamaEmbeddingGenerator(endpoint, model); 80using IEmbeddingGenerator<string, Embedding<float>> generator = new OllamaEmbeddingGenerator("http://localhost:11434", "all-minilm", httpClient); 93foreach (Embedding<float> e in response)
Microsoft.Extensions.AI.OpenAI (4)
OpenAIClientExtensions.cs (2)
31public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(this OpenAIClient openAIClient, string modelId, int? dimensions = null) => 38public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(this EmbeddingClient embeddingClient, int? dimensions = null) =>
OpenAIEmbeddingGenerator.cs (2)
20public sealed class OpenAIEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>> 112public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.OpenAI.Tests (20)
OpenAIEmbeddingGeneratorIntegrationTests.cs (1)
10protected override IEmbeddingGenerator<string, Embedding<float>>? CreateEmbeddingGenerator() =>
OpenAIEmbeddingGeneratorTests.cs (19)
57IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = client.AsEmbeddingGenerator(model); 72IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = openAIClient.AsEmbeddingGenerator("model"); 74Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 81using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator 87Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string, Embedding<float>>>()); 88Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string, Embedding<float>>>()); 89Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>()); 92Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 99IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = openAIClient.AsEmbeddingGenerator(); 101Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 104using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator 110Assert.NotNull(pipeline.GetService<DistributedCachingEmbeddingGenerator<string, Embedding<float>>>()); 111Assert.NotNull(pipeline.GetService<CachingEmbeddingGenerator<string, Embedding<float>>>()); 112Assert.NotNull(pipeline.GetService<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>()); 115Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>()); 150using IEmbeddingGenerator<string, Embedding<float>> generator = new OpenAIClient(new ApiKeyCredential("apikey"), new OpenAIClientOptions 166foreach (Embedding<float> e in response)
Microsoft.Extensions.AI.Tests (36)
Embeddings\ConfigureOptionsEmbeddingGeneratorTests.cs (4)
16Assert.Throws<ArgumentNullException>("innerGenerator", () => new ConfigureOptionsEmbeddingGenerator<string, Embedding<float>>(null!, _ => { })); 17Assert.Throws<ArgumentNullException>("configure", () => new ConfigureOptionsEmbeddingGenerator<string, Embedding<float>>(new TestEmbeddingGenerator(), null!)); 35GeneratedEmbeddings<Embedding<float>> expectedEmbeddings = []; 38using IEmbeddingGenerator<string, Embedding<float>> innerGenerator = new TestEmbeddingGenerator
Embeddings\DistributedCachingEmbeddingGeneratorTest.cs (3)
17private readonly Embedding<float> _expectedEmbedding = new(new float[] { 1.0f, 2.0f, 3.0f }) 37return Task.FromResult<GeneratedEmbeddings<Embedding<float>>>([_expectedEmbedding]); 40using var outer = new DistributedCachingEmbeddingGenerator<string, Embedding<float>>(testGenerator, _storage)
Embeddings\EmbeddingGeneratorBuilderTests.cs (9)
19var builder = new EmbeddingGeneratorBuilder<string, Embedding<float>>(services => 60Assert.Throws<ArgumentNullException>("innerGenerator", () => new EmbeddingGeneratorBuilder<string, Embedding<float>>((IEmbeddingGenerator<string, Embedding<float>>)null!)); 61Assert.Throws<ArgumentNullException>("innerGenerator", () => ((IEmbeddingGenerator<string, Embedding<float>>)null!).AsBuilder()); 68() => new EmbeddingGeneratorBuilder<string, Embedding<float>>((Func<IServiceProvider, IEmbeddingGenerator<string, Embedding<float>>>)null!)); 81private sealed class InnerServiceCapturingEmbeddingGenerator(string name, IEmbeddingGenerator<string, Embedding<float>> innerGenerator) : 82DelegatingEmbeddingGenerator<string, Embedding<float>>(innerGenerator) 87public new IEmbeddingGenerator<string, Embedding<float>> InnerGenerator => base.InnerGenerator;
Embeddings\LoggingEmbeddingGeneratorTests.cs (4)
19Assert.Throws<ArgumentNullException>("innerGenerator", () => new LoggingEmbeddingGenerator<string, Embedding<float>>(null!, NullLogger.Instance)); 20Assert.Throws<ArgumentNullException>("logger", () => new LoggingEmbeddingGenerator<string, Embedding<float>>(new TestEmbeddingGenerator(), null!)); 35using IEmbeddingGenerator<string, Embedding<float>> innerGenerator = new TestEmbeddingGenerator 39return Task.FromResult(new GeneratedEmbeddings<Embedding<float>>([new Embedding<float>(new float[] { 1f, 2f, 3f })]));
Embeddings\UseDelegateEmbeddingGeneratorTests.cs (12)
18EmbeddingGeneratorBuilder<string, Embedding<float>> builder = new(generator); 21builder.Use((Func<IEnumerable<string>, EmbeddingGenerationOptions?, IEmbeddingGenerator<string, Embedding<float>>, CancellationToken, Task<GeneratedEmbeddings<Embedding<float>>>>)null!)); 24new AnonymousDelegatingEmbeddingGenerator<string, Embedding<float>>( 25null!, (values, options, innerGenerator, cancellationToken) => Task.FromResult(new GeneratedEmbeddings<Embedding<float>>(Array.Empty<Embedding<float>>())))); 28new AnonymousDelegatingEmbeddingGenerator<string, Embedding<float>>(generator, null!)); 34GeneratedEmbeddings<Embedding<float>> expectedEmbeddings = new(); 40using IEmbeddingGenerator<string, Embedding<float>> innerGenerator = new TestEmbeddingGenerator 52using IEmbeddingGenerator<string, Embedding<float>> generator = new EmbeddingGeneratorBuilder<string, Embedding<float>>(innerGenerator) 67GeneratedEmbeddings<Embedding<float>> actual = await generator.GenerateAsync(expectedValues, expectedOptions, expectedCts.Token);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestEmbeddingGenerator.cs (3)
11public sealed class TestEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>> 15public Func<IEnumerable<string>, EmbeddingGenerationOptions?, CancellationToken, Task<GeneratedEmbeddings<Embedding<float>>>>? GenerateAsyncCallback { get; set; } 19public Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
21[JsonSerializable(typeof(Embedding<float>))]