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.

_images/faces_db.png
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 HasCacheKey instance 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 to False, except that a warning is also emitted.

This flag can be set to True on 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_cache attribute 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

number of link face to list

Type:

int

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

number of link face to list

Type:

int

list_id

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

number of link face to list

Type:

int

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

number of link face to list

Type:

int

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

list_id

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

number of link face to list

Type:

int

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

number of link face to list

Type:

int

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

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

number of link face to list

Type:

int

list_id

list id, uuid in format “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

Type:

str

number of unlink face to list

Type:

int

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

TemporaryAttributes state

Field

Type

Description

attributeId

String

Attribute identifier, also used as the Redis key.

accountId

String

Identifier of the account that owns the attribute.

createTime

Datetime

Object creation time in UTC.

basicAttributes

BasicAttributes or None

Age, gender and ethnicity.

descriptors

List of Descriptor objects

Descriptors of different versions; an empty list when absent.

basicAttributesSamples

List of strings

Sample identifiers associated with basic attributes; an empty list when absent.

descriptorSamples

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:

MessagePack 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

class luna_faces.attributes_db.model.BasicAttributes(age, gender, ethnicity)[source]

Container for basic attributes

age

age (0-100)

Type:

int

gender

gender (0,1)

Type:

int

ethnicity

ethnicity (1, 2, 3, 4)

Type:

int

class luna_faces.attributes_db.model.Descriptor(descriptor, version)[source]

Container for descriptor .. attribute:: descriptor

raw descriptor version (int): descriptor version

type:

bytes