1.  [](/)
2.  [Code examples](/recipes)
3.  Anomaly Detection

Back to code examples

Quality

# Anomaly Detection

Identify outliers and anomalous content using embedding distance from cluster centroids. Flag quality issues, novel content, or items that don't match expected patterns.

video

image

audio

text

Multi-Stage

[Run in Builder](/build?recipe=anomaly-detection)

"Find images that don't match the expected product catalog style with anomaly score above 0.85"

### Why This Matters

Anomalies can be problems (data quality issues) or opportunities (novel content). Either way, you need to find them before they find you.

Python

cURL

import csv

import io

import time

import requests

from mixpeek import Mixpeek

client \= Mixpeek(api\_key\="YOUR\_API\_KEY", namespace\="inspection")

API \= "https://api.mixpeek.com/v1"

HEADERS \= {"Authorization": "Bearer YOUR\_API\_KEY", "X-Namespace": "inspection"}

\# 1. A collection that embeds every inspection photo

bucket \= client.buckets.create(

    bucket\_name\="inspection-photos",

    bucket\_schema\={"properties": {"photo": {"type": "image"}}},

)

collection \= client.collections.create(

    collection\_name\="inspection-photos",

    source\={"type": "bucket", "bucket\_ids": \[bucket\["bucket\_id"\]\]},

    feature\_extractor\={

        "feature\_extractor\_name": "multimodal\_extractor",

        "version": "v1",

    },

)

client.buckets.upload(

    bucket\["bucket\_id"\],

    blobs\=\[{"property": "photo", "type": "image", "data": "s3://your-bucket/inspection/line-4/frame-0001.jpg"}\],

)

client.collections.trigger(collection\["collection\_id"\])

\# 2. HDBSCAN puts photos that fit no dense group into noise; those are the anomalies.

\#    The SDK has no clusters resource, so this part is REST.

cluster \= requests.post(API + "/clusters", headers\=HEADERS, json\={

    "cluster\_name": "inspection-baseline",

    "collection\_ids": \[collection\["collection\_id"\]\],

    "cluster\_type": "vector",

    "vector\_config": {

        "feature\_uris": \["mixpeek://multimodal\_extractor@v1/vertex\_multimodal\_embedding"\],

        "clustering\_method": "hdbscan",

        "algorithm\_params": {"min\_cluster\_size": 20},

    },

}).json()

task \= requests.post(API + "/clusters/" + cluster\["cluster\_id"\] + "/execute", headers\=HEADERS, json\={}).json()

while client.tasks.get(task\["task\_id"\])\["status"\] not in ("COMPLETED", "COMPLETED\_WITH\_ERRORS", "FAILED"):

    time.sleep(15)

\# 3. The latest run reports the noise ratio, and its CSV export lists every member

run \= requests.get(API + "/clusters/" + cluster\["cluster\_id"\] + "/executions", headers\=HEADERS).json()

print("noise ratio:", (run.get("metrics") or {}).get("noise\_ratio"))

export \= requests.get(

    API + "/clusters/" + cluster\["cluster\_id"\] + "/executions/" + run\["run\_id"\] + "/export",

    headers\=HEADERS,

    params\={"format": "csv"},

)

rows \= csv.DictReader(io.StringIO(export.text))

outliers \= \[r\["document\_id"\] for r in rows if r\["cluster\_id"\] in ("-1", "cl\_-1") and r\["is\_centroid"\] != "True"\]

print(len(outliers), "anomalous photos:", outliers\[:10\])

### Feature Extractors

Multimodal Extractor

Unified embeddings for video, audio, image, and text: scene/silence chunking, Whisper transcription, thumbnails, and Gemini vision.

### Retriever Stages

### Resources Used

Clustering

[

Baseline Clusters

Baseline distribution snapshot for comparison

Baseline cluster centroids for distance calculation



](https://mixpeek.com/docs/enrichment/clusters)

Analytics

[

Anomaly Scores

Distance-based anomaly scoring

Distance-based anomaly scoring



](https://mixpeek.com/docs/enrichment/clusters)

### Documentation

[Clusters](https://mixpeek.com/docs/enrichment/clusters)

## Use Cases Using This Recipe

Advanced

### AI Video Surveillance Analytics

Transform passive camera feeds into actionable security intelligence

85% of events caught live vs. 5% manual baseline

Real-time incident detection rate

[

security

](/solutions/security)

Who It's For

Security operations centers, facility managers, and enterprise security teams monitoring 50+ camera feeds across multiple locations

[View Details](/use-cases/video-surveillance-analytics)

## Related code examples and resources

Pages on the same stages, extractors and patterns.

[

Extractor

### Multimodal Extractor

Unified embeddings for video, audio, image, and text: scene/silence chunking, Whisper transcription, thumbnails, and Gemini vision.

Learn more





](/extractors/multimodal)[

Recipe

### Semantic Multimodal Search

Unified semantic search across all content types. Query by natural language and retrieve relevant video clips, images, audio segments, and documents based on meaning-not keywords or manual tags.

Learn more





](/recipes/semantic-multimodal-search)[

Recipe

### Feature Extraction

Multi-tier feature extraction that decomposes content into searchable components: embeddings, transcripts, detected objects, OCR text, scene boundaries, and more. The foundation for all downstream retrieval and analysis.

Learn more





](/recipes/feature-extraction)[

Recipe

### Clustering & Theme Discovery

Unsupervised clustering that groups content into semantic themes using HDBSCAN. Surfaces hidden patterns, content variants, and outliers without requiring predefined labels.

Learn more





](/recipes/clustering-theme-discovery)[

Recipe

### Multimodal RAG

Retrieval-augmented generation across video, images, and text. Retrieve relevant multimodal context, then pass to your LLM with citations back to source timestamps and frames.

Learn more





](/recipes/multimodal-rag)[

Recipe

### Sports Highlights Pipeline

Automatically identify highlight-worthy moments in sports broadcasts using multimodal analysis, visual action detection, audio spike recognition (crowd noise, commentator excitement), and on-screen graphic parsing. Returns timestamped event manifests ready for clip assembly.

Learn more





](/recipes/sports-highlights)