Semantic search + AI answers over the GSAS-II documentation set: 128 HTML pages by default (home, help, and all 64 tutorials), with the Developer's Guide and Powder Crystallography textbook available as optional additions (see Doc sources).
Answers include inline citations — every [N] in the response is a
clickable link to the exact documentation section that supported that sentence.
All embedding and retrieval runs on your machine — no data is sent externally unless you explicitly choose the Anthropic API backend.
- Pawan K. Tripathi — X-ray Science Division, Argonne National Laboratory (ptripathi@anl.gov)
- Mathew J. Cherukara — X-ray Science Division, Argonne National Laboratory (mcherukara@anl.gov)
- Brian H. Toby — X-ray Science Division, Argonne National Laboratory (toby@anl.gov)
pip install gsas2-queryOr install directly from source:
pip install git+https://github.com/AdvancedPhotonSource/Query-GSAS-II.gitconda install -c conda-forge gsas2-query# Activate the GSAS-II conda environment first, then:
pip install gsas2-querygit clone https://github.com/AdvancedPhotonSource/Query-GSAS-II.git
cd Query-GSAS-II
pip install -e ".[dev]"brew install ollama # macOS; see https://ollama.com for other platforms
ollama serve & # start the local server
ollama pull llama3 # ~5 GB one-time downloadOther model options: llama3:70b (better quality, ~40 GB), mistral (faster, ~4 GB).
llama-cpp-python runs a GGUF model directly inside the Python process — no
separate server required. It is cross-platform and available from conda-forge.
When llama-cpp-python is importable, gsas2-query selects it automatically
without any LLM_BACKEND setting.
conda install -c conda-forge llama-cpp-python # recommended
# or:
pip install "gsas2-query[llama_cpp]"Download any GGUF-format model from Hugging Face, for example:
# Llama 3.1 8B (Q4_K_M quantisation, ~5 GB):
wget https://huggingface.co/bartowski/Meta-Llama-3.1-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.ggufSet the model path in your .env or environment:
LLAMA_CPP_MODEL=/path/to/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf
# Optional tuning:
# LLAMA_CPP_N_CTX=4096 # context window (default: 4096)
# LLAMA_CPP_MAX_TOKENS=1500 # max tokens to generate (default: 1500)Run once, or again when the docs are updated. Fetches ~128 HTML pages (home, help, and all tutorials) and embeds everything locally. Takes roughly 10–20 minutes.
By default the index is stored in ~/.GSASII/query_gsas2/chroma_db
(see User data directory for details).
gsas2-query --setup # default sources (home, help, tutorials)
gsas2-query --setup --html-only # skip PDF ingestion (PDFs are not used by default anyway)
gsas2-query --setup --reset # drop index and rebuild from scratchThe default index is tens of MB. The Developer's Guide and Powder
Crystallography textbook are not included by the gsas2-query CLI's
--setup — they're opt-in via the standalone ingestion script
(python -m gsas_query.ingest --manual --book), which is what builds the
full ~324-source, ~65 MB index described in the project's paper and used
for the pre-built index released on GitHub (see
Re-indexing when docs update).
gsas2-query "How do I set up a sequential refinement?"
gsas2-query "What parameters control the background in Rietveld?"
gsas2-query "How do I export a CIF for publication?"Multi-turn conversation that remembers previous questions in the session.
gsas2-queryGSAS-II Documentation Assistant
════════════════════════════════════════════════════════════════════════════════
Knowledge base: 2,336 indexed chunks.
LLM backend: ollama
Type your question and press Enter. 'clear' resets history, 'quit' exits.
────────────────────────────────────────────────────────────────────────────────
You: How do I constrain lattice parameters?
Thinking…
Assistant: To constrain lattice parameters in GSAS-II, open the Constraints
tab in the Phase panel [1]…
Sources:
[94%] Help: Phase General › Constraints
https://advancedphotonsource.github.io/GSAS-II-tutorials/help/phasegeneral.html
Commands inside the REPL: clear (reset history), quit / exit (exit).
Opens a standalone floating dialog — stays open while you work in GSAS-II.
gsas2-query --guiAdd one call to the GSAS-II menu handler (e.g. in GSASIIctrl.py):
def OnDocAssistant(self, event):
try:
from gsas_query.gui import show_assistant
show_assistant(self) # self = GSAS-II main frame
except ImportError:
wx.MessageBox(
"GSAS-II Assistant not installed.\n"
"Run: pip install gsas2-query",
"Not available"
)show_assistant() is idempotent — calling it a second time raises the existing
window rather than opening a duplicate.
gsas2-query-web # serves on 0.0.0.0:8000
HOST=127.0.0.1 PORT=8765 gsas2-query-webThen open http://localhost:8000 in a browser. The web UI shows inline citations
as clickable superscript links and source chips below each answer.
| Flag | Description |
|---|---|
--setup |
Index all documentation sources |
--setup --reset |
Drop the existing index and rebuild |
--setup --html-only |
Index HTML only, skip PDFs |
--gui |
Open the wxPython desktop assistant |
--backend ollama|anthropic|retrieval|llama_cpp |
Override LLM_BACKEND env var |
--model <name> |
Override OLLAMA_MODEL, ANTHROPIC_MODEL, or LLAMA_CPP_MODEL |
--stats |
Show chunk count, backend, and DB path |
Backend selection precedence:
LLM_BACKENDenv var (or--backendCLI flag) always takes effect when set.- If
LLM_BACKENDis not set andllama-cpp-pythonis importable,llama_cppis selected automatically. - Otherwise the default is
ollama.
| Backend | Config | Notes |
|---|---|---|
llama_cpp (auto) |
LLAMA_CPP_MODEL=/path/to/model.gguf |
In-process, no daemon needed; auto-selected when llama-cpp-python is installed |
ollama (default) |
OLLAMA_MODEL=llama3 |
Free, fully local — no data leaves the network |
anthropic |
ANTHROPIC_API_KEY=sk-ant-… |
Better answers; queries sent to Anthropic |
retrieval |
— | No LLM — returns raw matched chunks; useful offline or for testing |
gsas2-query --backend retrieval "What is Le Bail extraction?"
gsas2-query --backend ollama --model mistral "How do I index peaks?"
gsas2-query --backend llama_cpp --model /path/to/model.gguf "How do I refine a structure?"When using Ollama, llama_cpp, or Anthropic backends, answers contain [N] markers inline.
In the web UI these render as clickable superscript links opening the exact
source section. In the CLI, source URLs are listed below the answer with
relevance scores.
| Category | Count | Included by default? |
|---|---|---|
| Home / installation pages | 22 | Yes |
| Help pages (all sections) | 42 | Yes |
| Tutorials (resolved dynamically) | 64 | Yes |
| Default total | 128 sources | |
| Developer's Guide (ReadTheDocs HTML) | 23 | Only with --manual |
| Powder Crystallography textbook (HTML) | 173 | Only with --book |
Full total (with --manual --book) |
324 sources |
All HTML sources are fetched from
https://advancedphotonsource.github.io/GSAS-II-tutorials/.
Tutorial URLs are resolved dynamically from the GSAS-II repository at
ingest time, so this count grows automatically as new tutorials are added.
The Developer's Guide is fetched from
gsas-ii.readthedocs.io, and the textbook
from the latest GitHub Pages build of
briantoby/PowderCrystallography.
Both --manual and --book are flags on the standalone
gsas_query.ingest module (see
First-time setup); they are
not currently exposed as gsas2-query --setup flags.
gsas2-query --setup --resetOr trigger via the web API (requires ADMIN_KEY set in .env):
curl -X POST http://localhost:8000/ingest -H "X-Admin-Key: your-key"- All embeddings and vector search run locally (sentence-transformers, ChromaDB).
- Ollama runs entirely on-premises — no queries leave the network.
- The
anthropicbackend sends question text and retrieved doc chunks to Anthropic. Do not use it in air-gapped or data-sensitive environments. - The web server applies per-IP rate limiting (default 30 req/min, configurable
via
RATE_LIMIT_RPMin.env). - The
/ingestendpoint is protected byX-Admin-Key; leaveADMIN_KEYblank to disable remote re-indexing.
The ChromaDB index is stored at ~/.GSASII/query_gsas2/chroma_db by default.
Override with the GSAS_QUERY_DATA_DIR environment variable:
GSAS_QUERY_DATA_DIR=/data/gsas_query gsas2-query --setup