Information Search
This section describes using the API to perform search queries on documents loaded into the InsightStream system. After successful document indexing, the assistant can answer questions using indexed data and provide links to source materials.
Sending a Search Request
After receiving a request, the assistant performs a search in the knowledge base and returns a result with a brief answer, as well as information about found documents.
Below are examples of sending a request using Python and cURL.
- Python
- cURL
import requests
# Replace with your assistant_id and token
assistant_id = "1234"
token = "your_InsightStream_token"
# Question text to the assistant
search_query = "Your question to the assistant"
# Define URL
url = f"http://server_address_or_domain_name:8080/{assistant_id}/api_v1/answers"
headers = {
"Authorization": f"Bearer {token}"
}
params = {
"search_query": search_query,
"sync": 1
}
# Execute GET request
response = requests.get(url, headers=headers, params=params)
# Output status and response
print(response.status_code, response.text)
curl -G "http://server_address_or_domain_name:8080/{assistant_id}/api_v1/answers" \
-H "Authorization: Bearer your_InsightStream_token" \
--data-urlencode "search_query=Your question to the assistant" \
--data "sync=1"
Request Response
Upon successful request execution, the server returns HTTP status 200 OK and a JSON object with search results. Possible response codes:
- 200 OK: Request completed successfully.
- 400 Bad Request: Invalid input data.
- 404 Not Found: Assistant not found or indexing not completed.
- 429 Too Many Requests: Request limit exceeded.
Example Response
{
"summary": "Per diem payments are made within the established period after document verification within 5 days.",
"documents": [
{
"title": "example_1.pdf",
"uri": "https://bot.insightstream.ru/documents/tmp/example_1.pdf",
"passage_md": "Control over compliance with these rules is assigned to the HR department and accounting.",
"doc_type": "application/pdf",
"loc": {
"from": 0,
"to": 1
}
}
],
"relevant_questions": [
"What to do if errors are found in the business trip report?",
"What is the deadline for submitting a business trip report to receive per diem?",
"What documents need to be provided to receive per diem?"
]
}
Response Parameter Descriptions
- summary: Main answer to the asked question.
- documents: Array of objects with information about documents used to form the answer:
- title: Document name.
- uri: Direct link to access the document.
- passage_md: Document fragment used when forming the answer.
- doc_type: MIME type of the document (e.g., application/pdf).
- loc: Character range indicating from which to which character the fragment was taken.
- relevant_questions: List of questions similar to the asked one that may be useful for further information clarification.