Log In

Search lets you find the relevant answer to a user query across all your trained documents. To search just send the query and you will receive the result in the form of a list of documents paired with the character offsets corresponding to the most relevant answers. The parameter you can set for the search are:

  • query: the user search
  • k: the number of results retrieved. If set to -1 it will retrieve all the results
  • query_correction (Optional default to False): enable suggestion of the correct query
  • one_per_document (Optional default to False): If set to True, it will only show one result per document. If set to False instead it may return more than one relevant result per document

This is what a search request would look like:

curl --location --request GET 'https://api.pigro.ai/search?query=what%20is%20the%20revenue%20of%20Tesla%20in%202020?&k=8' \
--header 'Content-Type: application/json' \
--header 'x-api-key: gAXwA2KGnJutbDJof0nqyh_ybUq_sdoMNje-WnMi-fs' \

The results will be as follows:

{
    "result": [
        {
            "document_id": 4841,
            "span": {
                "start": 128,
                "end": 319
            }
        },
        {
            "document_id": "aXXhkoS",
            "span": {
                "start": 0,
                "end": 432
            }
        },
        {
            "document_id": 4880,
            "span": {
                "start": 333,
                "end": 639
            }
        },
        {
            "document_id": "32",
            "span": {
                "start": 129,
                "end": 148
            }
        },
        {
            "document_id": 4841,
            "span": {
                "start": 699,
                "end": 964
            }
        },
        {
            "document_id": 4843,
            "span": {
                "start": 0,
                "end": 595
            }
        },
        {
            "document_id": "OaxlLKsjvbaue",
            "span": {
                "start": 211,
                "end": 341
            }
        },
        {
            "document_id": 4880,
            "span": {
                "start": 1832,
                "end": 1956
            }
        }
    ],
    "search_time": 0.122122,
    "suggested_query": null
}

The span offsets refer to the original HTML document (or plain text) used during the upload phase. The start and the end are the characters delimiting the span of text where the answer is contained. It is possible that multiple results come from the same document, if more than one relevant answer is found inside it.

If the query_correction is set to True the suggested_query parameter will be filled with the corrected query if a typo is found:

{
	...
	"suggested_query": "what was the revenue of Tesla in 2020?"
	...
}

or with an empty string if no typo is found:

{
	...
	"suggested_query": ""
	...
}