Schema Design
AVIS strictly types all internal data passing between pipeline stages. The core schema is the EvidenceGraph, built using Pydantic, which transforms raw machine learning detections into explainable geometric and semantic relationships.
1. The Evidence Graph Data Model
The EvidenceGraph is not a flat list of objects; it is a typed graph.
Nodes
Every physical entity detected in the image is represented as a node. Nodes contain their spatial bounds (BBox) and ML confidence score.
Vehicle: Represents cars, motorcycles, trucks, buses, or bicycles. Stores atype,bbox, andconfidence. Also tracks which calibration zones it sits inside (in_zones).Person: Represents humans. Includes aroleenum (rider,driver,pedestrian). Can carry attribute scores (e.g.,helmet: bool,seatbelt: bool).Light: A traffic light. Tracks itsstate(red,amber,green,unknown).Plate: A cropped license plate. Trackstext(OCR output) andregex_ok(whether it matches standard Indian plate formats).Zone: A geometric area derived from the camera calibration file. Can be astop_line,no_parking, orlanezone. Defined by apolygon.
Edges
Edges define the relationships between nodes. A violation is essentially a small subgraph.
rides:Person→Vehicle:motorcycle. Links a rider to a bike. Used for helmet and triple-riding rules.drives:Person→Vehicle:car. Links a driver to a car. Used for seatbelt rules.has_plate:Vehicle→Plate. Links OCR text to a specific vehicle.located_in:Vehicle→Zone. Determines if a vehicle has breached a calibration polygon.governed_by:Vehicle→Light. Links a vehicle to the specific traffic light dictating its allowed movement.
2. Violation Representation
When the Rule Engine identifies a violation subgraph, it generates structured records.
Candidate
An intermediate object representing a potential violation before routing or VLM verification.
type: E.g.,TRIPLE_RIDING.tier: The evidence sufficiency tier (A,B,C,D).subjects: A list of node IDs involved in the violation (e.g.,["motorcycle_1", "rider_1", "rider_2", "rider_3"]).rule_score: Mathematical confidence of the rule logic.
Violation
The final output payload, destined for the database and e-challan generation.
- Inherits the
Candidatedata but adds the final ruling: evidence_sufficiency:sufficient,candidate, orinsufficient.scores: A fused object containingdetection,rule,vlm, andfusedscores.route: How the decision was made (auto_confirmed,vlm_confirmed,human_review).reason: A human-readable, single-sentence justification.legal: A dictionary containing theact,section, andfineamount.evidence_hash: A SHA-256 hash of the original image to prove no tampering occurred.
3. Database Schema (PostgreSQL)
Because the EvidenceGraph is highly variable and deeply nested, AVIS does not use a strict relational schema for detections. Instead, it utilizes JSONB columns in PostgreSQL via SQLModel.
This provides:
- Relational Integrity: Metadata (timestamp, camera ID, status) is stored in standard relational columns for fast indexing and queue management.
- Flexible Storage: The entire
EvidenceGraphand the resultingViolationJSON are dumped into a JSONB column. This allows querying the database for specific graph conditions using Postgres JSON operators while allowing the schema to evolve without heavy migrations.