AiGeekSquad.AIContext.MEAI 1.0.18

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AiGeekSquad.AIContext.MEAI" Version="1.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AiGeekSquad.AIContext.MEAI" Version="1.0.18" />
                    
Directory.Packages.props
<PackageReference Include="AiGeekSquad.AIContext.MEAI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AiGeekSquad.AIContext.MEAI --version 1.0.18
                    
#r "nuget: AiGeekSquad.AIContext.MEAI, 1.0.18"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AiGeekSquad.AIContext.MEAI@1.0.18
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AiGeekSquad.AIContext.MEAI&version=1.0.18
                    
Install as a Cake Addin
#tool nuget:?package=AiGeekSquad.AIContext.MEAI&version=1.0.18
                    
Install as a Cake Tool

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's Vector<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:

  1. Leverage Microsoft's AI Ecosystem: Use any embedding generator that follows Microsoft's AI abstractions
  2. Maintain Compatibility: Keep your existing AIContext semantic chunking code unchanged
  3. Future-Proof: Benefit from updates to both Microsoft's AI abstractions and AIContext libraries
  4. Performance: Take advantage of Microsoft's optimized embedding implementations
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.26 0 7/22/2025
1.0.25 0 7/22/2025
1.0.24 0 7/22/2025
1.0.21 0 7/22/2025
1.0.20 0 7/21/2025
1.0.19 59 7/11/2025
1.0.18 53 7/11/2025
1.0.17 67 7/11/2025
1.0.16 67 7/11/2025
1.0.15 70 7/11/2025