Artificial Intelligence
Granit integrates AI as an optional, provider-agnostic layer that enriches existing modules without modifying them. Every AI feature follows the same principle: existing modules define extension points with null-object defaults; AI packages provide smart implementations that activate via DI composition.
What you can do with Granit.AI
Section titled “What you can do with Granit.AI”| Capability | Module | What it does |
|---|---|---|
| Chat & generation | Granit.AI | Workspace-managed access to IChatClient (OpenAI, Azure OpenAI, Ollama) |
| Natural language query | Querying.AI | Users type “unpaid invoices from last week” → structured filters |
| Semantic search | AI.VectorData | Find documents by meaning, build RAG knowledge bases |
| Import mapping | DataExchange.AI | Automatically map messy CSV/Excel columns to your entity properties |
| Document extraction | AI.Extraction | Turn a PDF invoice into a typed InvoiceData C# record |
| Workflow decisions | Workflow.AI | AI recommends next transition, scores risk for auto-approval |
| Notification content | Notifications.AI | Generate message body + route to optimal channel |
| Timeline intelligence | Timeline.AI | Summarize audit trails, detect unusual activity patterns |
| PII detection | Privacy.AI | Scan free-text fields for personal data (GDPR compliance) |
| Content moderation | Validation.AI | Detect toxic content, harassment, prompt injection in user input |
| Blob classification | BlobStorage.AI | Tag uploaded files by category, detect PII in filenames |
| Access anomalies | Authorization.AI | Detect suspicious access patterns in permission checks |
| Log analysis | Observability.AI | Summarize error batches, surface root cause insights |
| Image analysis | Imaging.AI | Alt text generation, object detection, smart tagging |
Core design principles
Section titled “Core design principles”1. Provider-agnostic
Section titled “1. Provider-agnostic”Your application code depends on IChatClient (from Microsoft.Extensions.AI), not on
OpenAI or Anthropic. Swap providers per environment:
| Environment | Provider | Why |
|---|---|---|
| Development | Ollama | Free, local, no API key |
| Staging | OpenAI | Fast iteration, latest models |
| Production | Azure OpenAI | EU data residency, Managed Identity, DPA |
2. Soft dependency — zero coupling
Section titled “2. Soft dependency — zero coupling”AI packages reference existing modules, never the reverse:
graph LR
DE[Granit.DataExchange] -.->|defines ISemanticMappingService| NULL[NullService]
DEAI[Granit.DataExchange.AI] -->|implements| DE
DEAI --> AI[Granit.AI]
AI --> MEAI[Microsoft.Extensions.AI]
style NULL fill:#ffebee
style DEAI fill:#e8f5e9
Without the AI package installed, the module works normally. With it, AI activates.
3. GDPR & ISO 27001 by design
Section titled “3. GDPR & ISO 27001 by design”| Principle | How Granit.AI implements it |
|---|---|
| Data minimization | AI modules send only metadata to the LLM (column names, schema), never business data |
| Audit trail | Every AI interaction is logged (tenant, user, workspace, model, tokens, timestamp) |
| Right to erasure | Workspace and usage records support soft delete; vector embeddings are deletable |
| Data residency | Azure OpenAI for EU-only; Ollama for on-premise (data never leaves your server) |
| Opt-in for sensitive data | Preview rows in import mapping require explicit IncludePreviewRows: true |
4. Async-first (Wolverine)
Section titled “4. Async-first (Wolverine)”AI calls are slow (200ms to 15s). Granit uses Wolverine for async execution:
| Use case | Execution | Why |
|---|---|---|
| Natural language query | Synchronous (~200ms) | User is waiting for search results |
| Import mapping | Synchronous (5-10s) | User is in the wizard, waiting for suggestions |
| Content moderation | Synchronous (2s, fail-open) | Must validate before persistence; timeout never blocks |
| Access anomaly detection | Synchronous (2s, fail-open) | Runs after auth check; never blocks access |
| Document extraction | Async (Wolverine handler) | 5-15s, client gets 202 Accepted + push notification |
| Blob classification | Async (Wolverine handler) | Upload should not wait for classification |
| Notification content | Async (Wolverine handler) | Generated after notification is queued |
| Workflow auto-approval | Async (Wolverine handler) | Runs on ApprovalRequested event |
| Timeline summarization | Async (Wolverine handler) | On-demand or scheduled, never interactive |
| PII detection (batch) | Async (Wolverine handler) | Scanning existing records at scale |
| Log analysis | Async (cron job) | Scheduled, batch analysis |
| Image analysis | Async (Wolverine handler) | Triggered after upload |
| Vector indexing | Async (Wolverine handler) | Batch operation, no user waiting |
Quick start
Section titled “Quick start”The minimal setup to get AI working in your Granit application:
builder.AddGranitAI();builder.AddGranitAIOllama(); // zero config for local dev# Terminal: start Ollamaollama pull llama3.1ollama serveThen inject IAIChatClientFactory in any service:
public class MyService(IAIChatClientFactory chatFactory){ public async Task<string> AskAsync(string question, CancellationToken ct) { IChatClient client = await chatFactory .CreateAsync(cancellationToken: ct) .ConfigureAwait(false);
ChatResponse response = await client .GetResponseAsync(question, cancellationToken: ct) .ConfigureAwait(false);
return response.Text; }}Pages in this section
Section titled “Pages in this section”User experience
- Natural Language Query — search with plain language
- Semantic Search & RAG — vector-based similarity search and knowledge bases
Data ingestion
- Import Mapping — AI-powered column mapping for CSV/Excel imports
- Document Extraction — structured data extraction from PDFs
Business intelligence
- Workflow Decision Support — transition advisor and risk-based auto-approval
- Notification Intelligence — AI-generated content and smart channel routing
- Timeline Intelligence — audit trail summarization and anomaly detection
Security & compliance
- PII Detection — scan text for personal data
- Content Moderation — detect toxic content and prompt injection
- Blob Storage Intelligence — file classification and PII in filenames
- Access Anomaly Detection — detect suspicious access patterns
Operations
- Log Analysis — batch log analysis and root cause insights
- Image Analysis — alt text, object detection, smart tagging
For the core module reference (providers, workspaces, configuration), see Setup & Configuration.