Sensor Anomaly Detector
Flags sensor windows far from normal operation.
| Industry | Level | Difficulty | Recommended mode |
|---|---|---|---|
| Manufacturing & IoT | 3 of 5 | Advanced | sq8 |
The problem
Section titled “The problem”- Thresholds miss subtle patterns.
- Failures are expensive.
- Edge devices are small.
How SrvDB powers Sensor Anomaly Detector
Section titled “How SrvDB powers Sensor Anomaly Detector”- Normal sensor windows are stored as feature vectors with
sq8. - New windows are compared; a large distance is an anomaly.
- Runs on ARM edge devices.
- Crash-safe through power cuts.
What changes
Section titled “What changes”| Today | With Sensor Anomaly Detector on SrvDB |
|---|---|
| Static thresholds | Learned normal behaviour |
| Late failure detection | Early deviations |
| Cloud dependence | On the device |
How it works
Section titled “How it works”- Collect normal windows.
- Store in SrvDB (
sq8). - Score live windows.
- Alert operators.
- Refresh baseline.
SrvDB features it uses
Section titled “SrvDB features it uses”- SQ8 compression (
sq8): stores each value in one byte, 4× smaller than full precision. - True cosine scores: scores in [-1, 1] mean the same in every mode, so thresholds are stable.
- Crash-safe
persist(): after it returns, data survives a crash or power loss and reopens exactly as committed. - Rust API: embed SrvDB directly in Rust services and devices.
Use cases
Section titled “Use cases”- Vibration anomalies
- Temperature drift
- Pressure patterns
- Motor current signatures
- Energy anomalies
- Process deviations
Core code
Section titled “Core code”embed() is your embedding model (for example sentence-transformers, or a function that turns your records into feature vectors).
import jsonimport srvdb
db = srvdb.Database("./sensor-anomaly-detector-db", dimension=128, mode="sq8")
def ingest(items): """items: list of (id, text, metadata dict)""" db.upsert( ids=[i for i, _, _ in items], embeddings=[embed(t) for _, t, _ in items], metadatas=[json.dumps(m) for _, _, m in items], ) db.persist() # crash-safe checkpoint
def deviation(window, k=5): hits = db.search(embed(window), k) return [(json.loads(db.get(i)), round(score, 3)) for i, score in hits]Limits and honest notes
Section titled “Limits and honest notes”- Requires a representative baseline and tuning.
Build roadmap
Section titled “Build roadmap”- Prototype: load a sample of real data with
flatmode and check that searches return what an expert expects. - Measure: if you move to an approximate mode, compare its results with
flaton the same queries (recall). - Pipeline: add continuous
upsertand decide when to callpersist(). - Harden: test restarts and crashes, add logging, review every output path with domain experts.
- Deploy: ship the database directory with the application or service.
All Manufacturing & IoT projects
Section titled “All Manufacturing & IoT projects”| Level | Project | What it does |
|---|---|---|
| 1 · Beginner | Maintenance Assistant | Technicians describe a symptom and get the right manual section and past fixes. |
| 2 · Intermediate | Defect Matcher | Matches new defects to past ones, from text and images. |
| 3 · Advanced | Sensor Anomaly Detector (this page) | Flags sensor windows far from normal operation. |
| 4 · Expert | Plant Knowledge Agent | An agent with shift memory across lines, manuals and quality records. |
| 5 · Frontier | Predictive Maintenance at the Edge | Finds machines whose behaviour resembles past pre-failure signatures. |
See also: Use cases · Live examples (coming soon)