ask method allows you to ask questions about your ingested documents and receive answers grounded in your content. The SDK supports conversational memory, enabling follow-up questions that maintain context.
Method Overview
Sync Method
client.sources.ask()Async Method
await client.sources.ask()Method Signature
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
question | str | The question to ask about your documents | ✅ Yes |
conversation_id | str | Conversation identifier to maintain memory context across questions | No |
reset | bool | When True, starts a new conversation and ignores previous history | No |
file_ids | list[str] | Restrict search to specific documents by file ID (preferred) | No |
file_names | list[str] | Restrict search to specific documents by file name (deprecated, use file_ids) | No |
output_schema | dict | JSON Schema to request structured output (see below) | No |
thinking_level | str | Controls model and thinking configuration: "fast", "balanced", "accurate" (default) | No |
timeout | float | Request timeout in seconds | No |
Thinking Level
Thethinking_level parameter controls the model and thinking configuration used for answering questions:
| Value | Description |
|---|---|
"fast" | Uses a faster model without extended thinking. Best for simple questions where speed is prioritized. |
"balanced" | Uses a more capable model with low thinking. Good balance between quality and speed. |
"accurate" | Default. Uses a more capable model with high thinking. Best for complex questions requiring deep reasoning. |
Response Object
The method returns aSourceAskResponse object:
| Property | Type | Description |
|---|---|---|
answer | str | The answer to your question. When output_schema is provided, this will be a short status message. |
conversation_id | str | None | Conversation identifier for follow-up questions |
structured_output | dict | None | Structured output validated against the requested output_schema. Present only when output_schema is provided. |
raw_json | str | None | Raw JSON-text produced by the model before validation. Present only when output_schema is provided. |
Code Examples
Basic Question
Conversation with Memory
Useconversation_id to maintain context across multiple questions:
Reset Conversation
Start fresh by using thereset parameter:
Filter by Specific Documents
Restrict the search to specific files usingfile_ids (preferred):
Using Thinking Level
Control the model’s reasoning depth withthinking_level:
Structured Output with JSON Schema
Request structured data by providing anoutput_schema:
Extract Array of Items
Extract multiple items with a schema:Async Usage
Error Handling
Advanced Examples
Chatbot Class
Build a conversational chatbot:Multi-Document Q&A
Ask questions across multiple documents:Structured Data Extraction Pipeline
Extract structured data from multiple documents:Async Parallel Questions
Ask multiple questions in parallel:Interactive Q&A Session
Build an interactive command-line Q&A:Output Schema Guidelines
When usingoutput_schema, follow these guidelines:
Supported Schema Features
- Basic types:
string,number,integer,boolean,null - Objects with
properties - Arrays with
items - Union with
nullonly:["string", "null"]
Unsupported Features
oneOf,anyOf,allOf$refreferences- Complex unions beyond
null
Schema Examples
Error Reference
| Error Type | Status Code | Description |
|---|---|---|
BadRequestError | 400 | Invalid parameters or request format |
AuthenticationError | 401 | Invalid or missing API key |
NotFoundError | 404 | Specified file not found |
UnprocessableEntityError | 422 | Invalid output_schema or structured output validation failed |
RateLimitError | 429 | Too many requests, please retry after waiting |
InternalServerError | ≥500 | Server-side error |
APIConnectionError | N/A | Network connectivity issues |
APITimeoutError | N/A | Request timed out |
Best Practices
-
Use conversation memory — Pass
conversation_idfor follow-up questions to maintain context - Be specific — Clear, specific questions get better answers
-
Scope when needed — Use
file_namesto focus on specific documents for faster, more accurate responses -
Use structured output for integration — Provide
output_schemato get JSON you can reliably parse in code -
Reset when changing topics — Set
reset=Truewhen switching to unrelated questions - Handle errors gracefully — Implement proper error handling for production applications

