Querying the Assistant (Q&A)
Once we've uploaded and processed documents from the knowledge base, we can ask a specific assistant a question and get an accurate answer with source references.
Main URL for API access: https://bot.insightstream.ru
Sending a Question to Get an Answer
GET /{bot_id}/api_v1/answers
After sending the request, the assistant will search the indexed documents and return an answer with source references.
- Python
- cURL
import requests
# Replace with your assistant ID
bot_id = "my_search_bot"
# Replace with your question
search_query = "What are the urgency assessment criteria?"
# Form the URL for the request
url = f"https://bot.insightstream.ru/{bot_id}/api_v1/answers"
# Request parameters
params = {
"search_query": search_query,
"sync": 1 # Synchronous request to get an answer immediately
}
# Execute GET request
response = requests.get(url, params=params)
# Check response status
if response.status_code == 200:
# Get JSON response
answer_data = response.json()
# Print the answer
print(f"Answer: {answer_data['summary']}")
# Print sources
print("\nSources:")
for doc in answer_data["documents"]:
print(f"- {doc['title']}: {doc['passage_md']}")
print(f" URL: {doc['uri']}")
# Print relevant questions
if "relevant_questions" in answer_data:
print("\nSimilar questions:")
for question in answer_data["relevant_questions"]:
print(f"- {question}")
else:
print(f"Error: {response.status_code}")
print(response.text)
curl -G "https://bot.insightstream.ru/my_search_bot/api_v1/answers" \
--data-urlencode "search_query=What are the urgency assessment criteria?" \
--data "sync=1"
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| search_query | string | Yes | Question you're asking the assistant |
| sync | integer | No | If set to 1, the request is executed synchronously and returns an answer immediately. |
Response Codes
- 200 OK: Returns an answer and links to relevant documents.
- 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
The response is returned in JSON format.
{
"summary": "Urgency assessment criteria include task priority, impact on business processes, execution deadlines, and resources required for resolution.",
"documents": [
{
"title": "Task_Assessment_Regulation.pdf",
"uri": "https://bot.insightstream.ru/documents/tmp/Task_Assessment_Regulation.pdf",
"passage_md": "Task urgency assessment criteria include: 1) Priority - high, medium, low; 2) Impact on business processes - critical, significant, minor; 3) Execution deadlines - immediately, within a day, within a week; 4) Required resources.",
"doc_type": "application/pdf",
"loc": {
"from": 12,
"to": 13
}
}
],
"relevant_questions": [
"How to properly assess task priority?",
"Which tasks are considered critical in terms of business impact?",
"How to allocate resources between tasks of different urgency?"
]
}
Response Parameter Descriptions
| Parameter | Description |
|---|---|
| summary | Answer to the asked question, formed based on found documents |
| documents | List of documents used to form the answer |
| title | Document name |
| uri | Link to the source document |
| passage_md | Relevant passage from the document used for the answer |
| doc_type | MIME type of the document (e.g., PDF, DOCX, etc.) |
| relevant_questions | List of similar questions that can be asked to the assistant |