forked from dotnet/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmbeddingGenerationDispatcher{TEmbedding}.cs
More file actions
41 lines (34 loc) · 2.07 KB
/
Copy pathEmbeddingGenerationDispatcher{TEmbedding}.cs
File metadata and controls
41 lines (34 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
using Microsoft.Shared.DiagnosticIds;
namespace Microsoft.Extensions.VectorData.ProviderServices;
/// <summary>
/// A <see cref="EmbeddingGenerationDispatcher"/> implementation for a specific <typeparamref name="TEmbedding"/> type.
/// This is an internal support type meant for use by providers only and not by applications.
/// </summary>
/// <typeparam name="TEmbedding">The embedding type.</typeparam>
[Experimental(DiagnosticIds.Experiments.VectorDataEmbeddingGeneration, UrlFormat = DiagnosticIds.UrlFormat)]
public sealed class EmbeddingGenerationDispatcher<TEmbedding> : EmbeddingGenerationDispatcher
where TEmbedding : Embedding
{
/// <inheritdoc />
public override Type EmbeddingType => typeof(TEmbedding);
/// <inheritdoc />
public override Type? ResolveEmbeddingType(VectorPropertyModel vectorProperty, IEmbeddingGenerator embeddingGenerator, Type? userRequestedEmbeddingType)
=> vectorProperty.ResolveEmbeddingType<TEmbedding>(embeddingGenerator, userRequestedEmbeddingType);
/// <inheritdoc />
public override bool CanGenerateEmbedding(VectorPropertyModel vectorProperty, IEmbeddingGenerator embeddingGenerator)
=> vectorProperty.CanGenerateEmbedding<TEmbedding>(embeddingGenerator);
/// <inheritdoc />
public override Task<IReadOnlyList<Embedding>> GenerateEmbeddingsAsync(VectorPropertyModel vectorProperty, IEnumerable<object?> values, CancellationToken cancellationToken)
=> vectorProperty.GenerateEmbeddingsCoreAsync<TEmbedding>(values, cancellationToken);
/// <inheritdoc />
public override Task<Embedding> GenerateEmbeddingAsync(VectorPropertyModel vectorProperty, object? value, CancellationToken cancellationToken)
=> vectorProperty.GenerateEmbeddingCoreAsync<TEmbedding>(value, cancellationToken);
}