paladin-ai 0.5.1

Enterprise AI orchestration framework with multi-agent coordination patterns
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# Sanctum Deployment Guide

This guide covers deployment scenarios for Sanctum's production-ready Qdrant adapter across various environments.

## Table of Contents

- [Prerequisites]#prerequisites
- [Local Development]#local-development
- [Docker Compose]#docker-compose
- [Kubernetes]#kubernetes
- [Cloud Deployments]#cloud-deployments
- [Production Best Practices]#production-best-practices
- [Monitoring]#monitoring
- [Backup and Recovery]#backup-and-recovery

## Prerequisites

### For Qdrant Deployment

- Docker 20.10+ (for Docker deployments)
- Kubernetes 1.21+ (for K8s deployments)
- Minimum 2GB RAM for Qdrant
- Sufficient disk space (estimate ~1KB per vector with 1536 dimensions)

### Resource Estimation

| Entries | Dimension | Estimated Storage | Recommended RAM |
|---------|-----------|-------------------|-----------------|
| 10,000 | 1536 | ~15 MB | 512 MB |
| 100,000 | 1536 | ~150 MB | 1 GB |
| 1,000,000 | 1536 | ~1.5 GB | 4 GB |
| 10,000,000 | 1536 | ~15 GB | 16 GB |

## Local Development

### Using InMemory Adapter

The simplest option for development - no infrastructure needed:

```yaml
# config.yml
sanctum:
  enabled: true
  adapter_type: "in_memory"
```

```rust
use paladin::infrastructure::adapters::sanctum::InMemorySanctum;

#[tokio::main]
async fn main() {
    let sanctum = InMemorySanctum::new();
    // Ready to use immediately
}
```

### Local Qdrant Instance

For testing Qdrant locally:

```bash
# Pull and run Qdrant
docker run -p 6333:6333 -p 6334:6334 \
    -v $(pwd)/qdrant_storage:/qdrant/storage \
    qdrant/qdrant:latest
```

```yaml
# config.yml
sanctum:
  enabled: true
  adapter_type: "qdrant"
  qdrant:
    url: "http://localhost:6334"
    collection_name: "dev_memories"
    vector_dimension: 1536
```

Access Qdrant dashboard at: http://localhost:6333/dashboard

## Docker Compose

### Basic Setup

```yaml
# docker-compose.yml
version: '3.8'

services:
  qdrant:
    image: qdrant/qdrant:v1.7.4
    container_name: paladin-qdrant
    ports:
      - "6333:6333"  # HTTP API
      - "6334:6334"  # gRPC API
    volumes:
      - qdrant_data:/qdrant/storage
    environment:
      QDRANT__SERVICE__HTTP_PORT: 6333
      QDRANT__SERVICE__GRPC_PORT: 6334
    restart: unless-stopped

  paladin:
    build: .
    container_name: paladin-app
    depends_on:
      - qdrant
    environment:
      APP_SANCTUM_ENABLED: "true"
      APP_SANCTUM_ADAPTER_TYPE: "qdrant"
      APP_SANCTUM_QDRANT_URL: "http://qdrant:6334"
      APP_SANCTUM_QDRANT_COLLECTION_NAME: "paladin_memories"
      APP_SANCTUM_QDRANT_VECTOR_DIMENSION: "1536"
    volumes:
      - ./config.yml:/app/config.yml
    restart: unless-stopped

volumes:
  qdrant_data:
    driver: local
```

Start services:

```bash
docker-compose up -d
```

Verify Qdrant health:

```bash
curl http://localhost:6333/health
```

### Production Docker Compose

Enhanced with resource limits and monitoring:

```yaml
# docker-compose.prod.yml
version: '3.8'

services:
  qdrant:
    image: qdrant/qdrant:v1.7.4
    container_name: paladin-qdrant-prod
    ports:
      - "6333:6333"
      - "6334:6334"
    volumes:
      - qdrant_data:/qdrant/storage
      - ./qdrant-config.yaml:/qdrant/config/production.yaml
    environment:
      QDRANT__SERVICE__HTTP_PORT: 6333
      QDRANT__SERVICE__GRPC_PORT: 6334
      QDRANT__LOG_LEVEL: INFO
    deploy:
      resources:
        limits:
          cpus: '4'
          memory: 8G
        reservations:
          cpus: '2'
          memory: 4G
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:6333/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  paladin:
    build:
      context: .
      dockerfile: Dockerfile.prod
    container_name: paladin-app-prod
    depends_on:
      qdrant:
        condition: service_healthy
    environment:
      APP_SANCTUM_ENABLED: "true"
      APP_SANCTUM_ADAPTER_TYPE: "qdrant"
      APP_SANCTUM_QDRANT_URL: "http://qdrant:6334"
      APP_SANCTUM_QDRANT_COLLECTION_NAME: "production_memories"
      APP_SANCTUM_QDRANT_VECTOR_DIMENSION: "1536"
      RUST_LOG: "info,paladin=debug"
    volumes:
      - ./config.prod.yml:/app/config.yml:ro
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4G
        reservations:
          cpus: '1'
          memory: 2G
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  qdrant_data:
    driver: local
```

