Database¶
We support Oracle and Postgres databases.
Temporary attributes are stored separately in Redis; see Temporary attributes storage.
Multiple hosts¶
The dsn parameter of service database config should be specified to enable multihost option for Postgres.
DSN may be specified in the following format: luna:luna@postgres01:5432,postgres02:5432/luna_faces?some_option=some_value. It is possible to partially fill in the DSN string (e.g. postgres01,postgres02/luna_faces), and then the missing parameters will be filled in from proprietary parameter values (or defaults).
At startup, the service will create a pool of connections to one of DSN hosts available. In case of problems with establishing a connection after several unsuccessful attempts, the service will again try to set up a connection pool to any of DSN hosts available.
DB scheme.¶
- class luna_faces.db.faces_db_tools.models.faces_models.Attribute(**kwargs)[source]¶
Database table model for attributes.
- age¶
age
- Type:
int
- age_obtaining_method¶
how the gender was obtained
- Type:
int
- age_version¶
age version
- Type:
int
- create_time¶
date and time of creating attributes
- Type:
DateTime
- descriptor_samples_generation¶
descriptor samples generation
- Type:
int
- ethnicity¶
ethnicity, enum luna_faces.crutches_on_wheels.cow.maps.vl_maps.ETHNIC_MAP
- Type:
int
- ethnicity_obtaining_method¶
how the ethnicity was obtained
- Type:
int
- ethnicity_version¶
ethnicity version
- Type:
int
- face_id¶
face id, uuid.
- Type:
str
- gender¶
gender. 0 - woman, 1- man
- Type:
int
- gender_obtaining_method¶
how the gender was obtained
- Type:
int
- gender_version¶
gender version
- Type:
int
- class luna_faces.db.faces_db_tools.models.faces_models.Column(_Column__name_pos=None, _Column__type_pos=None, /, *args, name=None, type_=None, autoincrement='auto', default=_NoArg.NO_ARG, insert_default=_NoArg.NO_ARG, doc=None, key=None, index=None, unique=None, info=None, nullable=SchemaConst.NULL_UNSPECIFIED, onupdate=None, primary_key=False, server_default=None, server_onupdate=None, quote=None, system=False, comment=None, insert_sentinel=False, _omit_from_statements=False, _proxies=None, **dialect_kwargs)[source]¶
Release some pretty methods for sqlalchemy.Column.
- in_(other)[source]¶
Split large “.in_” calls.
- Parameters:
other (
Any) – some values in list (or tuple) or select statement- Return type:
or_- Returns:
prepared or filter or just called in_
- inherit_cache = True¶
Indicate if this
HasCacheKeyinstance should make use of the cache key generation scheme used by its immediate superclass.The attribute defaults to
None, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value toFalse, except that a warning is also emitted.This flag can be set to
Trueon a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass.See also
compilerext_caching - General guideslines for setting the
HasCacheKey.inherit_cacheattribute for third-party or user defined SQL constructs.
- class luna_faces.db.faces_db_tools.models.faces_models.Descriptor(**kwargs)[source]¶
Database table model for descriptors.
- descriptor_generation¶
descriptor generation
- Type:
int
- descriptor_obtaining_method¶
how the descriptor was obtained
- Type:
int
- descriptor_version¶
descriptor version
- Type:
int
- face_id¶
face id, uuid.
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.Face(**kwargs)[source]¶
Database table model for faces.
- account_id¶
account uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”, to which this face belong
- Type:
str
- avatar¶
url to image, that represents the face
- Type:
str
- create_time¶
date and time of creating face
- Type:
DateTime
- external_id¶
external id of the face, if it has its own mapping in external system
- Type:
str
- face_id¶
face id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- last_update_time¶
date and time of last changed of the face
- Type:
DateTime
- user_data¶
client info about the face
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.List(**kwargs)[source]¶
Database table model for lists.
Warning
trg_lists_deletion_log ~— after delete trigger for logging
- account_id¶
account uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”, to which this list belong
- Type:
str
- create_time¶
date and time of creating list
- Type:
DateTime
- last_update_time¶
date and time of last changed of the list
- Type:
DateTime
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- user_data¶
client info about the list
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.ListFace(**kwargs)[source]¶
Database table model for links between faces and lists.
- face_id¶
face id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- last_update_time¶
date and time of last attach/detach face to list
- Type:
DateTime
- link_key¶
number of link face to list
- Type:
int
- link_key_index = Index('list_id_link_key_index', Column('list_id', String(length=36), ForeignKey('list.list_id'), table=<list_face>, primary_key=True, nullable=False), Column('link_key', Integer(), table=<list_face>, nullable=False, default=Sequence('link_key', metadata=MetaData())))¶
index link keys
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- matcher_load_delta_index = Index('matcher_load_delta_index', Column('link_key', Integer(), table=<list_face>, nullable=False, default=Sequence('link_key', metadata=MetaData())))¶
index for load delta into matcher
- class luna_faces.db.faces_db_tools.models.faces_models.ListsDeletionLog(**kwargs)[source]¶
Database table model for lists deletions history
After delete trigger trg_lists_deletion_log` (table list) insert a data.
- account_id¶
account uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”, to which this face belong
- Type:
str
- create_time¶
create time list
- Type:
DateTime
- deletion_id¶
deletion id
- Type:
str
- deletion_time¶
date list removig
- Type:
DateTime
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.MV_LINK(**kwargs)[source]¶
- link_key¶
number of link face to list
- Type:
int
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.MV_LINK_0(**kwargs)[source]¶
- link_key¶
number of link face to list
- Type:
int
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.MV_LINK_1(**kwargs)[source]¶
- link_key¶
number of link face to list
- Type:
int
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- class luna_faces.db.faces_db_tools.models.faces_models.MV_UNLINK(**kwargs)[source]¶
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- unlink_key¶
number of link face to list
- Type:
int
- class luna_faces.db.faces_db_tools.models.faces_models.MV_UNLINK_0(**kwargs)[source]¶
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- unlink_key¶
number of link face to list
- Type:
int
- class luna_faces.db.faces_db_tools.models.faces_models.MV_UNLINK_1(**kwargs)[source]¶
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- unlink_key¶
number of link face to list
- Type:
int
- class luna_faces.db.faces_db_tools.models.faces_models.RequestsCache(**kwargs)[source]¶
Model that provides cached data for various often used requests
- class luna_faces.db.faces_db_tools.models.faces_models.Sample(**kwargs)[source]¶
Database model to store samples.
- face_id¶
parent face id, uuid.
- Type:
str
- sample_id¶
id(uuid) of warp
- Type:
str
- type¶
enum for sample type, check ‘SampleType’ in luna_faces/utils/enums.py
- Type:
int
- class luna_faces.db.faces_db_tools.models.faces_models.UnlinkAttributesLog(**kwargs)[source]¶
Database table model for history attach and detach attributes to lists.
- face_id¶
face id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- link_key¶
number of link face to list
- Type:
int
- list_id¶
list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
- Type:
str
- unlink_key¶
number of unlink face to list
- Type:
int
- unlink_key_index = Index('list_id_unlink_key_index', Column('list_id', String(length=36), ForeignKey('list.list_id'), table=<unlink_attributes_log>), Column('unlink_key', Integer(), table=<unlink_attributes_log>, primary_key=True, nullable=False, default=Sequence('unlink_key', metadata=MetaData())))¶
index unlink keys
- update_time¶
date and time of detach attributes from list
- Type:
DateTime
Temporary attributes storage¶
Each temporary attribute is stored as a single Redis key-value record in the database
configured by LUNA_ATTRIBUTES_DB. The key is attributeId and the value is the
binary representation of a TemporaryAttributes
object. The account ID is part of the value, not the key.
Record structure:
Redis record
key: attributeId
value: MessagePack-encoded TemporaryAttributes
expiration: TTL in seconds
Stored fields¶
Field |
Type |
Description |
|---|---|---|
|
String |
Attribute identifier, also used as the Redis key. |
|
String |
Identifier of the account that owns the attribute. |
|
Datetime |
Object creation time in UTC. |
|
BasicAttributes or None |
Age, gender and ethnicity. |
|
List of Descriptor objects |
Descriptors of different versions; an empty list when absent. |
|
List of strings |
Sample identifiers associated with basic attributes; an empty list when absent. |
|
List of strings |
Sample identifiers associated with descriptors; an empty list when absent. |
BasicAttributes contains age, gender and ethnicity.
Each Descriptor contains raw descriptor bytes in descriptor and an integer
descriptor version. Sample lists contain identifiers, not image data.
Binary format¶
The value is a MessagePack extension of type 1 containing a field dictionary. Nested structures and the creation time use the following extension types:
Code |
Type |
Payload |
|---|---|---|
1 |
TemporaryAttributes |
MessagePack-encoded field dictionary. |
2 |
BasicAttributes |
MessagePack-encoded field dictionary. |
3 |
Descriptor |
MessagePack-encoded field dictionary, including binary descriptor data. |
127 |
Datetime |
MessagePack-encoded ISO 8601 string. |
Expiration¶
The creation request supplies ttl in seconds. When omitted, it defaults to
ATTRIBUTES_STORAGE_POLICY.DEFAULT_TTL (300 seconds by default). The maximum is
ATTRIBUTES_STORAGE_POLICY.MAX_TTL (86400 seconds by default).
The supplied integer value is limited to the range from 1 to this maximum.
TTL is stored as the Redis key expiration, not as a field in the value. Redis expires the record when its TTL elapses.
Model reference¶
- class luna_faces.attributes_db.model.TemporaryAttributes(accountId, attributeId=None, descriptors=None, basicAttributes=None, basicAttributesSamples=None, descriptorSamples=None)[source]¶
Container for temporary attribute.
- Attributes
basicAttributes (Optional[BasicAttributes]): basic attributes createTime (datetime): attribute create time attributeId (str): attribute id accountId (str): account id descriptors (Optional[List[Descriptor]]): list of descriptors different versions basicAttributesSamples (Optional[List[str]): basic attributes samples descriptorSamples (Optional[List[str]])): descriptors samples