Skip to main content

Highlighting API

API to generate highlight locations for a search term in the document which has been extracted using LLMWhisperer. This can be used to highlight the search terms in your frontend application.

Note: The parameter store_metadata_for_highlighting should be set to true while starting the whisper process to use this API.

Endpoint/highlight-data
URLhttps://llmwhisperer-api.unstract.com/v1/highlight-data
MethodPOST
Headersunstract-key: <YOUR API KEY>

Parameters

ParameterTypeDefaultRequiredDescription
whisper-hashstringYesThe whisper hash returned while starting the whisper process.

Request Body

The request body should contain the search term. The Content-Type should be text/plain.

Example Curl Request

curl -X POST --location 'https://llmwhisperer-api.unstract.com/v1/highlight-data?whisper-hash=XXXXXXXXXXXXXXXXXXX' \
-H 'unstract-key: <Your API Key>' \
-H 'Content-Type: text/plain' \
--data 'search term'
info

To include the headers in the response use curl -i in the request.

Response

HTTP StatusContent-TypeHeadersDescription
200application/jsonHighlight information
400application/jsonError while retrieveing. Refer below for JSON format

Highlight Data

The API will return the highlight data in the response body. The JSON response will contain an array of JSON objects. Each object will contain the following fields:

FieldTypeDescription
textstringThe search term (or part of)
pageintegerThe page number where the search term is found. 0 indexed
posintegerThe position of the search term in the text. 0 indexed
leftfloatThe left position of the search term in the page.
topfloatThe top position of the search term in the page.
widthfloatThe width of the search term in the page.
heightfloatThe height of the search term in the page.
distanceintegerThe Levenshtein distance of the search term from the match.
location_typestringThe unit of the location values. Can be inches or points based on how the original document was created and processed

Example 200 Response

{
"highlight_data": [
{
"distance": 4,
"height": 0.11460000000000026,
"left": 6.2699,
"location_type": "inches",
"page": 0,
"pos": 960,
"text": "U.S.",
"top": 2.9505,
"width": 0.20060000000000056
},
{
"distance": 4,
"height": 0.11940000000000017,
"left": 6.4944,
"location_type": "inches",
"page": 0,
"pos": 965,
"text": "Citizen",
"top": 2.9505,
"width": 0.34860000000000024
}
]
}

Example 400 Response

{
"message": "No Metadata found"
}