## Kubernetes

### Qdrant StatefulSet

```yaml
# k8s/qdrant-statefulset.yaml
apiVersion: v1
kind: Service
metadata:
  name: qdrant
  namespace: paladin
spec:
  selector:
    app: qdrant
  ports:
    - name: http
      port: 6333
      targetPort: 6333
    - name: grpc
      port: 6334
      targetPort: 6334
  clusterIP: None
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: qdrant
  namespace: paladin
spec:
  serviceName: qdrant
  replicas: 1
  selector:
    matchLabels:
      app: qdrant
  template:
    metadata:
      labels:
        app: qdrant
    spec:
      containers:
      - name: qdrant
        image: qdrant/qdrant:v1.7.4
        ports:
        - containerPort: 6333
          name: http
        - containerPort: 6334
          name: grpc
        env:
        - name: QDRANT__SERVICE__HTTP_PORT
          value: "6333"
        - name: QDRANT__SERVICE__GRPC_PORT
          value: "6334"
        - name: QDRANT__LOG_LEVEL
          value: "INFO"
        volumeMounts:
        - name: qdrant-storage
          mountPath: /qdrant/storage
        resources:
          requests:
            memory: "2Gi"
            cpu: "500m"
          limits:
            memory: "8Gi"
            cpu: "4000m"
        livenessProbe:
          httpGet:
            path: /health
            port: 6333
          initialDelaySeconds: 30
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /readyz
            port: 6333
          initialDelaySeconds: 10
          periodSeconds: 5
  volumeClaimTemplates:
  - metadata:
      name: qdrant-storage
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "standard"
      resources:
        requests:
          storage: 50Gi
```

### Paladin Deployment

```yaml
# k8s/paladin-deployment.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: paladin-config
  namespace: paladin
data:
  config.yml: |
    sanctum:
      enabled: true
      adapter_type: "qdrant"
      qdrant:
        url: "http://qdrant:6334"
        collection_name: "k8s_memories"
        vector_dimension: 1536
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: paladin
  namespace: paladin
spec:
  replicas: 3
  selector:
    matchLabels:
      app: paladin
  template:
    metadata:
      labels:
        app: paladin
    spec:
      containers:
      - name: paladin
        image: paladin:latest
        ports:
        - containerPort: 8080
        env:
        - name: APP_SANCTUM_ENABLED
          value: "true"
        - name: APP_SANCTUM_ADAPTER_TYPE
          value: "qdrant"
        - name: APP_SANCTUM_QDRANT_URL
          value: "http://qdrant:6334"
        - name: APP_SANCTUM_QDRANT_COLLECTION_NAME
          value: "k8s_memories"
        - name: APP_SANCTUM_QDRANT_VECTOR_DIMENSION
          value: "1536"
        volumeMounts:
        - name: config
          mountPath: /app/config.yml
          subPath: config.yml
        resources:
          requests:
            memory: "1Gi"
            cpu: "500m"
          limits:
            memory: "4Gi"
            cpu: "2000m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /ready
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
      volumes:
      - name: config
        configMap:
          name: paladin-config
```

Deploy to Kubernetes:

```bash
# Create namespace
kubectl create namespace paladin

# Apply configurations
kubectl apply -f k8s/qdrant-statefulset.yaml
kubectl apply -f k8s/paladin-deployment.yaml

# Verify deployment
kubectl get pods -n paladin
kubectl logs -n paladin -l app=paladin
```

## Cloud Deployments

### AWS (EKS + Qdrant)

#### Option 1: Self-Hosted on EKS

Use the Kubernetes manifests above with EKS-specific storage class:

```yaml
# Use AWS EBS for storage
volumeClaimTemplates:
  - metadata:
      name: qdrant-storage
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "gp3"  # AWS EBS GP3
      resources:
        requests:
          storage: 100Gi
```

#### Option 2: Qdrant Cloud

