8 implementations of IEmbeddingGenerator
Microsoft.Extensions.AI.Abstractions (1)
Microsoft.Extensions.AI.Abstractions.Tests (1)
Microsoft.Extensions.AI.AzureAIInference (1)
Microsoft.Extensions.AI.Integration.Tests (2)
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.OpenAI (1)
Microsoft.Extensions.AI.Tests (1)
197 references to IEmbeddingGenerator
Aspire.Azure.AI.OpenAI.Tests (20)
AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (20)
35var generator = useKeyed ?
36host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
37host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
65var generator = useKeyed ?
66host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
67host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
93var generator = useKeyed ?
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>>>();
186var generator = useKeyed ?
187host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
188host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
213var generator = useKeyed ?
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)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (23)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (23)
38var generator = useKeyed ?
39host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
40host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
68var generator = useKeyed ?
69host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
70host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
96var generator = useKeyed ?
97host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
98host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
128host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
129host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
159host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
160host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
189var generator = useKeyed ?
190host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
191host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
216var generator = useKeyed ?
217host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
218host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
249var generator = useKeyed ?
250host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
251host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
268private Task<GeneratedEmbeddings<Embedding<float>>> TestMiddleware(IEnumerable<string> inputs, EmbeddingGenerationOptions? options, IEmbeddingGenerator<string, Embedding<float>> nextAsync, CancellationToken cancellationToken)
Microsoft.Extensions.AI (50)
Embeddings\AnonymousDelegatingEmbeddingGenerator.cs (3)
19private readonly Func<IEnumerable<TInput>, EmbeddingGenerationOptions?, IEmbeddingGenerator<TInput, TEmbedding>, CancellationToken, Task<GeneratedEmbeddings<TEmbedding>>> _generateFunc;
27IEmbeddingGenerator<TInput, TEmbedding> innerGenerator,
28Func<IEnumerable<TInput>, EmbeddingGenerationOptions?, IEmbeddingGenerator<TInput, TEmbedding>, CancellationToken, Task<GeneratedEmbeddings<TEmbedding>>> generateFunc)
Embeddings\EmbeddingGeneratorBuilder.cs (20)
12/// <summary>A builder for creating pipelines of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/>.</summary>
18private readonly Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> _innerGeneratorFactory;
21private List<Func<IEmbeddingGenerator<TInput, TEmbedding>, IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>>>? _generatorFactories;
26public EmbeddingGeneratorBuilder(IEmbeddingGenerator<TInput, TEmbedding> innerGenerator)
34public EmbeddingGeneratorBuilder(Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory)
40/// Builds an <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the entire pipeline. Calls to this instance will pass through each of the pipeline stages in turn.
43/// The <see cref="IServiceProvider"/> that should provide services to the <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> instances.
46/// <returns>An instance of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the entire pipeline.</returns>
47public IEmbeddingGenerator<TInput, TEmbedding> Build(IServiceProvider? services = null)
50var embeddingGenerator = _innerGeneratorFactory(services);
61$"The {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} entry at index {i} returned null. " +
62$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} instances.");
74public EmbeddingGeneratorBuilder<TInput, TEmbedding> Use(Func<IEmbeddingGenerator<TInput, TEmbedding>, IEmbeddingGenerator<TInput, TEmbedding>> generatorFactory)
86Func<IEmbeddingGenerator<TInput, TEmbedding>, IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> generatorFactory)
97/// an implementation for <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/>.
100/// A delegate that provides the implementation for <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/>.
105Func<IEnumerable<TInput>, EmbeddingGenerationOptions?, IEmbeddingGenerator<TInput, TEmbedding>, CancellationToken, Task<GeneratedEmbeddings<TEmbedding>>>? generateFunc)
Embeddings\EmbeddingGeneratorBuilderServiceCollectionExtensions.cs (13)
10/// <summary>Provides extension methods for registering <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> with a <see cref="IServiceCollection"/>.</summary>
17/// <param name="innerGenerator">The inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
25IEmbeddingGenerator<TInput, TEmbedding> innerGenerator,
39/// <param name="innerGeneratorFactory">A callback that produces the inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
47Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory,
55serviceCollection.Add(new ServiceDescriptor(typeof(IEmbeddingGenerator<TInput, TEmbedding>), builder.Build, lifetime));
57static services => services.GetRequiredService<IEmbeddingGenerator<TInput, TEmbedding>>(), lifetime));
66/// <param name="innerGenerator">The inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
75IEmbeddingGenerator<TInput, TEmbedding> innerGenerator,
90/// <param name="innerGeneratorFactory">A callback that produces the inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
99Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory,
107serviceCollection.Add(new ServiceDescriptor(typeof(IEmbeddingGenerator<TInput, TEmbedding>), serviceKey, factory: (services, serviceKey) => builder.Build(services), lifetime));
109static (services, serviceKey) => services.GetRequiredKeyedService<IEmbeddingGenerator<TInput, TEmbedding>>(serviceKey), lifetime));
Microsoft.Extensions.AI.Abstractions (25)
Embeddings\EmbeddingGeneratorExtensions.cs (11)
16/// <summary>Provides a collection of static methods for extending <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> instances.</summary>
19/// <summary>Asks the <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> for an object of type <typeparamref name="TService"/>.</summary>
27/// <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/>, including itself or any services it might be wrapping.
38/// Asks the <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> for an object of the specified type <paramref name="serviceType"/>
50/// <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/>, including itself or any services it might be wrapping.
64/// Asks the <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> for an object of type <typeparamref name="TService"/>
75/// <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/>, including itself or any services it might be wrapping.
106this IEmbeddingGenerator<TInput, Embedding<TEmbeddingElement>> generator,
129/// This operations is equivalent to using <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/> with a
134this IEmbeddingGenerator<TInput, TEmbedding> generator,
179this IEmbeddingGenerator<TInput, TEmbedding> generator,
Microsoft.Extensions.AI.Abstractions.Tests (7)
Microsoft.Extensions.AI.AzureAIInference (4)
Microsoft.Extensions.AI.AzureAIInference.Tests (7)
Microsoft.Extensions.AI.Integration.Tests (10)
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.Ollama.Tests (6)
OllamaEmbeddingGeneratorTests.cs (5)
30Assert.Same(generator, generator.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
32using IEmbeddingGenerator<string, Embedding<float>> pipeline = generator
43Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
52using IEmbeddingGenerator<string, Embedding<float>> generator = new OllamaEmbeddingGenerator(endpoint, model);
81using IEmbeddingGenerator<string, Embedding<float>> generator = new OllamaEmbeddingGenerator("http://localhost:11434", "all-minilm", httpClient);
Microsoft.Extensions.AI.OpenAI (7)
Microsoft.Extensions.AI.OpenAI.Tests (11)
OpenAIEmbeddingGeneratorTests.cs (10)
57IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = client.AsEmbeddingGenerator(model);
73IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = openAIClient.AsEmbeddingGenerator("model");
75Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
82using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator
93Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
100IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = openAIClient.AsEmbeddingGenerator();
102Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
105using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator
116Assert.IsType<OpenTelemetryEmbeddingGenerator<string, Embedding<float>>>(pipeline.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
151using IEmbeddingGenerator<string, Embedding<float>> generator = new OpenAIClient(new ApiKeyCredential("apikey"), new OpenAIClientOptions
Microsoft.Extensions.AI.Tests (18)
Embeddings\EmbeddingGeneratorBuilderTests.cs (5)
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) :
87public new IEmbeddingGenerator<string, Embedding<float>> InnerGenerator => base.InnerGenerator;