Add optional Claude-generated answers with extractive fallback
Claude+1: Claude Opus 4.8
Unverified signature
913d26e
/ask now synthesizes a grounded answer from the retrieved passages using the
Anthropic API when ANTHROPIC_API_KEY is set, and falls back to the extractive
best-sentence answer otherwise (no key, no cost, no network — CI unaffected).
- app/generate.py: lazy Anthropic client; grounded system prompt over the top
passages; never raises (missing key/package, network error, or refusal all
return None). Model defaults to claude-opus-5, overridable via ANTHROPIC_MODEL.
- /ask returns a 'generated' flag and measures latency around generation; the
chat UI shows an 'AI answer' badge while still displaying the source passage.
- requirements add anthropic; .env.example and README document the key.
- test_generate.py covers the keyless fallback path.
Full suite is 23 tests, green; frontend builds.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WN4QRr6dTE2W7hQ2SDnLmY
Switch deploy to HF Static Space (frontend) + separate API
Claude+1: Claude Opus 4.8
Unverified signature
abf3c4b
Hugging Face only offers free Static Spaces (Docker requires a paid plan),
so the frontend now deploys to a Static Space and the API to any Python
host:
- README front matter -> sdk: static with app_build_command building
frontend/ and serving frontend/dist.
- Frontend resolves the API base at runtime from the HF Space variable
DOCUASK_API_URL (via window.huggingface.variables), then VITE_API_URL,
then /api — so the API URL changes without a rebuild.
- Backend CORS default now includes the Static Space origin; backend
Dockerfile honors and a Procfile is added for native-Python hosts.
- Deploy docs rewritten for the split; the single-image Docker option
(root Dockerfile + app/server.py) is kept as an alternative.
Sync workflow and tests unchanged in behavior; 21 backend tests pass and
the frontend builds.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WN4QRr6dTE2W7hQ2SDnLmY
Add data-collection & feedback layer (Session 4)
Claude+1: Claude Opus 4.8
Unverified signature
44215ae
Backend:
- SQLite telemetry store (db.py): interactions table logging every /ask
with its measured latency_ms. Single shared connection guarded by a lock
(FastAPI threadpool-safe); DB path from DOCUASK_DB.
- /ask now logs each turn and returns interaction_id + latency_ms.
- POST /feedback attaches a 'up'/'down' rating to an interaction
(422 on invalid value, 404 on unknown id).
- GET /stats returns total questions, median latency, thumbs-up rate,
up/down counts, and questions-over-time buckets.
- docker-compose mounts a volume for the DB so telemetry survives restarts.
Frontend:
- 👍/👎 feedback buttons under each answer, posting to /feedback with an
optimistic update.
- Dashboard page (hash route /#/dashboard) with three KPI tiles and a
questions-over-time bar chart (per-bar hover tooltip), plus a header nav
to switch between Chat and Dashboard.
Tests:
- conftest.py points the DB at in-memory SQLite per test for isolation.
- test_stats.py covers latency persistence, fe…
Add retrieval + chat loop (Session 3)
Claude+1: Claude Opus 4.8
Unverified signature
d9f07b6
Backend:
- POST /ask takes {document_id, question}, runs hybrid retrieval over the
document's chunks, and returns an extractive answer plus the source
passage it came from (with chunk index and score).
- retrieval.py: a per-document index combining BM25 (rank_bm25) with a
FAISS cosine search over TF-IDF vectors; scores are min-max normalised
and averaged. The index is built lazily on first /ask and cached.
- Empty question -> 400, unknown document id -> 404.
- Dockerfile installs libgomp1 (faiss-cpu OpenMP runtime dep).
Frontend:
- Chat interface: question input, message history, a typing indicator
while /ask is in flight, and each answer shows a collapsible source
passage underneath. App swaps the uploader for the chat once a document
is ready, with a 'New document' reset.
Tests:
- test_ask.py covers index ranking, sentence extraction, the /ask happy
path, empty-question, and unknown-document paths.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Sess…
Add upload & parse flow (Session 2)
Claude+1: Claude Opus 4.8
Unverified signature
52739ad
Backend:
- POST /documents accepts a PDF (pypdf) or raw text, extracts and chunks
the text, and stores it in an in-memory store keyed by document id.
- GET /documents/{id} returns document metadata.
- Visible, logged failure handling: non-PDF (415), broken/encrypted PDF
(400, friendly message), empty input (400), oversize input (413).
- pytest suite covers the happy path plus every parse-failure path.
Frontend:
- Drag-and-drop PDF uploader (also click-to-browse and a paste-text mode)
with idle/uploading/ready/error states and inline error messages.
- Client-side guards for non-PDF and oversize files before upload.
Also adds a .gitignore (Python + Node) so build artifacts stay untracked.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WN4QRr6dTE2W7hQ2SDnLmY
Full-stack document Q&A skeleton with a health-check wired end to end
browser -> API. Includes FastAPI backend with pytest suite, Vite + React +
Tailwind frontend, Docker Compose orchestration, and project spec.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WN4QRr6dTE2W7hQ2SDnLmY