AiGeekSquad.AIContext.MEAI
1.0.18
See the version list below for details.
dotnet add package AiGeekSquad.AIContext.MEAI --version 1.0.18
NuGet\Install-Package AiGeekSquad.AIContext.MEAI -Version 1.0.18
<PackageReference Include="AiGeekSquad.AIContext.MEAI" Version="1.0.18" />
<PackageVersion Include="AiGeekSquad.AIContext.MEAI" Version="1.0.18" />
<PackageReference Include="AiGeekSquad.AIContext.MEAI" />
paket add AiGeekSquad.AIContext.MEAI --version 1.0.18
#r "nuget: AiGeekSquad.AIContext.MEAI, 1.0.18"
#:package AiGeekSquad.AIContext.MEAI@1.0.18
#addin nuget:?package=AiGeekSquad.AIContext.MEAI&version=1.0.18
#tool nuget:?package=AiGeekSquad.AIContext.MEAI&version=1.0.18
AiGeekSquad.AIContext.MEAI
A Microsoft Extensions AI Abstractions adapter for the AiGeekSquad.AIContext semantic chunking library.
Overview
This package provides seamless integration between Microsoft's AI abstractions (Microsoft.Extensions.AI.Abstractions
) and the AiGeekSquad.AIContext library. It allows you to use any embedding generator that implements Microsoft's IEmbeddingGenerator<TInput,TEmbedding>
interface with the AIContext semantic chunking functionality.
Purpose
The MicrosoftExtensionsAIEmbeddingGenerator
class acts as an adapter that:
- Implements the
AiGeekSquad.AIContext.Chunking.IEmbeddingGenerator
interface - Wraps any Microsoft Extensions AI embedding generator
- Converts between Microsoft's
Embedding<float>
format and Math.NET'sVector<double>
format - Enables seamless integration with AIContext's semantic text chunking capabilities
Installation
dotnet add package AiGeekSquad.AIContext.MEAI
Usage
Basic Usage
using AiGeekSquad.AIContext.MEAI;
using AiGeekSquad.AIContext.Chunking;
using Microsoft.Extensions.AI;
// Your Microsoft Extensions AI embedding generator
IEmbeddingGenerator<string, Embedding<float>> microsoftEmbeddingGenerator =
// ... initialize your Microsoft AI embedding generator
// Wrap it with the adapter
IEmbeddingGenerator aiContextEmbeddingGenerator =
new MicrosoftExtensionsAIEmbeddingGenerator(microsoftEmbeddingGenerator);
// Use with AIContext semantic chunking
var chunker = new SemanticTextChunker(
embeddingGenerator: aiContextEmbeddingGenerator,
// ... other parameters
);
var chunks = await chunker.ChunkTextAsync("Your text to chunk...");
With Dependency Injection
using Microsoft.Extensions.DependencyInjection;
using AiGeekSquad.AIContext.MEAI;
using AiGeekSquad.AIContext.Chunking;
var services = new ServiceCollection();
// Register your Microsoft Extensions AI embedding generator
services.AddSingleton<IEmbeddingGenerator<string, Embedding<float>>>(
// ... your embedding generator implementation
);
// Register the adapter
services.AddSingleton<IEmbeddingGenerator, MicrosoftExtensionsAIEmbeddingGenerator>();
// Register semantic chunker
services.AddSingleton<SemanticTextChunker>();
var serviceProvider = services.BuildServiceProvider();
var chunker = serviceProvider.GetRequiredService<SemanticTextChunker>();
Advanced Example with Options
using AiGeekSquad.AIContext.MEAI;
using AiGeekSquad.AIContext.Chunking;
// Create embedding generator with custom options
var embeddingGenerator = new MicrosoftExtensionsAIEmbeddingGenerator(microsoftGenerator);
// Configure chunking options
var chunkOptions = new ChunkOptions
{
MaxChunkSize = 1000,
OverlapSize = 100,
SimilarityThreshold = 0.7
};
// Create semantic chunker
var chunker = new SemanticTextChunker(
embeddingGenerator: embeddingGenerator,
options: chunkOptions
);
// Chunk your text
var text = "Your long document text here...";
var chunks = await chunker.ChunkTextAsync(text);
foreach (var chunk in chunks)
{
Console.WriteLine($"Chunk: {chunk.Text}");
Console.WriteLine($"Embedding: [{string.Join(", ", chunk.Embedding.Take(5))}...]");
}
Integration Benefits
By using this adapter, you can:
- Leverage Microsoft's AI Ecosystem: Use any embedding generator that follows Microsoft's AI abstractions
- Maintain Compatibility: Keep your existing AIContext semantic chunking code unchanged
- Future-Proof: Benefit from updates to both Microsoft's AI abstractions and AIContext libraries
- Performance: Take advantage of Microsoft's optimized embedding implementations
- Flexibility: Switch between different embedding providers without changing your chunking logic
Supported Operations
The adapter supports both single and batch embedding generation:
- Single Embedding:
GenerateEmbeddingAsync(string text)
- Batch Embeddings:
GenerateBatchEmbeddingsAsync(IEnumerable<string> texts)
Both methods convert from Microsoft's Embedding<float>
format to Math.NET's Vector<double>
format as required by the AIContext library.
Error Handling
The adapter provides comprehensive error handling:
- Null Argument Validation: Throws
ArgumentNullException
for null inputs - Operation Failures: Wraps underlying exceptions in
InvalidOperationException
with descriptive messages - Embedding Validation: Ensures embedding vectors are valid before conversion
Threading and Cancellation
The adapter fully supports:
- Async Operations: All methods are properly async
- Cancellation Tokens: Supports cancellation for long-running operations
- Thread Safety: Safe for concurrent use (inherits from underlying generator's thread safety)
Dependencies
Microsoft.Extensions.AI.Abstractions
(>= 9.7.0)AiGeekSquad.AIContext
(included as project reference)MathNet.Numerics
(transitively via AIContext)
Contributing
This package is part of the AiGeekSquad.AIContext project. For contributions, issues, or feature requests, please visit the main repository.
License
MIT License - see the main project for full license details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- AiGeekSquad.AIContext (>= 1.0.18)
- Microsoft.Extensions.AI.Abstractions (>= 9.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.