Matching client

Indexed matching requests can be executed through a matcher client.

Typical usage example:

>>> from luna3.common.http_objs import RawDescriptor
>>> from client import MatcherClient

>>> client = await MatcherClient.create("redis://localhost:6379")

>>> descriptor = RawDescriptor(descriptor=b"1" * 512, version=59)
>>> async with client.session() as conn:
>>>     response = await conn.match(
            descriptor=descriptor,
            label="87bd1c29-5dc7-4ef3-9479-5184a2f8f6a0",
            limit=1,
            lunaRequestId="1653383336,38a97f88-2226-4907-8ea8-d36d80690ce6",
            timeout=10,
        )
>>> print(response)
{
    "luna_request_id": "1653383336,38a97f88-2226-4907-8ea8-d36d80690ce6",
    "status_code": 201,
    "result": [[ ..., ...]]
    "error": None
}

>>> anotherVersionDescriptor = RawDescriptor(descriptor=b"1" * 512, version=0)
>>> async with client.session() as conn:
>>>     response = await conn.match(
            descriptor=RawDescriptor(anotherVersionDescriptor,
            label="87bd1c29-5dc7-4ef3-9479-5184a2f8f6a0",
            limit=1,
            lunaRequestId="1653383336,38a97f88-2226-4907-8ea8-d36d80690ce6",
            timeout=10,
        )

>>> print(response)
{
    "luna_request_id": "1653383336,38a97f88-2226-4907-8ea8-d36d80690ce6",
    "status_code": 400,
    "result": None,
    "error": {"error_code": 26305, "desc": "Descriptor version mismatch", "detail": "Descriptor of version 0 cannot be searched in index of version 59", "link": "https://docs.visionlabs.ai/info/luna/troubleshooting/errors-description/code-26305"}
}

>>> await client.close()

The luna_request_id field is external matching request ID. It helps to identify messages in system logs that correspond to particular requests. If external request ID is not specified, the new unique request ID will be generated.

Labels available for matching can be checked as follows:

>>>     response = await client.readMatchingLabels()
>>>     print(response)

["87bd1c29-5dc7-4ef3-9479-5184a2f8f6a0", "17cdbe41-c7f1-440b-b9ad-aad93c7176ee", "8c8309ad-627a-40d6-9a2d-fe87fcf8867e"]

>>>     response = await client.checkMatchingLabel("87bd1c29-5dc7-4ef3-9479-5184a2f8f6a0")
>>>     print(response)

True