Query API

The Query API is used to retrieve answers to search queries. This section walks you through understanding and using the Query API, a must when developing your own applications on top of Sparque.

Basics of the Query API

The Query API is fully stateless. Making the same request twice will yield the same result twice. This also means that every request that is made of the Query API must contain all relevant information for the execution of that request.

All requests made of the Query API use the HTTP GET request method.

A request URL is constructed out of 4 parts:

  • root::

    The the base of the search application.

  • query::

    The the part of the request that specifies the query you want an answer to.

  • response type::

    Defines defines what response you expect: a page of results, the facet options, or statistics about the query.

  • options::

    Optional optional modifiers such as count, offset, or cutoff.

Request Root

All requests have a root of the following form:

GET https://rest.sparque.ai/<name>/

Where <name> is the name of your workspace.

A workspace is the environment within Sparque Desk in which users create datasets, pipelines, strategies, APIs, testsets.

Query

Endpoints

In Sparque Desk, users can expose strategies through the Query API as endpoints. These endpoints are grouped together in an API. APIs and endpoints belong to a workspace and have their own names.

The query part of a request specifies which API and endpoint(s) to use, along with values for their parameters:

GET /api/<api>/e/<endpoint>/p/<name>/<value>

Where <api> is the name of the API (preceded by '/api/'), <endpoint> is the name of the endpoint (preceded by '/e/' for endpoint), <name> is the name of the parameter (preceded by '/p/' for parameter) and <value> is its value.

Example request

GET /api/portal/e/search/p/topic/john/

Parameters

The parameters that can be filled are defined by the endpoint. Sign in to Sparque Desk to view the exposed APIs and endpoints.

An endpoint can have 0 to many parameters. Filling multiple parameters using the Query API is done by simply appending them:

GET /api/<api>/e/<endpoint>/p/<name1>/<value1>/p/<name2>/<value2>

The order in which the set of parameters is given is not relevant. Specifying the same parameters multiple times with different values is not allowed, and the result is not defined in such cases.

Example request

GET /api/portal/e/search/p/topic/utrecht/p/color/purple

Stacking Endpoints

Some endpoints take the result of another endpoint as input. These are called stackable endpoints and can be used as follows:

GET /e/<endpoint1>/p/<name1>/<value1>/e/<endpoint2>/p/<name2>/<value2>

Where <endpoint1> is the name of the first endpoint, <name1> is the name of a parameter of the first endpoint, <value1> is its value, <endpoint2> is the name of the endpoint that receives the result of the first endpoint as input, <name2> is the name of a parameter of this second endpoint and <value2> is its value.

The stacking of more than one endpoint is supported.

Response Type

The end of the URL path specifies the response type you expect. This can be: results or statistics.

Results

GET /e/<endpoint>/.../results

Provides a list of results, sorted on probability.

Example request

GET /api/portal/e/search/p/topic/utrecht/results

Example response

{
  "offset": 0,
  "count": 10,
  "type": [
      "OBJ"
  ],
  "items": [
    {
      "rank": 1,
      "probability": 1.0,
      "tuple": [
        {
          "id": "...",
          "class": [
            "..."
          ],
          "attributes": {
            "name": "..."
          }
        }
      ]
    }
  ]
}

Statistics

GET /e/<endpoint>/.../statistics

Provides information about the number of matches, and information about the distribution of probabilities in the result set.

Example request

GET /api/portal/e/search/p/topic/utrecht/statistics

Example response

{
  "total": 30999,
  "stats": [
    {
      "cutoff": "0.1",
      "numResults": 10
    },
    {
      "cutoff": "0.01",
      "numResults": 5362
    },
    {
      "cutoff": "0.001",
      "numResults": 25627
    }
  ]
}  

Request Options

The following options can be added to the URL query string:

  • config::

    Name of the configuration to use. Dafault value is 'default' (the initial configuration of a workspace).

When using the results response type, these additional options are available:

  • count::

    Number of items returned. Default value is 10. Should be between 1 and 100.

  • offset::

    Offset on the number of items returned. Default is 0. Should be 0 or more.

  • format::

    Formatting of the results: json/xml/rdf/csv/xlsx. Default value is 'json'.

    Note: XML is not enabled by default, and RDF can only be requested when the ouput of strategy is [STRING,STRING,STRING]

  • level::

    Level the result descriptions. Default value is 1. Should be 0 or more.

  • homogeneousArrays::

    Boolean option to specify whether items in a result-tuple are returned as an array (false) or as an object (true). This option was introduced because some programming environments struggle with arrays that contain heterogeneous items (mix of strings, numbers, arrays, objects).