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)
179 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 (20)
AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs (20)
36var generator = useKeyed ?
37host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
38host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
66var generator = useKeyed ?
67host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
68host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
94var generator = useKeyed ?
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>>>();
187var generator = useKeyed ?
188host.Services.GetRequiredKeyedService<IEmbeddingGenerator<string, Embedding<float>>>("openai_embeddinggenerator") :
189host.Services.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();
214var generator = useKeyed ?
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)
Microsoft.Extensions.AI (46)
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;
25public EmbeddingGeneratorBuilder(IEmbeddingGenerator<TInput, TEmbedding> innerGenerator)
33public EmbeddingGeneratorBuilder(Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory)
39/// 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.
42/// The <see cref="IServiceProvider"/> that should provide services to the <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> instances.
45/// <returns>An instance of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the entire pipeline.</returns>
46public IEmbeddingGenerator<TInput, TEmbedding> Build(IServiceProvider? services = null)
49var embeddingGenerator = _innerGeneratorFactory(services);
58$"The {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} entry at index {i} returned null. " +
59$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} instances.");
69public EmbeddingGeneratorBuilder<TInput, TEmbedding> Use(Func<IEmbeddingGenerator<TInput, TEmbedding>, IEmbeddingGenerator<TInput, TEmbedding>> generatorFactory)
80Func<IEmbeddingGenerator<TInput, TEmbedding>, IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> generatorFactory)
91/// an implementation for <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/>.
94/// A delegate that provides the implementation for <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/>.
99Func<IEnumerable<TInput>, EmbeddingGenerationOptions?, IEmbeddingGenerator<TInput, TEmbedding>, CancellationToken, Task<GeneratedEmbeddings<TEmbedding>>>? generateFunc)
Embeddings\EmbeddingGeneratorBuilderServiceCollectionExtensions.cs (9)
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>
22IEmbeddingGenerator<TInput, TEmbedding> innerGenerator)
30/// <param name="innerGeneratorFactory">A callback that produces the inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
35Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory)
51/// <param name="innerGenerator">The inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
57IEmbeddingGenerator<TInput, TEmbedding> innerGenerator)
66/// <param name="innerGeneratorFactory">A callback that produces the inner <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> that represents the underlying backend.</param>
72Func<IServiceProvider, IEmbeddingGenerator<TInput, TEmbedding>> innerGeneratorFactory)
Microsoft.Extensions.AI.Abstractions (25)
Embeddings\EmbeddingGeneratorExtensions.cs (11)
15/// <summary>Provides a collection of static methods for extending <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> instances.</summary>
18/// <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.
29public static TService? GetService<TInput, TEmbedding, TService>(this IEmbeddingGenerator<TInput, TEmbedding> generator, object? serviceKey = null)
43/// <summary>Asks the <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> for an object of type <typeparamref name="TService"/>.</summary>
50/// <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/>, including itself or any services it might be wrapping.
52public static TService? GetService<TService>(this IEmbeddingGenerator<string, Embedding<float>> generator, object? serviceKey = null) =>
68this IEmbeddingGenerator<TInput, Embedding<TEmbedding>> generator,
88/// This operations is equivalent to using <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/> with a
93this IEmbeddingGenerator<TInput, TEmbedding> generator,
129this IEmbeddingGenerator<TInput, TEmbedding> generator,
Embeddings\IEmbeddingGenerator.cs (7)
16/// Unless otherwise specified, all members of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> are thread-safe for concurrent use.
17/// It is expected that all implementations of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> support being used by multiple requests concurrently.
20/// However, implementations of <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> may mutate the arguments supplied to
23/// invocations or should otherwise ensure by construction that no <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> instances
40/// <summary>Gets metadata that describes the <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/>.</summary>
43/// <summary>Asks the <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> for an object of the specified type <paramref name="serviceType"/>.</summary>
49/// <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/>, including itself or any services it might be wrapping.
Microsoft.Extensions.AI.Abstractions.Tests (3)
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>> chatClient = new OllamaEmbeddingGenerator(endpoint, model);
80using 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);
72IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = openAIClient.AsEmbeddingGenerator("model");
74Assert.Same(embeddingGenerator, embeddingGenerator.GetService<IEmbeddingGenerator<string, Embedding<float>>>());
81using IEmbeddingGenerator<string, Embedding<float>> pipeline = embeddingGenerator
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
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
Microsoft.Extensions.AI.Tests (11)
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;