Skip to main content

Inference Store Metadata

One of the powerful features of the Inference Store is its ability to process, store, and query for metadata.

Metadata must be key-value pairs, where keys and values must be sent to the server as strings, but values can be parsed based on their specified type. The supported specified types are integers, floats, strings, and nested JSON.

note

If you use the Chariot SDK to send metadata, you do not need to specify the type; it will be interpreted for you.

Adding Metadata

Metadata can be added to an inference in a couple of ways:

  1. Sending additional metadata with the inference requests.
  2. Posting metadata to an existing inference in the Inference Store.

Adding Metadata During Inference

Sending metadata with the inference request using the Chariot SDK

from json import dumps
from PIL import Image
from chariot.client import connect
from chariot.models import get_model_by_id

connect()
model = get_model_by_id("your-model-id")
image = Image.open(file)

# When using the SDK to request an inference, there is no need to specify the type of metadata.
# The SDK will infer the type for you.
metadata = {
"camera_id": "hallway-camera-1",
"location": dumps({"building": "headquarters", "floor": 2}),
"confidence_threshold": 0.8,
"frame_number": 1234
}

result = model.detect(image, custom_metadata=metadata)
note

If you are sending a JSON as a value, be sure to turn any Python dictionary into a JSON string using json.dumps.

Adding Location Metadata

Location metadata (latitude and longitude) are reserved metadata keys that enable geospatial querying. Here's how to add location data:

from PIL import Image
from chariot.client import connect
from chariot.models import get_model_by_id

connect()
model = get_model_by_id("your-model-id")
image = Image.open(file)

# Add GPS coordinates as metadata
metadata = {
"latitude": 40.7128, # New York City latitude
"longitude": -74.0060, # New York City longitude
"altitude": 10.5, # Optional: altitude in meters
"gps_accuracy": 5.0 # Optional: GPS accuracy in meters
}

result = model.detect(image, custom_metadata=metadata)

Adding Metadata to Existing Inferences

Creating metadata for an existing inference in the store

from chariot.inference_store import models, metadata

metadata.create_metadata(
model_id=model_id,
inference_id=inference_id,
request_body=models.NewExtendedMetadataRequest(
key="image_chip_id",
type=models.MetadataType.STRING,
value="abc123"
),
)

# Add latitude
metadata.create_metadata(
model_id=model_id,
inference_id=inference_id,
request_body=models.NewExtendedMetadataRequest(
key="latitude",
type=models.MetadataType.FLOAT,
value="40.7128"
),
)

# Add longitude
metadata.create_metadata(
model_id=model_id,
inference_id=inference_id,
request_body=models.NewExtendedMetadataRequest(
key="longitude",
type=models.MetadataType.FLOAT,
value="-74.0060"
),
)

Retrieving Metadata

You can retrieve all metadata associated with a specific inference to inspect what data has been stored.

Retrieving all metadata for an inference:

from chariot.inference_store import metadata

metadata_list = metadata.get_metadata(model_id=model_id, inference_id=inference_id)
for meta in metadata_list:
print(f"Key: {meta.key}, Type: {meta.type}, Value: {meta.value}")

Deleting Metadata

You can remove specific metadata keys from an inference when they are no longer needed or contain incorrect information.

Deleting specific metadata for an inference:

from chariot.inference_store import metadata

metadata.delete_metadata(
model_id=model_id,
inference_id=inference_id,
key="image_chip_id"
)

Metadata Statistics

Metadata statistics help you understand the distribution and usage patterns of metadata across all inferences for a model. This is useful for data analysis and understanding your production data characteristics.

Getting statistics about metadata usage across all inferences for a model:

from chariot.inference_store import models, metadata

# Get counts of each metadata key-type combination
key_type_counts = metadata.get_metadata_key_type_counts(model_id=model_id)
print(key_type_counts.counts)

# Get statistics for a specific metadata key
stats_request = models.NewGetMetadataStatisticsRequest(
key="confidence_threshold",
type=models.MetadataStatisticsType.FLOAT,
distribution_bin_count=10
)

stats = metadata.get_metadata_statistics(
model_id=model_id,
request_body=stats_request
)
print(f"Count: {stats.count}")
print(f"Min: {stats.min}, Max: {stats.max}")
print(f"Distribution: {stats.distribution}")

Reserved Metadata Keys

Some metadata keys are reserved and are used for unique functions in the Inference Store:

  • data_source (string): Identifies the source of the inference data (e.g., "camera-1", "batch-upload")
  • latitude (float): GPS latitude coordinate for geolocation filtering
  • longitude (float): GPS longitude coordinate for geolocation filtering