Spaces:
Running
Running
eliezer avihail
Answer-quality eval (LLM-judge) + hy3-led OpenRouter default (#81)
0942768 unverified A newer version of the Gradio SDK is available: 6.22.0
metadata
kind: runbook
title: Deploy the TorchDocs Agent to Hugging Face Spaces
date: 2026-07-06T00:00:00.000Z
Deploy to Hugging Face Spaces (free, always-on)
The app is a long-lived Gradio server: the embedding model loads once, so each
question answers in seconds. Content is read live from docs.pytorch.org when no
snapshot is bundled (TORCHDOCS_LIVE_HYDRATE=1, the default), so the Space
needs no _corpus/ and no crawl β only the Neon index (pointers) and an LLM key.
One-time setup
- Create a Space: huggingface.co β New Space β Gradio SDK, CPU basic (free).
- Point it at this repo, or push these files to the Space repo:
app.py,requirements.txt, and theagent/,index/,ingest/packages. (Simplest: add the Space as a git remote and push.) - Space β Settings β Variables and secrets, add:
NEON_URLβ the Neon connection string (the index)OPENAI_COMPAT_BASE_URL=https://openrouter.ai/api/v1OPENAI_COMPAT_API_KEYβ your OpenRouter keyTORCHDOCS_PROVIDER=openai-compatTORCHDOCS_OPENAI_COMPAT_MODEL= a comma-separated free-model chain, hy3 first (e.g.tencent/hy3:free,meta-llama/llama-3.3-70b-instruct:free) β with OpenRouter credit hy3's free-tier daily cap is wide enough to carry the Space on its own, so a second provider (gemini) is not needed.
That's it β the Space boots, downloads bge-small once (~130 MB, then cached), and serves a public URL.
Notes
- First boot is slow (model download); subsequent questions are fast.
- Live hydrate: with no bundled snapshot the app fetches each cited page
live (cached per-URL). To serve from a bundled snapshot instead, commit
_corpus/and setTORCHDOCS_LIVE_HYDRATE=0. - Speed/quality: free OpenRouter models are rate-limited and variable; the fallback chain smooths this. Loading ~$5 of OpenRouter/DeepInfra credit removes the throttling and is the single biggest UX upgrade.
- Cost: Neon free tier + HF CPU-basic free + free models = $0.