Skip to main content
The 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() (using AsyncGraphor)

Method Signature

Parameters

Thinking Level

The thinking_level parameter controls the model and thinking configuration used for answering questions:

Response Object

The method returns a SourceAskResponse object:

Citations

Each entry in citations corresponds to one [N] marker that appears in the answer text. Use index to map a marker to its citation.

When to use include_citation_images

The include_citation_images flag is convenient for quick prototyping or one-off requests where you want both the answer and the visual previews in a single round-trip. For real applications — especially when answers commonly cite many pages — prefer leaving the flag as False (the default) and lazy-load the screenshots on demand via the dedicated get_page_screenshot method. Reasons:
  • Payload size: each base64 PNG is typically 100-400 KB. Five citations can push the JSON response above a megabyte.
  • Latency: rendering screenshots adds seconds to the response. Without the flag, the answer comes back as soon as the model finishes.
  • Cache locality: the screenshot endpoint is keyed by (file_id, page_number) and emits a Cache-Control hint. Lazy-loading lets browsers and CDNs cache the bytes; inlining base64 prevents that.
Rule of thumb: enable include_citation_images=True only when you control both ends and know the answer will cite at most 1-2 pages. Otherwise, ship the answer with structured citations and fetch images on hover/click.

Code Examples

Basic Question

Conversation with Memory

Use conversation_id to maintain context across multiple questions:

Reset Conversation

Start fresh by using the reset parameter:

Filter by Specific Documents

Restrict the search to specific files using file_ids (preferred):

Working with Citations

Every grounded answer comes back with a structured citations array. The default flow is fetch screenshots on demand — only render images for the citations the user actually inspects.

Inlining citation images in the response

When you really do want the screenshots in the same round-trip — for example, a one-off batch job that won’t be re-rendered — set include_citation_images=true. Avoid this in interactive UIs and any flow where the answer typically cites many pages.

Using Thinking Level

Control the model’s reasoning depth with thinking_level:

Structured Output with JSON Schema

Request structured data by providing an output_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:

Parallel Questions

Ask multiple questions in parallel:

Interactive Q&A Session

Build an interactive command-line Q&A:

Output Schema Guidelines

When using output_schema, follow these guidelines:

Supported Schema Features

  • Basic types: string, number, integer, boolean, null
  • Objects with properties
  • Arrays with items
  • Union with null only: ["string", "null"]

Unsupported Features

  • oneOf, anyOf, allOf
  • $ref references
  • Complex unions beyond null

Schema Examples

Error Reference

Best Practices

  1. Use conversation memory — Pass conversation_id for follow-up questions to maintain context
  2. Be specific — Clear, specific questions get better answers
  3. Scope when needed — Use file_ids or file_names to focus on specific documents for faster, more accurate responses
  4. Use structured output for integration — Provide output_schema to get JSON you can reliably parse in code
  5. Reset when changing topics — Set reset=True when switching to unrelated questions
  6. Lazy-load citation images — Keep include_citation_images=False (the default) and call get_page_screenshot on demand. Inlining base64 only makes sense for low-citation, low-frequency requests — for typical chat UIs it bloats the payload by hundreds of KB per cited page.
  7. Parse citations, not the markup — Use the structured citations array. The inline [N](file_id|pX|...) markup is hidden by default and is an implementation detail that may change.
  8. Handle errors gracefully — Implement proper error handling for production applications

Next Steps

Get Page Screenshot

Lazy-load citation page previews on demand

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