POST
/
v2
/
library
/
{library_id}
/
query
curl --request POST \
  --url https://api.libraria.ai/v2/library/{library_id}/query \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "query": "<string>",
  "conversationId": {},
  "streaming": {}
}'
{
  "reply": "The capital of France is Paris.",
  "conversationId": "optional-unique-id",
  "metadata": {
      "documents": [
          {
  			"id": "some-document-id",
  			"title": "The france capital",
  			"similarity": 0.966698234468654,
  			"extraFields": {
  				"learnMoreLink": {
  					"url": "https://france-capital",
  					"text": "The France Capital"
  				}
  			}
  		},
      ],
      "images": [],
      "helpArticles": [
          {
              "url": "https://france-capital",
              "text": "The France Capital"
  		}
      ]
  }
}

Parameters

library_id
string
required

The ID of the library you are going to ask a question

Body

query
string
required

The question you will make to the library.

conversationId
string | null

Optional. Use this for a continuation of the conversation. You will receive a conversation id on the first query you send.

streaming
boolean | null

Optional. Whether or not you want to receive a streamed response. Default value is False.

Response

The response will vary according to the value of the streaming attribute.

Non-streamed response

When streaming is false, the response will be a JSON object containing the following fields

reply
string
required

The response from the library for the query provided in the request body

conversationId
string
required

Use this in follow-up requests for a continuation of the conversation. You will receive a conversation id on the first query you send.

metadata
json
required

A map containing data used to generate the query response. It provides additional sources of information to the reply.

Streamed response

When streaming is true, the response is sent as a series of chunks where each of them will be a JSON object.

All chunks includes a type param the describes how the rest of the JSON will look like

type
string
required

Specifies the type of the chunk that is being sent

Possible values are: initializing, token, response, done

type == initializing

The initial chunk when the stream has just be opened.

Example:

{"type": "initializing"}

type == token

Each token represents a partial response sent from the library. When all chunks are concatenated together, you will have the final response.

The body will include a value attribute the will include the current token sent.

value
string

It represents the token that is currently being sent as part of a partial response. If you concatenate all tokens you will have the complete response.

{"type": "token",
 "value": "Paris"}

type == response

It contains the final response and additional metadata that has been used to generate the response

The body will include a data attribute the will include the final response and the metadata.

data
json

A json object containing the final response and additional metadata that has been used to generate the response.

done

The final chunk sent before the stream is closed.

Example:

{"type": "done"}