Methods
Note: The database is typically managed automatically by FaceRecognizer and FaceTracker. Direct usage is only needed for advanced scenarios.
Methods Overview
Object Management
add_object()
Add/update person attributes
get_id_by_attributes()
Get object ID by attributes
get_attributes_by_id()
Get attributes by object ID
list_objects()
List all objects
remove_object_by_id()
Remove object and embeddings
remove_object_by_attributes()
Remove object by attributes
Embedding Management
add_embeddings()
Add embeddings for object ID
add_embeddings_for_attributes()
Add embeddings for attributes
get_embeddings()
Get embeddings and images
remove_embeddings_by_id()
Remove embeddings by ID
remove_embeddings_by_attributes()
Remove embeddings by attributes
count_embeddings()
Count embeddings per object
Search
get_attributes_by_embedding()
Find person by embedding vector
Database Operations
backup()
Create zip backup
restore()
Restore from backup
clear_all_tables()
Clear all data
Object Management
add_object()
Add or update person attributes.
Parameters:
object_id(str) - Unique object ID (typically UUID)attributes(Any) - Person attributes (name, metadata, etc.)
Example:
Example with dictionary attributes:
Note: The first attribute added to the database defines its structure. All subsequent attributes must have the same dictionary format - same keys and same value types.
get_id_by_attributes()
Search for object ID by its attributes.
Returns: Object ID or None if not found
Example:
get_attributes_by_id()
Get person attributes by object ID.
Returns: Attributes or None if not found
Example:
list_objects()
List all objects in database.
Returns: Dictionary mapping object ID to attributes
Example:
remove_object_by_id()
Remove person and all their embeddings and associated images.
Example:
remove_object_by_attributes()
Remove person by attributes.
Example:
Embedding Management
add_embeddings()
Add face embeddings for a person.
Parameters:
object_id(str) - Object IDembeddings(List[np.ndarray]) - List of embedding vectorsdedup(bool) - Deduplicate embeddings (default: True)images(Sequence) - Optional face images (numpy arrays or PNG bytes)
Returns: Number of embeddings added (after deduplication)
Example:
add_embeddings_for_attributes()
Add embeddings for person attributes (creates person if needed). Object ID will be created automatically as a uuid4 string.
Returns: Tuple of (embeddings added, object ID)
Example:
get_embeddings()
Get all embeddings and images for a person.
Returns: Tuple of (embedding vectors, images)
Example:
remove_embeddings_by_id()
Remove all embeddings and associated images for a person (keeps person record).
Example:
remove_embeddings_by_attributes()
Remove embeddings and associated images by person attributes.
Example:
count_embeddings()
Count embeddings per person.
Returns: Dictionary mapping object ID to (count, attributes)
Example:
Search
get_attributes_by_embedding()
Find person by embedding similarity.
Returns: Tuple of (object ID, attributes, similarity score)
Example:
Database Operations
backup()
Create zip archive backup of database.
Parameters:
dest(str) - Destination zip file path
Example:
restore()
Restore database from zip backup.
Parameters:
src(str) - Source zip file path
Warning: Replaces current database completely
Example:
clear_all_tables()
Delete all data in database.
Warning: Irreversible - all data is deleted
Example:
Common Patterns
Bulk Import
Database Migration
Last updated
Was this helpful?

