FonsecaFramework.Ai
2026.6.18.1
dotnet add package FonsecaFramework.Ai --version 2026.6.18.1
NuGet\Install-Package FonsecaFramework.Ai -Version 2026.6.18.1
<PackageReference Include="FonsecaFramework.Ai" Version="2026.6.18.1" />
<PackageVersion Include="FonsecaFramework.Ai" Version="2026.6.18.1" />
<PackageReference Include="FonsecaFramework.Ai" />
paket add FonsecaFramework.Ai --version 2026.6.18.1
#r "nuget: FonsecaFramework.Ai, 2026.6.18.1"
#:package FonsecaFramework.Ai@2026.6.18.1
#addin nuget:?package=FonsecaFramework.Ai&version=2026.6.18.1
#tool nuget:?package=FonsecaFramework.Ai&version=2026.6.18.1
FonsecaFramework.Ai
AI and machine learning utilities for .NET applications.
Overview
FonsecaFramework.Ai is a .NET 9 library that provides tools for building ML models with AutoML, performing sentiment/discourse analysis, implementing RAG (Retrieval-Augmented Generation) vector stores, and integrating with LLM providers via the Microsoft.Extensions.AI abstraction. It wraps ML.NET and ONNX Runtime to offer a streamlined API for training, predicting, and exporting models.
Installation
dotnet add package FonsecaFramework.Ai
Features
| Area | Key Classes |
|---|---|
| AutoML Model Building | AiModelBuilder<T> — build regression, classification, ranking, and recommendation models with ML.NET AutoML |
| Trained Model | AiModel<T, TMetrics> — make predictions and export to ONNX format |
| RAG Vector Store | RagVectorStore — chunk documents, build TF-IDF + discourse vectors, and retrieve context for LLM prompts |
| Agent Framework RAG Bridge | RagVectorStore.CreateTextSearchProvider(...) — expose store retrieval through Microsoft.Agents.AI.TextSearchProvider |
| RAG Snapshots | RagVectorStoreSnapshot — serialize/deserialize a vector store to avoid re-processing documents |
| Sentiment Analysis | ISentimentAnalyzer — 10-element discourse vector interface |
LexiconSentimentAnalyzer — fast, deterministic, lexicon-based analyzer (no external service required) |
|
OllamaSentimentAnalyzer — LLM-powered analyzer via IChatClient with lexicon fallback |
|
| LLM Chat Client | VLRChatClient — IChatClient implementation for OpenAI-compatible endpoints (e.g. Ollama) with streaming support |
Examples
Build and Use a Regression Model
using FonsecaFramework.Ai;
var data = new List<HouseData>
{
new() { Size = 1000, Price = 200_000 },
new() { Size = 1500, Price = 300_000 },
new() { Size = 2000, Price = 400_000 },
// ... more training data
};
var builder = new AiModelBuilder<HouseData>(data, nameof(HouseData.Price));
var model = builder.BuildRegressionModel(
MaxExperimentTimeInSeconds: 30);
float prediction = model.Predict(new HouseData { Size = 1750 });
Console.WriteLine($"Predicted price: {prediction:C}");
// Export to ONNX
await model.ConvertToOnnx("house-model.onnx");
Build a Binary Classification Model
using FonsecaFramework.Ai;
var data = new List<EmailData>
{
new() { Subject = "Free money!", Body = "Click here now", IsSpam = true },
new() { Subject = "Meeting tomorrow", Body = "See you at 3pm", IsSpam = false },
// ... more training data
};
var builder = new AiModelBuilder<EmailData>(data, nameof(EmailData.IsSpam));
var model = builder.BuildBinaryClassificationModel(MaxExperimentTimeInSeconds: 60);
float score = model.Predict(new EmailData { Subject = "You won!", Body = "Claim prize" });
Console.WriteLine($"Spam score: {score}");
RAG Vector Store — Build and Query
using FonsecaFramework.Ai;
// Build from a folder of .txt documents
var store = await RagVectorStore.Build(
sourceFolder: "./docs",
chunkSize: 512,
chunkOverlap: 128);
// Augment a user prompt with relevant context
string augmentedPrompt = await store.Lookup(
prompt: "How do I configure the database?",
topK: 3);
Console.WriteLine(augmentedPrompt);
// The prompt now includes the most relevant document chunks as context
RAG with LLM-Powered Sentiment Analysis
using FonsecaFramework.Ai;
using FonsecaFramework.Ai.LLM;
// Use Ollama for richer discourse analysis
var chatClient = new VLRChatClient("http://localhost:11434");
var sentimentAnalyzer = new OllamaSentimentAnalyzer(chatClient);
var store = await RagVectorStore.Build(
sourceFolder: "./docs",
sentimentAnalyzer: sentimentAnalyzer);
// Filter by discourse category
string result = await store.Lookup(
prompt: "What safety precautions should I take?",
topK: 5,
sentimentFilter: "cautionary");
Agent Framework Integration (TextSearchProvider)
using FonsecaFramework.Ai;
using Microsoft.Agents.AI;
var store = await RagVectorStore.Build("./docs");
// Basic wrapper for Microsoft Agent Framework RAG pattern
var provider = store.CreateTextSearchProvider(
options: new TextSearchProviderOptions
{
SearchTime = TextSearchProviderOptions.TextSearchBehavior.BeforeAIInvoke
},
topK: 3,
minSimilarity: 0.05);
// Optional: direct adapter usage if you need raw search results
var results = await store.SearchTextResultsAsync("refund policy", topK: 3);
Sentiment / Discourse Analysis
using FonsecaFramework.Ai;
var analyzer = new LexiconSentimentAnalyzer();
float[] vector = await analyzer.AnalyzeAsync(
"Warning: Do not operate the machine without safety equipment.");
// vector is a 10-element array:
// [positive, negative, instructional, technical, cautionary,
// informational, urgency, formality, specificity, actionability]
string category = analyzer.Classify(vector);
Console.WriteLine($"Dominant category: {category}"); // "cautionary"
VLRChatClient — OpenAI-Compatible LLM Integration
using FonsecaFramework.Ai.LLM;
using Microsoft.Extensions.AI;
using var client = new VLRChatClient("http://localhost:11434");
var messages = new[]
{
new ChatMessage(ChatRole.System, "You are a helpful assistant."),
new ChatMessage(ChatRole.User, "Explain dependency injection in one paragraph.")
};
var response = await client.GetResponseAsync(messages);
Console.WriteLine(response.Text);
Requirements
- .NET 9.0
- For
OllamaSentimentAnalyzer/VLRChatClient: an OpenAI-compatible LLM endpoint (e.g. Ollama)
License
Copyright 2025 Steven Fonseca / VLR Creations
Licensed under the Apache License, Version 2.0. You may use this library free of charge, provided you include the required attribution notices. See the LICENSE file for full terms.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Azure.Identity (>= 1.21.0)
- FonsecaFramework (>= 2026.6.18.1)
- MathNet.Numerics (>= 5.0.0)
- Microsoft.Agents.AI (>= 1.10.0)
- Microsoft.Bcl.Memory (>= 10.0.9)
- Microsoft.Data.SqlClient (>= 7.0.1)
- Microsoft.Extensions.AI (>= 10.7.0)
- Microsoft.Extensions.ML (>= 5.0.0)
- Microsoft.ML (>= 5.0.0)
- Microsoft.ML.AutoML (>= 0.23.0)
- Microsoft.ML.OnnxConverter (>= 0.23.0)
- Microsoft.ML.OnnxRuntime (>= 1.26.0)
- Microsoft.ML.OnnxTransformer (>= 5.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FonsecaFramework.Ai:
| Package | Downloads |
|---|---|
|
FonsecaFramework.Asp
Base Classes for Asp.Net Core |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.18.1 | 134 | 6/18/2026 |
| 2026.6.13.1 | 132 | 6/13/2026 |
| 2026.6.4.2 | 138 | 6/4/2026 |
| 2026.6.4.1 | 129 | 6/4/2026 |
| 2026.6.3.3 | 139 | 6/4/2026 |
| 2026.6.3.2 | 140 | 6/4/2026 |
| 2026.6.3.1 | 137 | 6/3/2026 |
| 2026.5.21.1 | 137 | 5/22/2026 |
| 2026.5.20.1 | 142 | 5/20/2026 |
| 2026.5.12.1 | 144 | 5/13/2026 |
| 2026.5.11.1 | 146 | 5/11/2026 |
| 2026.5.7.2 | 143 | 5/7/2026 |
| 2026.5.7.1 | 138 | 5/7/2026 |
| 2026.5.6.1 | 121 | 5/6/2026 |
| 2026.5.5.1 | 124 | 5/5/2026 |
| 2026.5.2.1 | 123 | 5/2/2026 |
| 2026.4.30.1 | 118 | 4/30/2026 |
| 2026.4.29.1 | 150 | 4/29/2026 |
| 2026.4.27.1 | 128 | 4/28/2026 |
| 2026.4.22.1 | 116 | 4/22/2026 |