File size: 3,092 Bytes
f5ff7cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
title: Document QA with Manual RAG
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 6.31.0
python_version: "3.12"
app_file: app.py
suggested_hardware: cpu-basic
pinned: false
short_description: Manual RAG with visible source passages
models:
  - sentence-transformers/all-MiniLM-L6-v2
  - google/flan-t5-small
datasets:
  - rajpurkar/squad
---

# Document Q&A with Manual RAG

A Gradio teaching app that answers questions about 30 SQuAD/Wikipedia passages loaded directly from Hugging Face and displays the source evidence. The pipeline uses plain Python, sentence-transformers, NumPy, and Transformers.

## Using the app
Ask a question such as “Which company produces the iPod?” Read the answer and the source passages. The evidence box distinguishes passages supplied to the generator from passages retrieved but omitted from the prompt.

At startup, datasets.load_dataset streams the pinned SQuAD training split and builds the 30-passage sample in memory. No local passage JSON is used. The first generation request downloads FLAN-T5-small. A cold start may take time. Select **Retrieval only** to inspect source passages without generating an answer. This option still requires the dataset and embedding model.

## Models and limits
- Search: sentence-transformers/all-MiniLM-L6-v2.
- Generation: google/flan-t5-small.
- Input: a question of at most 300 characters.
- Prompt: at most 512 tokens, retaining complete passages.
- A single model request runs at a time, with a bounded waiting queue.

Similarity scores are not confidence probabilities. The 0.30 cutoff is an uncalibrated teaching heuristic. The generator can produce unsupported answers, fail to abstain, or alter source terms. Check every answer against its evidence. This demonstration is not for clinical or other high-stakes decisions.

## Deployment
See [Hugging_Face_Deployment_Guide.md](Hugging_Face_Deployment_Guide.md). Upload the extracted files into the root of a **Gradio** Space. The README configuration above is required. Uploading the ZIP alone does not deploy the app.

No token or external inference API is needed by this app's public models. The Hugging Face hosting account must separately meet Space creation eligibility. As checked on 29 October 2026, the documented CPU Basic route for Gradio requires a subscription, despite having no hourly hardware charge. Review the creation screen before selecting hardware or a plan. No plan or paid hardware has been purchased for this package.

## Data attribution
The historical passages originate from Wikipedia contributors through SQuAD 1.1 by Rajpurkar et al. The teaching subset retains the previous lesson's source IDs and pinned dataset revision. The excerpts are distributed under CC BY-SA 4.0. Preserve [DATA_ATTRIBUTION.md](DATA_ATTRIBUTION.md) and Data_Provenance.md when sharing the app.

## References
- https://huggingface.co/docs/hub/spaces-overview
- https://huggingface.co/docs/hub/spaces-config-reference
- https://huggingface.co/docs/hub/spaces-dependencies
- https://huggingface.co/docs/huggingface_hub/guides/manage-spaces