34 instantiations of Embedding
Aspire.Azure.AI.OpenAI.Tests (1)
Aspire.OpenAI.Tests (1)
Microsoft.Extensions.AI.Abstractions.Tests (26)
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)
Microsoft.Extensions.AI.Integration.Tests (1)
Microsoft.Extensions.AI.OpenAI (1)
Microsoft.Extensions.AI.Tests (3)
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)
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)
Microsoft.Extensions.AI.Abstractions (17)
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);
Microsoft.Extensions.AI.Abstractions.Tests (59)
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 });
Microsoft.Extensions.AI.AzureAIInference (4)
Microsoft.Extensions.AI.AzureAIInference.Tests (11)
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)
Microsoft.Extensions.AI.Ollama (2)
Microsoft.Extensions.AI.Ollama.Tests (11)
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)
Microsoft.Extensions.AI.OpenAI.Tests (20)
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\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\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);