Direct API Requests to Tarantool¶
You can use HTTP API to extract data directly from the Tarantool Database.
In this section:
General Information¶
API requests to Tarantool are to be sent to http://<tarantool_host_ip:port>
.
Tip
The port for API requests can be found in the FindFace.start
section of the Tarantool configuration file:
cat /etc/tarantool/instances.available/FindFace.lua
##8101:
FindFace.start("127.0.0.1", 8101)
Note
In the case of the standalone deployment, you can access Tarantool by default only locally (127.0.0.1). If you want to access Tarantool remotely, alter the Tarantool configuration file.
API requests to Tarantool may contain the following parameters in path segments:
:ver
: API version (v2 at the moment).:name
: gallery name.Tip
To list gallery names on a shard, type in the following command in the address bar of your browser:
http://<tarantool_host_ip:shard_port>/stat/list/1/99
The same command on the console is as such:
curl <tarantool_host_ip:shard_port>/stat/list/1/99 \| jq
You can also list gallery names by using a direct request to Tarantool:
echo 'box.space.galleries:select()' | tarantoolctl connect <tarantool_host_ip:shard_port>
Note that if there is a large number of shards in the system, chances are that a randomly taken shard does not contain all the existing galleries. In this case, just list galleries on several shards.
Add Face¶
POST /:ver/faces/add/:name
Parameters in body:
JSON-encoded array of faces with the following fields:
"id"
: face id in the gallery, uint64_t,"facen"
: raw feature vector, base64,"meta"
: face metadata, dictionary.
Returns:
- HTTP 200 and empty body on success.
- HTTP 404 if a gallery with the given name doesn’t exist.
- HTTP with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -s 'http://localhost:8101/v2/faces/add/testgal' --data '
[
{
"id": 9223372036854776000,
"facen": "qgI3vZRv/z…NpO9MdHavW1WuT0=",
"meta": {
"cam_id": "223900",
"person_name": "Mary Ostin",
}
}
]
Response
HTTP/1.1 200 Ok
Content-length: 1234
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
Remove Face¶
POST /v2/faces/delete/:name
Parameters in body:
JSON-encoded array of face ids to be removed
Returns:
- HTTP 200 and empty body on success.
- HTTP 404 if a face with the given id is not found in the gallery.
- HTTP with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -s 'http://localhost:8101/v2/faces/delete/testgal' --data '[1, 4, 922, 3]'
Response
HTTP/1.1 200 Ok
Content-length: 111
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
Face Search¶
POST /v2/faces/search/:name
Parameters in body:
JSON-encoded search request with the following fields:
limit
: maximum number of faces in the response.sort
: sorting order. Pass one of the following values:id
: increasing order by id,-id
: decreasing order by id,-score
: decreasing order by face similarity (only if you search for faces with similar feature vectors).filter
(filters):facen
: (optional) search for faces with similar feature vectors. Pass a dictionary with the following fields:data
: raw feature vector, base64;score
: range of similarity between faces [threshold similarity; 1], where1
is 100% match.id
andmeta/<meta_key>
: search by face id and metastring content. To set this filter, use the following operators:range
: range of values, only for numbers.set
: id or metastring must contain at least one value from a given set, for numbers and strings.subset
: id or metastring must include all values from a given subset, for numbers and strings.like
: by analogy withlike
in SQL requests: only ‘aa%’, ‘%aa’, and ‘%aa%’ are supported. Only for strings and set[string]. In the case of set[string], the filter will return result if at least one value meets the filter condition.ilike
: by analogy withlike
but case-insensitive, only for strings and set[string].
Returns:
JSON-encoded array with faces on success. The value in the
X-search-stat
header indicates whether the fast index was used for the search:with_index
orwithout_index
.Note
Fast index is not used in API v2.
HTTP with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -s 'http://localhost:8101/v2/testgal/search' --data '
{
"limit": 2,
"sort": {
"score": -1
},
"filter": {
"facen": {
"data": "qgI3vZRv/z0BQTk9rcirOyZrNpO9MdHavW1WuT0=",
"score": [0.75, 1]
},
"id": {
"range": [9223372036854000000, 9223372036854999000]
},
"meta": {
"person_id": {
"range": [444, 999]
},
"cam_id": {
"set": ["12767", "8632", "23989"]
}
}
}
}'
Response
HTTP/1.1 200 Ok
Content-length: 1234
X-search-stat: without_index
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
{
"results": [
{
"facen": " qgI3vZRv/z0BQTk9rcirOyZrNpO9MdHavW1WuT0=",
"meta": {
"timestamp": 0,
"photo_hash": "",
"person_id": 777,
"cam_id": "8632"
},
"score": 0.9964,
"id": 9223372036854776000
}
]
}
Edit Face Metadata and Feature Vector¶
POST /v2/faces/update/:name
Parameters in body:
JSON-encoded array with faces with the following fields:
"id"
: face id, uint64_t."facen"
: (optional) new feature vector, base64. If omitted or passed asnull
, the relevant field in the database won’t be updated."meta"
: dictionary with metadata to be updated. If some metastring is omitted or passed asnull
, the relevant field in the database won’t be updated.
Returns:
- HTTP 200 and dictionary with all face parameters, including not updated, on success.
- HTTP 404 and error description if a face with the given id doesn’t exist.
- HTTP with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -s 'http://localhost:8101/v2/faces/update/sandbox' --data '[{"id":1,"facen":null,"meta":{"m:timestamp":1848}}]'
Response
HTTP/1.1 200 Ok
Content-length: 151
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
{"meta":{"m:timestamp":1848,"normalized_id":"1_b9pkrf00mjt6h1vmq1kg.png","m:cam_id":"a9f7a973-f07e-469d-a3bd-41ddd510b26f","feat":"{\"score\":0.123}"}, "id":1, ... }
List Galleries¶
POST /v2/galleries/list
Returns:
JSON-encoded array with galleries with the following fields: name
: gallery name, faces
: number of faces in a gallery.
Example
Request
curl -D - -s -X POST http://localhost:8101/v2/galleries/list
Response
HTTP/1.1 200 Ok
Content-length: 42
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
{
"results": [
{
"name": "testgal",
"faces": 2
}
]
}
Get Gallery Info¶
POST /v2/galleries/get/:name
Returns:
- HTTP 200 and dictionary with gallery parameters on success.
- HTTP 404 and error description if a gallery with the given name doesn’t exist.
- HTTP with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -s -X POST http://localhost:8101/v2/galleries/get/testgal
HTTP/1.1 200 Ok
Content-length: 11
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
{"faces":2}
Create Gallery¶
POST /v2/galleries/add/:name
Returns:
- HTTP 200 and empty body on success.
- with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -X POST -s 'http://localhost:8101/v2/galleries/add/123'
Response
HTTP/1.1 409 Conflict
Content-length: 57
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive
{"error":{"message":"gallery already exists","code":409}}
Remove Gallery¶
POST /v2/galleries/delete/:name
Returns:
- HTTP 200 and empty on success.
- with a status other than 200 and error description in the body on failure.
Example
Request
curl -D - -X POST -s 'http://localhost:8101/v2/galleries/delete/123'
Response
HTTP/1.1 204 No content
Content-length: 0
Server: Tarantool http (tarantool v1.7.3-673-g23cc4dc)
Connection: keep-alive