Overview
Prismatic Ollama provides the platform's local AI inference capability through integration with Ollama. It enables sovereign, on-premise language model usage without sending data to external cloud providers. The module manages model lifecycle, request routing, response processing, and quality gate enforcement for AI-generated outputs.
Data sovereignty is a fundamental requirement for intelligence platforms handling sensitive OSINT, legal, and financial data. Prismatic Ollama ensures that no query or context data leaves the organization's infrastructure during AI-assisted analysis. Combined with the platform's NABLA epistemic framework, it provides AI capabilities where outputs are treated as signals requiring the same confidence scoring, provenance tracking, and multi-source validation as any other intelligence source.
Model Management
Coordinator Agent
The Ollama Coordinator Agent (AIAD-compliant) manages the full model lifecycle:
Model Discovery --> Health Check --> Load/Unload --> Request Routing --> Quality Gate
| | | | |
ollama list Memory check Memory-aware Best model for Pass/fail
API call + latency test scheduling task type + fallback
| Coordinator Function | Description | Automation |
| Auto-Discovery | Detect available models on startup | Startup hook |
| Health Monitoring | Periodic latency and accuracy testing | Every 60s |
| Memory Management | Load/unload models based on memory pressure | Threshold-based |
| Version Tracking | Track model versions, trigger re-evaluation on update | On model pull |
| Failover | Automatic cloud fallback when local models unavailable | Circuit breaker |
Model Registry
{:ok, models} = PrismaticOllama.list_models()
[
%{name: "qwen3-coder", size: "7B", status: :loaded, memory_mb: 7200,
capabilities: [:code_generation, :code_review, :refactoring]},
%{name: "gpt-oss:20b", size: "20B", status: :available, memory_mb: 15800,
capabilities: [:general_intelligence, :analysis, :summarization]},
%{name: "deepseek-coder", size: "6.7B", status: :loaded, memory_mb: 6900,
capabilities: [:code_analysis, :bug_detection, :documentation]}
]
Supported Models
| Model | Size | Response Time | Memory | Primary Use | Accuracy |
| qwen3-coder | 7B | < 3s | < 8GB | Code generation, review | > 85% |
| gpt-oss:20b | 20B | < 5s | < 16GB | General intelligence, analysis | > 90% |
| deepseek-coder | 6.7B | < 3s | < 8GB | Code analysis, bug detection | > 85% |
Cloud Fallback Architecture
When local models are unavailable or insufficient for a task, the coordinator transparently routes to cloud providers:
Request --> Local Model Available? --> YES --> Local Inference --> Quality Gate --> Result
|
NO (or quality gate fails)
|
Cloud Fallback --> Cloud API --> Quality Gate --> Result
|
Circuit Breaker monitors failure rate
| Fallback Trigger | Condition | Recovery |
| Model Unavailable | Ollama not running or model not pulled | Auto-pull attempt, then cloud |
| Memory Pressure | System memory > 90% | Unload model, use cloud |
| Quality Gate Failure | Local output below quality threshold | Retry with cloud model |
| Timeout | Response time exceeds 30s | Cancel local, route to cloud |
| Repeated Failures | 3+ consecutive failures | Circuit breaker opens for 60s |
Cloud Provider Configuration
config :prismatic_ollama, :cloud_fallback,
enabled: true,
providers: [
%{name: :anthropic, model: "claude-sonnet-4-20250514", priority: 1},
%{name: :openai, model: "gpt-4o", priority: 2}
],
circuit_breaker: %{
failure_threshold: 3,
reset_timeout_ms: 60_000
}
Inference Pipeline
Request Processing
{:ok, code} = PrismaticOllama.generate("Write an Elixir GenServer for rate limiting",
model: "qwen3-coder",
template: :code_generation,
variables: %{language: "Elixir", pattern: "GenServer"},
max_tokens: 2000,
temperature: 0.3
)
{:ok, analysis} = PrismaticOllama.analyze(source_code,
model: "deepseek-coder",
task: :quality_review,
criteria: [:credo_compliance, :otp_patterns, :typespec_coverage]
)
{:ok, entities} = PrismaticOllama.extract(text,
model: "gpt-oss:20b",
schema: %{
entities: [%{name: :string, type: :enum, confidence: :float}],
relationships: [%{source: :string, target: :string, type: :string}]
}
)
Pipeline Stages
| Stage | Function | Implementation |
| Template Resolution | Apply prompt template with variables | ETS-cached templates |
| Model Selection | Choose best model for task type | Capability matching + load balancing |
| Request Dispatch | Send to Ollama HTTP API | Finch HTTP client with streaming |
| Response Parsing | Extract structured data from output | Schema-guided parsing with fallback |
| Quality Gate | Validate output meets quality standards | Task-specific validation rules |
| Result Caching | Cache results for identical prompts | Content-hash based with TTL |
Quality Gate Enforcement
AI-generated outputs are treated as untrusted signals requiring validation:
| Quality Check | Description | Failure Action |
| Schema Compliance | Output matches expected structure | Retry with stricter prompt |
| Factual Grounding | Claims reference verifiable data | Flag as ungrounded |
| Code Compilation | Generated code compiles without errors | Retry with error context |
| Credo Compliance | Generated code passes Credo strict | Auto-fix or retry |
| Confidence Scoring | AI self-reported confidence meets threshold | Route to larger model or cloud |
| NABLA Integration | Output treated as signal, not truth | Signal Plurality requirement |
NABLA Epistemic Integration
AI outputs are integrated into the belief graph as signals with explicit provenance:
signal = %{
source: :ollama,
model: "qwen3-coder",
model_version: "2024.11",
confidence: 0.82,
provenance: %{
prompt_hash: "sha256:...",
model_id: "qwen3-coder:latest",
inference_time_ms: 2340,
temperature: 0.3
}
}
| Metric | Target | Current | Measurement |
| Response Time (7B) | < 3s | 2.1s avg | Telemetry p50 |
| Response Time (20B) | < 5s | 4.2s avg | Telemetry p50 |
| Memory Usage | < 8GB per 7B model | 7.2GB | :erlang.memory/0 |
| Uptime | > 99% | 99.7% | Health check monitoring |
| Quality Gate Pass Rate | > 85% | 88% | Gate telemetry |
| Cloud Fallback Rate | < 5% | 2.3% | Routing telemetry |
Architecture
Request --> Prompt Template --> Model Selector --> Ollama API --> Response Parser --> Quality Gate --> Result
| | | | |
Variable Capability + HTTP/Stream Structured Pass/Fail
Injection Load Balance via Finch Extraction + Fallback
| Component | Implementation |
| Coordinator | GenServer with ETS-backed model registry |
| HTTP Client | Finch with connection pooling and streaming |
| Templates | ETS-cached prompt templates with hot reload |
| Quality Gates | Configurable validation pipeline per task type |
| Circuit Breaker | Auto-opens after 3 failures, resets after 60s |
| Telemetry | Full event coverage for inference, quality, routing |
Integration Points
- NABLA Axioms -- AI outputs treated as signals with provenance tracking and confidence scoring
- Multi-Paradigm Solving -- Multiple model capabilities (code, analysis, extraction) unified in single pipeline
- Autonomous Self-Healing -- Automatic cloud fallback when local models are unavailable or fail quality gates
Connect & Contribute
Created by Tomáš Korcak (korczis) | Open Source under GHL