ShadAI Framework
  1. getting-started
ShadAI Framework
  • Index
  • README
  • Pricing
    • Pricing Plan
  • advanced
    • Best Practices
    • Tool Orchestration
    • Performance Optimization
    • Custom Tools
  • examples
    • Advanced Patterns
    • Custom Agent Examples
    • Market Research Examples
    • Multi-Document Analysis
    • Basic Query Examples
  • api-reference
    • Exceptions Reference
    • Engine Tool API
    • Shadai Client API Reference
    • Query Tool API
    • Summarize Tool API
    • Agent Tool API
    • Web Search Tool API
  • use-cases
    • Knowledge Synthesis
    • Research Assistant
    • Custom Workflows
    • Document Q&A
  • core-concepts
    • Architecture
    • Intelligent Agent
    • RAG System
    • Tools Overview
  • guides
    • Memory & Context
    • Streaming Responses
    • File Ingestion
    • Error Handling
    • Session Management
  • getting-started
    • Authentication
    • Your First Query
    • Quick Start
    • Installation
  1. getting-started

Your First Query

Learn by doing! This step-by-step tutorial will take you from zero to your first successful query.

What You'll Build#

A simple document Q&A application that:
1.
Ingests PDF documents
2.
Answers questions about them
3.
Maintains conversation context
Time to complete: ~10 minutes

Prerequisites#

āœ… Shadai installed (Installation Guide)
āœ… API key configured (Authentication Guide)
āœ… Python 3.10+ with async support

Step 1: Prepare Your Documents#

Create a folder with some PDF files:
For this tutorial, you can use any PDF - research papers, reports, books, etc.

Step 2: Create Your Script#

Create first_query.py:

Step 3: Run Your First Query#

You should see output like:
šŸš€ Starting Shadai session...
šŸ“„ Ingesting documents...
āœ… Successfully ingested: 3
āŒ Failed: 0
⊘ Skipped (too large): 0

šŸ” Asking question...
Q: What are the main topics covered in these documents?

A: Based on the documents provided, the main topics include:
1. Machine learning algorithms and their applications
2. Data preprocessing techniques
3. Model evaluation metrics...

Step 4: Add Follow-Up Questions#

The magic of Shadai is context! Let's add a follow-up:
Notice how the second question doesn't need to repeat context - Shadai remembers "the first topic" from the previous answer!

Understanding the Code#

The Context Manager#

async with - Ensures proper cleanup
name="my-first-query" - Creates a persistent session
Session stores: documents, chat history, context

Ingestion#

What happens behind the scenes:
1.
šŸ” Scans folder recursively
2.
šŸ“„ Extracts text from PDFs
3.
āœ‚ļø Chunks documents intelligently
4.
🧠 Creates embeddings
5.
šŸ’¾ Stores in vector database

Querying#

What happens:
1.
🧠 Converts question to embedding
2.
šŸ” Finds relevant document chunks
3.
šŸ¤– Generates answer with context
4.
⚔ Streams tokens in real-time

Troubleshooting#

No documents ingested#

Problem: Successfully ingested: 0
Solutions:
Check folder path is correct
Ensure PDFs are under 35MB
Verify PDFs aren't corrupted

Slow ingestion#

Problem: Ingestion takes a long time
Explanation:
First ingestion is slower (processing + embedding)
Large files take longer
This is normal! Subsequent queries are fast

Generic answers#

Problem: Answers don't reference your documents
Solutions:
Check documents were actually ingested
Make questions more specific
Verify documents contain relevant information

Authentication errors#

Problem: AuthenticationError
Solution:

Next Level: Interactive Q&A#

Let's make it interactive:
Run it:
Example interaction:
šŸ“„ Loading documents...
āœ… Ready! Ask your questions (type 'quit' to exit)

You: What is this document about?
AI: This document discusses machine learning algorithms...

You: What are the key benefits?
AI: The key benefits mentioned include improved accuracy...

You: quit

What You Learned#

āœ… How to create a Shadai session
āœ… How to ingest documents
āœ… How to query your knowledge base
āœ… How streaming responses work
āœ… How context is maintained automatically

Next Steps#

Now that you've run your first query, explore more:

šŸ“– Learn More#

Session Management - Organize your data
Memory & Context - Control conversation flow
Streaming Responses - Handle real-time data

šŸ’” See Examples#

Document Q&A - Production-ready Q&A system
Research Assistant - Advanced research workflows
Multi-Document Analysis - Analyze multiple sources

šŸš€ Go Advanced#

Custom Tools - Build your own tools
Intelligent Agents - Orchestrate complex workflows
Performance Optimization - Scale to production

Need Help?#

šŸ’¬ Having issues? Check Error Handling Guide
šŸ› Found a bug? Open an issue
šŸ’” Have questions? Email support@shadai.com

šŸŽ‰ Congratulations! You've completed your first query. Ready to build something amazing?
Modified atĀ 2025-10-17 17:48:00
Previous
Authentication
Next
Quick Start
Built with