feat: Intelligence Pipeline v3 — full implementation

Multi-stage evidence-grounded inference architecture replacing the
monolithic 9B model extraction pipeline. CPU-first specialist services
handle routine extraction while the 9B vLLM model is preserved for
semantic adjudication of ambiguous cases.

Key components:
- Capability-aware inference gateway (OpenAI-compatible + Ollama)
- Endpoint registry with DB migrations and REST API
- Sentence-aware document segmenter (property tests)
- Deterministic financial parsing with offset integrity
- Symbol resolution with ambiguity detection
- Specialist service (GLiNER2, dynamic batching, K8s deployment)
- Company-specific sentiment (FinBERT, calibration)
- Retrieval-based novelty and duplicate detection
- Confidence calibration pipeline
- Deterministic routing engine (property tests)
- 9B adjudication layer with VRAM gating
- Stock-specific impact model (features, labels, baseline, trained)
- Pipeline orchestrator (state machine, queues, leases, feature flags)
- Bounded parallelism (async workers, semaphore, load shedding)
- Observability (tracing, metrics, alerts)
- Compatibility adapter (v3→v2 golden mapping tests)
- Shadow/canary promotion framework
- Active learning and fine-tuning pipeline

Test results: 1,161 tests pass, ruff lint clean.
All 282 spec tasks completed.
This commit is contained in:
Celes Renata
2026-07-13 02:14:59 +00:00
parent 84634a365e
commit a72f336ad1
227 changed files with 50403 additions and 0 deletions
@@ -0,0 +1,108 @@
{{- if .Values.specialist }}
{{- if .Values.specialist.enabled }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: specialist
namespace: {{ .Release.Namespace }}
labels:
app: specialist
{{- include "stonks.labels" . | nindent 4 }}
stonks-oracle/tier: processing
spec:
replicas: {{ .Values.specialist.replicas | default 2 }}
selector:
matchLabels:
app: specialist
template:
metadata:
labels:
app: specialist
stonks-oracle/tier: processing
spec:
automountServiceAccountToken: false
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- include "stonks.podSecurityContext" . | nindent 8 }}
containers:
- name: specialist
image: {{ .Values.image.registry }}/specialist:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["sh", "-c", "uvicorn services.specialist.app:app --host 0.0.0.0 --port 8000"]
ports:
- containerPort: 8000
env:
- name: SPECIALIST_MODEL
value: {{ .Values.specialist.model | default "urchade/gliner_large-v2.1" | quote }}
- name: SPECIALIST_MAX_BATCH_SIZE
value: {{ .Values.specialist.maxBatchSize | default "32" | quote }}
- name: SPECIALIST_MAX_WAIT_MS
value: {{ .Values.specialist.maxWaitMs | default "50.0" | quote }}
- name: SPECIALIST_MAX_QUEUE_SIZE
value: {{ .Values.specialist.maxQueueSize | default "256" | quote }}
- name: SPECIALIST_TEST_MODE
value: {{ .Values.specialist.testMode | default "0" | quote }}
securityContext:
{{- include "stonks.containerSecurityContext" . | nindent 12 }}
envFrom:
- configMapRef:
name: stonks-config
{{- range .Values.specialist.secrets }}
- secretRef:
name: {{ . }}
{{- end }}
resources:
requests:
cpu: {{ .Values.specialist.resources.requests.cpu | default "2" | quote }}
memory: {{ .Values.specialist.resources.requests.memory | default "4Gi" }}
limits:
cpu: {{ .Values.specialist.resources.limits.cpu | default "6" | quote }}
memory: {{ .Values.specialist.resources.limits.memory | default "10Gi" }}
readinessProbe:
httpGet:
path: /ready
port: 8000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: model-cache
mountPath: /root/.cache
volumes:
- name: tmp
emptyDir:
sizeLimit: 10Mi
- name: model-cache
emptyDir:
sizeLimit: 5Gi
---
apiVersion: v1
kind: Service
metadata:
name: specialist
namespace: {{ .Release.Namespace }}
labels:
app: specialist
{{- include "stonks.labels" . | nindent 4 }}
spec:
selector:
app: specialist
ports:
- port: 8000
targetPort: 8000
protocol: TCP
{{- end }}
{{- end }}
+18
View File
@@ -289,6 +289,24 @@ superset:
requests: { cpu: 200m, memory: 512Mi }
limits: { cpu: "1", memory: 2Gi }
## Specialist inference service (CPU-first NER/classification)
specialist:
enabled: true
replicas: 2
model: "urchade/gliner_large-v2.1"
maxBatchSize: "32"
maxWaitMs: "50.0"
maxQueueSize: "256"
testMode: "0"
secrets: [stonks-core-secrets]
resources:
requests:
cpu: "2"
memory: 4Gi
limits:
cpu: "6"
memory: 10Gi
## Network policies
networkPolicies:
enabled: true