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
- Python
- TypeScript
Sync Method
client.sources.ask()Async Method
await client.sources.ask() (using AsyncGraphor)Method Signature
- Python
- TypeScript
Parameters
- Python
- TypeScript
| 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
- Python
- TypeScript
Conversation with Memory
Useconversation_id to maintain context across multiple questions:
- Python
- TypeScript
Reset Conversation
Start fresh by using thereset parameter:
- Python
- TypeScript
Filter by Specific Documents
Restrict the search to specific files usingfile_ids (preferred):
- Python
- TypeScript
Using Thinking Level
Control the model’s reasoning depth withthinking_level:
- Python
- TypeScript
Structured Output with JSON Schema
Request structured data by providing anoutput_schema:
- Python
- TypeScript
Extract Array of Items
Extract multiple items with a schema:- Python
- TypeScript
Async Usage
- Python
- TypeScript
Error Handling
- Python
- TypeScript
Advanced Examples
Chatbot Class
Build a conversational chatbot:- Python
- TypeScript
Multi-Document Q&A
Ask questions across multiple documents:- Python
- TypeScript
Structured Data Extraction Pipeline
Extract structured data from multiple documents:- Python
- TypeScript
Parallel Questions
Ask multiple questions in parallel:- Python
- TypeScript
Interactive Q&A Session
Build an interactive command-line Q&A:- Python
- TypeScript
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
- Python
- TypeScript
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_idsorfile_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
- Python
- TypeScript
Next Steps
Document Chat Guide
Learn best practices for chatting with your documents
Extract API
Extract structured data from documents
Upload Sources
Upload documents to chat with
Prebuilt RAG
Retrieve relevant chunks from your documents

