release: v1.3.1 - Pipeline Queue Integration, OCR Fix, Worker Compatibility

Major Changes:
- Pipeline Queue integration completed (internal.file + pipeline.commands)
- Fixed old job_worker database compatibility with new command_queue table
- Compiled Swift OCR binary (was missing, causing empty OCR results)
- Added deep scan functionality through re-scan API

Fixes:
- Changed CommandJob.id from i32 to i64 for database compatibility
- Added UUID generation in create_command (message_id field)
- Fixed claim_pending_commands to query queue_name = 'internal.file'
- Fixed field mappings: command_id → message_id, job_type → command_type
- Added support for 'processing' status in CommandJobStatus

Queue System:
- internal.file queue: for register/unregister/re-scan commands (job_worker)
- pipeline.commands queue: for vectorize/store_asrx/etc commands (pipeline_worker)

Documentation:
- Added comprehensive queue system documentation
- Created M4 workspace status reports
- Updated AGENTS.md with queue system details
This commit is contained in:
Accusys
2026-10-12 10:00:51 +08:00
parent 0a18e70639
commit 63fbbe1225
418 changed files with 44084 additions and 4280 deletions
+92 -18
View File
@@ -3,6 +3,26 @@ import Vision
import ArgumentParser
import AVFoundation
/// Calculate capture quality based on face size and confidence
/// Returns a score between 0.0 and 1.0
func calculateFallbackCaptureQuality(
faceWidth: Int,
faceHeight: Int,
imageWidth: Int,
imageHeight: Int,
confidence: Double
) -> Double {
// Face size relative to image (larger faces = better quality)
let faceArea = Double(faceWidth * faceHeight)
let imageArea = Double(imageWidth * imageHeight)
let relativeSize = min(1.0, faceArea / (imageArea * 0.25)) // Normalize to max 25% of image
// Combine confidence and size (50% weight each)
let quality = (confidence * 0.5) + (relativeSize * 0.5)
return min(1.0, max(0.0, quality))
}
/// Swift Face Processor - Apple Vision Framework for face detection + pose
/// Uses AVAssetImageGenerator for reliable frame access (no AVAssetReader corruption).
@main
@@ -118,10 +138,11 @@ struct SwiftFace: ParsableCommand {
return
}
let faceObservations = detectReq.results ?? []
let landmarkObservations = lmReq.results ?? []
let captureQualityObs = captureQReq.results ?? []
guard !faceObservations.isEmpty || !landmarkObservations.isEmpty else {
let faceObservations = detectReq.results ?? []
let landmarkObservations = lmReq.results ?? []
let captureQualityObs = captureQReq.results ?? []
let hasQualityResults = !captureQualityObs.isEmpty
guard !faceObservations.isEmpty || !landmarkObservations.isEmpty else {
return
}
@@ -145,12 +166,6 @@ struct SwiftFace: ParsableCommand {
let faceW = Int(bb.size.width * imgW)
let faceH = Int(bb.size.height * imgH)
// BBox validation - ensure non-zero dimensions
if bb.size.width <= 0 || bb.size.height <= 0 {
print("[WARN] Invalid bbox dimensions (width=\(bb.size.width), height=\(bb.size.height)) at frame \(frameNumber), skipping")
continue
}
// Size filter
if faceW < MIN_SIZE || faceH < MIN_SIZE { continue }
@@ -176,6 +191,57 @@ struct SwiftFace: ParsableCommand {
}
}
}
// Fallback: Calculate quality from size, confidence, pose if API didn't provide it
if captureQ == 0.0 {
let faceArea = Double(faceW * faceH)
let imgArea = Double(imgW * imgH)
let sizeScore = min(1.0, (faceArea / imgArea) * 4.0) // Normalize, larger = better
let confScore = lmConf // Already 0-1
// Pose score (frontal = 1.0, profile = 0.0)
var poseScore = 1.0
if let yaw = lmObs.yaw?.doubleValue {
poseScore = max(0.0, 1.0 - abs(yaw) / 90.0)
}
// Weighted combination
captureQ = sizeScore * 0.3 + confScore * 0.4 + poseScore * 0.3
}
// Match face observation by bbox to extract faceprint (embedding)
var embedding: [Float]? = nil
if #available(macOS 14, *) {
var matchCount = 0
for faceObs in faceObservations {
let fBB = faceObs.boundingBox
let ix = max(bb.minX, fBB.origin.x)
let iy = max(bb.minY, fBB.origin.y)
let iw = min(bb.maxX, fBB.origin.x + fBB.width) - ix
let ih = min(bb.maxY, fBB.origin.y + fBB.height) - iy
if iw <= 0 || ih <= 0 { continue }
let intersection = iw * ih
let union = bb.width * bb.height + fBB.width * fBB.height - intersection
if intersection / union > 0.5 {
matchCount += 1
// Try to extract faceprint
if let fp = faceObs.value(forKey: "faceprint") as? NSObject {
if let desc = fp.value(forKey: "descriptor") as? NSObject {
if let elems = desc.value(forKey: "elements") as? [NSNumber] {
embedding = elems.map { Float($0.doubleValue) }
} else {
print("[DEBUG] No elements in descriptor")
}
} else {
print("[DEBUG] No descriptor in faceprint")
}
} else {
print("[DEBUG] No faceprint in faceObs (frame \(frameNumber), match \(matchCount))")
}
break
}
}
}
var faceData: [String: Any] = [
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
@@ -183,7 +249,11 @@ struct SwiftFace: ParsableCommand {
"confidence": Double(lmObs.confidence),
"captureQuality": captureQ,
]
// NOTE: embedding is NOT stored in JSON, only in Qdrant via Rust worker
// Add embedding if available
if let emb = embedding {
faceData["embedding"] = emb
}
// Pose from landmark observation
if let yaw = lmObs.yaw?.doubleValue,
@@ -256,13 +326,6 @@ struct SwiftFace: ParsableCommand {
let faceW = Int(fBB.size.width * imgW)
let faceH = Int(fBB.size.height * imgH)
// BBox validation - ensure non-zero dimensions
if fBB.size.width <= 0 || fBB.size.height <= 0 {
print("[WARN] Invalid bbox dimensions (width=\(fBB.size.width), height=\(fBB.size.height)) at frame \(frameNumber), skipping")
continue
}
if faceW < MIN_SIZE || faceH < MIN_SIZE { continue }
// Unmatched face rect: output without landmarks
@@ -287,6 +350,17 @@ struct SwiftFace: ParsableCommand {
}
}
}
// Fallback: Calculate quality from size and confidence if API didn't provide it
if captureQ == 0.0 {
let faceArea = Double(faceW * faceH)
let imgArea = Double(imgW * imgH)
let sizeScore = min(1.0, (faceArea / imgArea) * 4.0) // Normalize, larger = better
let confScore = Double(faceObs.confidence) // Already 0-1
// Weighted combination (no pose available for unmatched faces)
captureQ = sizeScore * 0.5 + confScore * 0.5
}
var faceData: [String: Any] = [
"bbox": ["x": max(0, faceX), "y": max(0, faceY),