```yaml
# config.yml
sanctum:
  enabled: true
  adapter_type: "qdrant"
  qdrant:
    url: "https://your-cluster.qdrant.io:6334"
    collection_name: "aws_memories"
    vector_dimension: 1536
```

Set API key via environment:

```bash
export QDRANT_API_KEY=your_api_key_here
```

### GCP (GKE + Qdrant)

Use GCP persistent disk:

```yaml
volumeClaimTemplates:
  - metadata:
      name: qdrant-storage
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "standard-rwo"  # GCP persistent disk
      resources:
        requests:
          storage: 100Gi
```

### Azure (AKS + Qdrant)

Use Azure managed disk:

```yaml
volumeClaimTemplates:
  - metadata:
      name: qdrant-storage
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "managed-premium"  # Azure premium SSD
      resources:
        requests:
          storage: 100Gi
```

## Production Best Practices

### 1. High Availability

**Qdrant Cluster Mode** (v1.2.0+):

```yaml
# qdrant-config.yaml
cluster:
  enabled: true
  consensus:
    tick_period_ms: 100
  p2p:
    port: 6335
```

Deploy multiple Qdrant replicas:

```yaml
replicas: 3  # Minimum for HA
```

### 2. Resource Allocation

**CPU Guidelines**:
- Development: 0.5-1 CPU
- Production: 2-4 CPUs
- High load: 4-8 CPUs

**Memory Guidelines**:
- Base: 2 GB + (vectors * dimension * 4 bytes)
- Example: 1M vectors × 1536 dim = ~6 GB + 2 GB buffer = 8 GB

**Storage**:
- Use SSD for production (NVMe preferred)
- Plan for 2x growth capacity
- Enable compression (built into Qdrant)

### 3. Network Configuration

**Firewall Rules**:
- Port 6333: HTTP API (internal only)
- Port 6334: gRPC API (application access)
- Port 6335: P2P cluster communication (Qdrant cluster only)

**TLS Configuration**:

```yaml
service:
  http_port: 6333
  grpc_port: 6334
  enable_tls: true
  tls_cert: /path/to/cert.pem
  tls_key: /path/to/key.pem
```

### 4. Collection Configuration

**Optimal Settings**:

```rust
use qdrant_client::prelude::*;

// Configure collection for production
let collection_config = CreateCollection {
    collection_name: "production_memories".to_string(),
    vectors_config: Some(VectorsConfig {
        params: Some(VectorParams {
            size: 1536,
            distance: Distance::Cosine,
            hnsw_config: Some(HnswConfig {
                m: 16,  // Number of edges per node (higher = better recall, more memory)
                ef_construct: 200,  // Build-time accuracy (higher = better quality, slower build)
                full_scan_threshold: 10000,
            }),
            quantization_config: Some(QuantizationConfig {
                scalar: Some(ScalarQuantization {
                    type_: ScalarType::Int8,  // Reduce memory by 4x
                    quantile: 0.99,
                    always_ram: true,
                }),
            }),
            on_disk: false,  // Keep vectors in RAM for speed
        }),
    }),
    // ... other settings
};
```

### 5. Security

**Authentication**:

```yaml
# qdrant-config.yaml
service:
  api_key: ${QDRANT_API_KEY}  # Use environment variable
```

**Network Policies (Kubernetes)**:

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: qdrant-network-policy
  namespace: paladin
spec:
  podSelector:
    matchLabels:
      app: qdrant
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: paladin
    ports:
    - protocol: TCP
      port: 6334
```

### 6. Backup Strategy

**Automated Snapshots**:

```bash
# Create snapshot
curl -X POST 'http://localhost:6333/collections/paladin_memories/snapshots'

# List snapshots
curl 'http://localhost:6333/collections/paladin_memories/snapshots'

# Download snapshot
curl -O 'http://localhost:6333/collections/paladin_memories/snapshots/snapshot-2024-01-30.snapshot'
```

**Kubernetes CronJob**:

```yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: qdrant-backup
  namespace: paladin
spec:
  schedule: "0 2 * * *"  # Daily at 2 AM
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: curlimages/curl:latest
            command:
            - sh
            - -c
            - |
              curl -X POST http://qdrant:6333/collections/paladin_memories/snapshots
              # Upload to S3/GCS/Azure Storage
          restartPolicy: OnFailure
