Spaces:
Runtime error
A newer version of the Gradio SDK is available: 6.13.0
Auto-Save Index Feature π
Your QA bot now automatically saves the FAISS index after building it!
How It Works
First Startup (No Index Files)
- β Builds index from documents (~30 seconds)
- πΎ Automatically saves
siauto_qa.index+siauto_qa.pkl - π Next restart loads in ~5 seconds!
Subsequent Startups (Index Exists)
- π¦ Loads pre-built index (~5 seconds)
- β Ready to answer questions immediately
If Load Fails
- π¨ Rebuilds from documents
- πΎ Saves new index
- β Ready for next time
π― Three Ways to Use
Option 1: Let HF Auto-Build (Easiest)
Upload 5 files to Hugging Face:
app.py
qa_bot.py
siauto_documents.py
requirements.txt
README.md
What happens:
- First deploy: Builds index, saves it automatically
- Future deploys: Loads saved index (fast!)
Note: If HF filesystem is read-only, it rebuilds each time (still works fine!)
Option 2: Pre-Build Locally (Fastest)
Build index on your computer first:
python build_index.py
Upload 7 files to Hugging Face:
app.py
qa_bot.py
siauto_documents.py
requirements.txt
README.md
siauto_qa.index β Pre-built
siauto_qa.pkl β Pre-built
What happens:
- First deploy: Loads pre-built index immediately (~5 sec)
- No need to build on HF
Option 3: Build Once on HF, Download for Local
- Deploy to HF without index files
- Let it build and save automatically
- Download the generated files from HF
- Use them locally or re-upload to other instances
π Performance Comparison
| Scenario | First Startup | Next Startup | Notes |
|---|---|---|---|
| No index files | ~30 sec (build) | ~5 sec (loads saved) | Auto-saves after build |
| Pre-built index | ~5 sec | ~5 sec | No build needed |
| Read-only filesystem | ~30 sec | ~30 sec | Can't save, rebuilds each time |
π Check the Logs
In Hugging Face β Your Space β Logs, you'll see:
First run (no index):
π No pre-built index found. Building from 10 documents...
π Indexing 10 documents...
β
FAISS index built with 45 vectors
πΎ Saving index to siauto_qa.index for faster future startups...
β
Index saved! Next startup will be ~5x faster.
π Created files: siauto_qa.index + siauto_qa.pkl
β
QA Bot ready!
Second run (index exists):
π¦ Loading pre-built FAISS index from siauto_qa.index...
β
Loaded index with 45 vectors
β
QA Bot ready!
β οΈ Important Notes
Persistent Storage
- HF Spaces Free Tier: Storage persists between restarts β
- HF Spaces Sleep: Index files survive sleep β
- Git Repo: Index files can be committed (optional)
When Index is Rebuilt
The bot rebuilds (and re-saves) the index when:
- Documents are updated
- Index files are deleted/corrupted
- Load fails for any reason
File Permissions
If you see:
β οΈ Could not save index: [Permission denied]
This means the filesystem is read-only (rare on HF Spaces). The bot still works, but rebuilds each time.
π‘ Best Practice
For most users: Just upload 5 files and let it auto-save!
For fastest deployment: Pre-build locally with build_index.py
For version control: Add to .gitignore:
*.index
*.pkl
Then upload index files separately to HF.
π Updating Documents
When you update siauto_documents.py:
Option A (Automatic):
- Delete
siauto_qa.indexandsiauto_qa.pklfrom HF - Restart the Space
- It rebuilds with new documents and saves
Option B (Manual):
- Run
build_index.pylocally with updated documents - Upload new
siauto_qa.indexandsiauto_qa.pklto HF
π Benefits
- β No manual work: Saves automatically
- β Faster restarts: Loads saved index
- β Resilient: Rebuilds if needed
- β Flexible: Works with or without pre-built files
- β Smart: Only rebuilds when necessary
TL;DR: Just deploy and forget! The bot handles index management automatically. π