- Loads a book dataset from JSON (auto-creates a small default if missing)
- Keyword retriever with synonym expansion, bigram (phrase) bonus, fuzzy fallback
- Optional tags in each book entry (weighted higher for recall)
- Two answer modes: • Identify mode → returns exact book title + snippet citation (e.g., Title [1]) • Explain mode → one-sentence factual answer + title + citation (e.g., Fact — Title [1])
- Answer generation with Hugging Face (FLAN-T5 small/base)
- Safer generation defaults: beam search, no-repeat n-gram, temp=0
- Auto device selection: Apple MPS (Mac), CUDA (if available), or CPU
- Choose a Hub model (e.g., google/flan-t5-small) or a local on-disk folder
- python -m venv .venv
- Linux/MacOS: source .venv/bin/activate
- Windows: .venv\Scripts\activate
- pip install --upgrade pip
- pip install torch==2.3.1 transformers==4.43.3
- python rag_library.py --help
- python rag_library.py
- python rag_library.py --data books.json
- python rag_library.py --model google/flan-t5-small
- python rag_library.py --local-model-path ./flan-t5-small-local
- python rag_library.py --topk 1
- python rag_library.py --topk 3
- python rag_library.py --topk 5
- python rag_library.py --demo
- python rag_library.py --show-context
- python rag_library.py --demo --show-context
- python rag_library.py --offline
- python rag_library.py --local-model-path ./flan-t5-small-local --offline
- python rag_library.py --model google/flan-t5-small --demo --show-context
- python rag_library.py --local-model-path ./flan-t5-small-local --data books.json --topk 5
- python rag_library.py --local-model-path ./flan-t5-small-local --data books.json --offline