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:2.
Answers questions about them
3.
Maintains conversation context
Time to complete: ~10 minutesPrerequisites#
ā
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#
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
5.
š¾ Stores in vector database
Querying#
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: 0Check folder path is correct
Ensure PDFs are under 35MB
Verify PDFs aren't corrupted
Slow ingestion#
Problem: Ingestion takes a long timeFirst ingestion is slower (processing + embedding)
This is normal! Subsequent queries are fast
Generic answers#
Problem: Answers don't reference your documentsCheck documents were actually ingested
Make questions more specific
Verify documents contain relevant information
Authentication errors#
Problem: AuthenticationErrorNext Level: Interactive Q&A#
Let's make it interactive:š„ 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 automaticallyNext Steps#
Now that you've run your first query, explore more:š Learn More#
š” See Examples#
š Go Advanced#
Need Help?#
š Congratulations! You've completed your first query. Ready to build something amazing? Modified atĀ 2025-10-17 17:48:00