Knowledge Base Context
Torrify ships with API reference context for OpenSCAD and build123d. This context is injected into AI prompts to improve accuracy and reduce hallucinations.
What It Includes
- OpenSCAD API reference
- build123d function signatures
- Backend-specific usage guidance
Bundled context files live in resources/:
resources/context_openscad.txtresources/context_build123d.txt
Why Updating Matters
The knowledge base is what the AI uses for API accuracy. When the context is out of date, the model may:
- Suggest deprecated functions or missing parameters.
- Use old build123d signatures that no longer match your installed version.
- Generate code that runs but produces unexpected geometry.
This is especially important after upgrading build123d, since its Python API and signatures evolve regularly.
When To Update (Especially build123d)
- You upgrade
build123dto a new version. - You notice the AI referencing functions that no longer exist.
- You add a custom build123d install in a different Python environment.
- You want to sync to the newest bundled context in the repo.
Settings UI
In Settings → Knowledge Base you can:
- Check context file status and size
- Update from the cloud
- Reset to factory bundled versions
User updates are stored in the app data directory and override bundled defaults.
How To Update
Option A: Update from the App (Recommended)
- Open Settings → Knowledge Base.
- Click Update from the cloud.
- Verify the status and file size update.
Option B: Regenerate Bundled Context (For Repo Updates)
Use this when you are shipping a new build or when build123d changes:
npm run generate:context
npm run generate:context:openscad
npm run generate:context:build123dMake sure the Python environment running generate:context:build123d has the same build123d version you intend to support.
Regenerating Context
These scripts rebuild context files:
npm run generate:context
npm run generate:context:openscad
npm run generate:context:build123dOptional: Condense with LLM (Lower Token Use)
To reduce context size and save money on LLM tokens, you can run the generator with an LLM condense step. The script will generate raw context as usual, then call an LLM (OpenRouter or Gemini) to produce a denser "Context Guide" (build123d) or "Syntax Context" (OpenSCAD) with the same semantic value and ~60% fewer characters.
Preferred: OpenRouter (uses the same key as in the app)
- Set
OPENROUTER_API_KEYin your environment (same as in the app):- Windows (PowerShell):
$env:OPENROUTER_API_KEY = "your-api-key" - macOS/Linux:
export OPENROUTER_API_KEY=your-api-key
- Windows (PowerShell):
- Optionally set the model (default is
google/gemini-2.0-flash):$env:OPENROUTER_MODEL = "google/gemini-2.0-flash"(PowerShell) orexport OPENROUTER_MODEL=google/gemini-2.0-flash(bash)
- Run the generator. If
OPENROUTER_API_KEYis set, the script will condense each context file after generating it:bashnpm run generate:context
Alternative: Gemini (direct Google API)
- Set
GEMINI_API_KEY(from Google AI Studio):- Windows (PowerShell):
$env:GEMINI_API_KEY = "your-api-key" - macOS/Linux:
export GEMINI_API_KEY=your-api-key
- Windows (PowerShell):
- Optionally set
GEMINI_MODEL(e.g.gemini-2.0-flashorgemini-3-flash).
Skip condense: To regenerate raw context only (skip the LLM step even if a key is set):
npm run generate:context -- --no-geminiCondensed output is written over the same context_openscad.txt and context_build123d.txt files. Use --no-gemini when you want to keep the raw scrape/introspection output.
Files Involved
scripts/generate-context.cjsscripts/generate-build123d-context.pyresources/context_openscad.txtresources/context_build123d.txtsrc/components/SettingsModal.tsxsrc/components/ChatPanel.tsx