Path: redb-route/redb.Route.Llm/Embeddings/EmbedComponent.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Llm/Embeddings/EmbedComponent.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Llm.Providers;
namespace redb.Route.Llm.Embeddings;
///
/// Embedding transport. Scheme: embed. Producer-only, symmetric with
/// llm://: To("embed://<connectionFactoryName>") turns the
/// exchange body (a text, or a collection of texts) into an embedding vector
/// (float[]) or vectors (float[][]) written to Out.Body.
///
/// The URI host names an (Provider / BaseUrl /
/// ApiKey / ModelId — set ModelId to the embedding model), so different
/// routes can pick different embedding models by name — the same lever as
/// llm://<factory>.
///
///
///
/// From("kafka://texts").To("embed://openai").To("vector://sink");
///
///
///
[EndpointRole(EndpointRole.Producer, Hint = "Use To(\"embed://\").")]
public sealed class EmbedComponent : ComponentBase
{
///
public override string Scheme => "embed";
///
/// Builds the from a resolved connection
/// factory. Defaults to ; override
/// for a custom provider or in tests.
///
public Func ProviderFactory { get; set; } =
OpenAiEmbeddingProvider.Create;
///
public override IEndpoint CreateEndpoint(EndpointUri uri)
{
ArgumentNullException.ThrowIfNull(uri);
var options = new EmbedEndpointOptions();
options.BindFromUri(uri.RawParameters);
options.Validate();
return new EmbedEndpoint(uri, this, options);
}
}
/// Options for an embed:// endpoint.
public sealed class EmbedEndpointOptions : EndpointOptions
{
/// Alternative to the URI host for the connection-factory name.
[RegistryReference(typeof(LlmConnectionFactory))]
public string? ConnectionFactory { get; set; }
///
public override void Validate() { }
}
/// Embedding endpoint. URI path = connection-factory name.
public sealed class EmbedEndpoint : EndpointBase
{
/// Connection-factory name (URI path or ?connectionFactory=).
public string FactoryName { get; }
/// Factory resolved from the route context (null when wired later).
internal LlmConnectionFactory? ResolvedFactory { get; }
/// Creates the endpoint.
public EmbedEndpoint(EndpointUri uri, EmbedComponent component, EmbedEndpointOptions options)
: base(uri, component, options)
{
FactoryName = !string.IsNullOrWhiteSpace(uri.Path) ? uri.Path : (options.ConnectionFactory ?? string.Empty);
if (string.IsNullOrWhiteSpace(FactoryName))
throw new InvalidOperationException(
"embed:// requires a connection factory — use 'embed://' or '?connectionFactory='.");
if (component.Context is not null)
ResolvedFactory = component.Context.GetFromRegistry(FactoryName);
}
///
public override IProducer CreateProducer() => new EmbedProducer(this, Options);
///
public override IConsumer CreateConsumer(IProcessor processor) =>
throw new NotSupportedException("embed:// is producer-only. Use To(\"embed://\").");
}