```

## Monitoring

### Metrics to Track

**Qdrant Metrics**:
- Collection size (number of vectors)
- Search latency (p50, p95, p99)
- Memory usage
- CPU utilization
- Disk I/O

**Application Metrics**:
- Store operation latency
- Search operation latency
- Error rates
- Cache hit rates

### Prometheus Integration

```yaml
# prometheus-config.yaml
scrape_configs:
  - job_name: 'qdrant'
    static_configs:
      - targets: ['qdrant:6333']
    metrics_path: '/metrics'
```

### Grafana Dashboard

Key panels:
1. **Search Performance**: p95 latency over time
2. **Storage Growth**: Collection size trend
3. **Resource Usage**: CPU/Memory utilization
4. **Error Rates**: Failed operations per minute

## Backup and Recovery

### Full Backup

```bash
#!/bin/bash
# backup-qdrant.sh

COLLECTION="paladin_memories"
BACKUP_DIR="/backups/$(date +%Y%m%d)"
QDRANT_URL="http://localhost:6333"

# Create snapshot
SNAPSHOT=$(curl -s -X POST "${QDRANT_URL}/collections/${COLLECTION}/snapshots" | jq -r '.result.name')

# Download snapshot
curl -o "${BACKUP_DIR}/${SNAPSHOT}" \
  "${QDRANT_URL}/collections/${COLLECTION}/snapshots/${SNAPSHOT}"

# Upload to S3
aws s3 cp "${BACKUP_DIR}/${SNAPSHOT}" \
  "s3://paladin-backups/qdrant/${COLLECTION}/${SNAPSHOT}"
```

### Restore from Backup

```bash
#!/bin/bash
# restore-qdrant.sh

COLLECTION="paladin_memories"
SNAPSHOT_FILE="$1"
QDRANT_URL="http://localhost:6333"

# Upload snapshot to Qdrant
curl -X POST "${QDRANT_URL}/collections/${COLLECTION}/snapshots/upload" \
  -F "snapshot=@${SNAPSHOT_FILE}"

# Restore from snapshot
curl -X PUT "${QDRANT_URL}/collections/${COLLECTION}/snapshots/recover" \
  -H "Content-Type: application/json" \
  -d "{\"location\": \"${SNAPSHOT_FILE}\"}"
```

### Disaster Recovery Plan

1. **Regular Backups**: Daily automated snapshots
2. **Off-site Storage**: Copy to cloud storage (S3/GCS/Azure)
3. **Test Restores**: Monthly restore validation
4. **RPO/RTO**: Define acceptable data loss and recovery time
5. **Runbook**: Document recovery procedures

## Troubleshooting

### High Memory Usage

**Symptoms**: OOM kills, swapping

**Solutions**:
1. Enable quantization to reduce memory 4x:
   ```rust
   quantization_config: Some(QuantizationConfig {
       scalar: Some(ScalarQuantization {
           type_: ScalarType::Int8,
       }),
   })
   ```

2. Move vectors to disk:
   ```rust
   on_disk: true  // Slower but uses less RAM
   ```

3. Increase node resources

### Slow Search Performance

**Symptoms**: Search > 500ms consistently

**Solutions**:
1. Increase HNSW ef parameter:
   ```rust
   ef_construct: 200  // Higher = better accuracy
   ```

2. Tune search parameters:
   ```rust
   search_params: Some(SearchParams {
       hnsw_ef: Some(128),  // Higher = more accurate but slower
       exact: false,
   })
   ```

3. Add filters to reduce search space

### Connection Timeouts

**Symptoms**: "Failed to connect to Qdrant"

**Solutions**:
1. Verify Qdrant is running:
   ```bash
   curl http://localhost:6333/health
   ```

2. Check network connectivity:
   ```bash
   telnet qdrant 6334
   ```

3. Increase timeouts:
   ```rust
   QdrantClient::builder()
       .with_timeout(Duration::from_secs(30))
       .build()
   ```

## Cost Optimization

### Resource Right-Sizing

**Start Small**:
- 2 GB RAM for <100K vectors
- 4 GB RAM for <1M vectors
- Scale based on metrics

### Storage Optimization

**Techniques**:
1. **Quantization**: Reduce memory/storage by 75%
2. **Compression**: Built into Qdrant (ZSTD)
3. **Pruning**: Delete old/unused memories

### Cloud Cost Management

**Tips**:
- Use spot/preemptible instances for non-critical workloads
- Scale down non-prod environments off-hours
- Use Qdrant Cloud for predictable costs
- Monitor and set budget alerts

---

**Next Steps**:
- [Migration Guide]sanctum-migration.md
- [Main Documentation]../user-guides/sanctum-vector-memory.md
- [Performance Tuning]../operations/performance-tuning.md