Use this file to discover all available pages before exploring further.
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.
from graphor import Graphorclient = Graphor()# Ask a simple questionresponse = client.sources.ask( question="What are the main findings in this report?")print(f"Answer: {response.answer}")print(f"Conversation ID: {response.conversation_id}")
import Graphor from 'graphor';const client = new Graphor();// Ask a simple questionconst response = await client.sources.ask({ question: 'What are the main findings in this report?',});console.log(`Answer: ${response.answer}`);console.log(`Conversation ID: ${response.conversation_id}`);
Use conversation_id to maintain context across multiple questions:
Python
TypeScript
from graphor import Graphorclient = Graphor()# First questionresponse = client.sources.ask( question="What products are mentioned in the catalog?")print(f"Answer: {response.answer}")# Follow-up question using conversation memoryfollow_up = client.sources.ask( question="Which one is the most expensive?", conversation_id=response.conversation_id)print(f"Follow-up: {follow_up.answer}")# Another follow-upanother = client.sources.ask( question="What are its specifications?", conversation_id=response.conversation_id)print(f"Answer: {another.answer}")
import Graphor from 'graphor';const client = new Graphor();// First questionconst response = await client.sources.ask({ question: 'What products are mentioned in the catalog?',});console.log(`Answer: ${response.answer}`);// Follow-up question using conversation memoryconst followUp = await client.sources.ask({ question: 'Which one is the most expensive?', conversation_id: response.conversation_id,});console.log(`Follow-up: ${followUp.answer}`);// Another follow-upconst another = await client.sources.ask({ question: 'What are its specifications?', conversation_id: response.conversation_id,});console.log(`Answer: ${another.answer}`);
from graphor import Graphorclient = Graphor()# Start a conversationresponse = client.sources.ask( question="What is the company's revenue?")# Switch to a new topic - reset the conversationnew_response = client.sources.ask( question="What are the safety guidelines?", conversation_id=response.conversation_id, reset=True # Ignores previous conversation history)print(f"Answer: {new_response.answer}")
import Graphor from 'graphor';const client = new Graphor();// Start a conversationconst response = await client.sources.ask({ question: "What is the company's revenue?",});// Switch to a new topic - reset the conversationconst newResponse = await client.sources.ask({ question: 'What are the safety guidelines?', conversation_id: response.conversation_id, reset: true, // Ignores previous conversation history});console.log(`Answer: ${newResponse.answer}`);
Restrict the search to specific files using file_ids (preferred):
Python
TypeScript
from graphor import Graphorclient = Graphor()# Ask about specific documents using file_ids (preferred)response = client.sources.ask( question="What is the total amount due?", file_ids=["file_abc123", "file_def456"])print(f"Answer: {response.answer}")# Or using file_names (deprecated)response = client.sources.ask( question="What is the total amount due?", file_names=["invoice-2024.pdf", "invoice-2023.pdf"])print(f"Answer: {response.answer}")
import Graphor from 'graphor';const client = new Graphor();// Ask about specific documents using file_ids (preferred)const response = await client.sources.ask({ question: 'What is the total amount due?', file_ids: ['file_abc123', 'file_def456'],});console.log(`Answer: ${response.answer}`);// Or using file_names (deprecated)const response2 = await client.sources.ask({ question: 'What is the total amount due?', file_names: ['invoice-2024.pdf', 'invoice-2023.pdf'],});console.log(`Answer: ${response2.answer}`);
Control the model’s reasoning depth with thinking_level:
Python
TypeScript
from graphor import Graphorclient = Graphor()# Fast mode for simple questionsresponse = client.sources.ask( question="What is the document title?", thinking_level="fast")print(f"Answer: {response.answer}")# Accurate mode for complex analysisresponse = client.sources.ask( question="Analyze the legal implications of the termination clause and identify potential risks.", file_names=["contract.pdf"], thinking_level="accurate")print(f"Analysis: {response.answer}")
import Graphor from 'graphor';const client = new Graphor();// Fast mode for simple questionsconst response = await client.sources.ask({ question: 'What is the document title?', thinking_level: 'fast',});console.log(`Answer: ${response.answer}`);// Accurate mode for complex analysisconst analysis = await client.sources.ask({ question: 'Analyze the legal implications of the termination clause and identify potential risks.', file_names: ['contract.pdf'], thinking_level: 'accurate',});console.log(`Analysis: ${analysis.answer}`);
from graphor import Graphorclient = Graphor()# Schema for extracting a list of productsproducts_schema = { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": ["number", "null"]}, "quantity": {"type": ["integer", "null"]} } }}response = client.sources.ask( question="Extract all products with their prices and quantities from the order.", file_names=["order.pdf"], output_schema=products_schema)if response.structured_output: products = response.structured_output for product in products: print(f"- {product['name']}: ${product.get('price', 'N/A')} x {product.get('quantity', 'N/A')}")
import Graphor from 'graphor';const client = new Graphor();// Schema for extracting a list of productsconst productsSchema = { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, price: { type: ['number', 'null'] }, quantity: { type: ['integer', 'null'] }, }, },};const response = await client.sources.ask({ question: 'Extract all products with their prices and quantities from the order.', file_names: ['order.pdf'], output_schema: productsSchema,});if (response.structured_output) { const products = response.structured_output as Array<Record<string, unknown>>; for (const product of products) { console.log(`- ${product.name}: $${product.price ?? 'N/A'} x ${product.quantity ?? 'N/A'}`); }}
import asynciofrom graphor import AsyncGraphorasync def ask_questions(): client = AsyncGraphor() # Ask a question response = await client.sources.ask( question="What are the key terms in this contract?" ) print(f"Answer: {response.answer}") # Follow-up follow_up = await client.sources.ask( question="When does it expire?", conversation_id=response.conversation_id ) print(f"Follow-up: {follow_up.answer}")asyncio.run(ask_questions())
import Graphor from 'graphor';const client = new Graphor();async function askQuestions() { // Ask a question const response = await client.sources.ask({ question: 'What are the key terms in this contract?', }); console.log(`Answer: ${response.answer}`); // Follow-up const followUp = await client.sources.ask({ question: 'When does it expire?', conversation_id: response.conversation_id, }); console.log(`Follow-up: ${followUp.answer}`);}await askQuestions();
import asynciofrom graphor import AsyncGraphorasync def ask_parallel_questions(questions: list[str]): """Ask multiple questions in parallel.""" client = AsyncGraphor() tasks = [ client.sources.ask(question=q) for q in questions ] responses = await asyncio.gather(*tasks, return_exceptions=True) results = [] for question, response in zip(questions, responses): if isinstance(response, Exception): results.append({"question": question, "error": str(response)}) else: results.append({"question": question, "answer": response.answer}) return results# Usagequestions = [ "What is the total revenue?", "Who are the main competitors?", "What are the key risks?"]results = asyncio.run(ask_parallel_questions(questions))for result in results: print(f"Q: {result['question']}") if "answer" in result: print(f"A: {result['answer'][:200]}...") else: print(f"Error: {result['error']}") print()
import Graphor from 'graphor';const client = new Graphor();async function askParallelQuestions(questions: string[]) { const promises = questions.map((question) => client.sources .ask({ question }) .then((response) => ({ question, answer: response.answer })) .catch((err) => ({ question, error: err instanceof Graphor.APIError ? err.message : String(err), })), ); return Promise.all(promises);}// Usageconst questions = [ 'What is the total revenue?', 'Who are the main competitors?', 'What are the key risks?',];const results = await askParallelQuestions(questions);for (const result of results) { console.log(`Q: ${result.question}`); if ('answer' in result) { console.log(`A: ${result.answer.slice(0, 200)}...`); } else { console.log(`Error: ${result.error}`); } console.log();}
Use conversation memory — Pass conversation_id for follow-up questions to maintain context
Be specific — Clear, specific questions get better answers
Scope when needed — Use file_ids or file_names to focus on specific documents for faster, more accurate responses
Use structured output for integration — Provide output_schema to get JSON you can reliably parse in code
Reset when changing topics — Set reset=True when switching to unrelated questions
Handle errors gracefully — Implement proper error handling for production applications
Python
TypeScript
# Good: Specific question with contextresponse = client.sources.ask( question="What was the total revenue for Q4 2024 compared to Q4 2023?", file_names=["annual-report-2024.pdf"])# Good: Follow-up with conversation memoryfollow_up = client.sources.ask( question="What were the main drivers of this change?", conversation_id=response.conversation_id)
// Good: Specific question with contextconst response = await client.sources.ask({ question: 'What was the total revenue for Q4 2024 compared to Q4 2023?', file_names: ['annual-report-2024.pdf'],});// Good: Follow-up with conversation memoryconst followUp = await client.sources.ask({ question: 'What were the main drivers of this change?', conversation_id: response.conversation_id,});