API-first Rails app that classifies free-text questions into industries per project/tenant. Includes:
- Projects with rate limits and API keys.
- Shared industry catalog and per-project associations.
- Classification endpoint with logging.
- Admin JSON endpoints secured with optional HTTP basic auth (set
ADMIN_USER/ADMIN_PASSWORD).
git clone <repo>
cd sector-classifier
DISABLE_SPRING=1 BUNDLE_USER_HOME=./.bundle bundle install
DISABLE_SPRING=1 BUNDLE_USER_HOME=./.bundle rails db:create db:migrate db:seed
DISABLE_SPRING=1 BUNDLE_USER_HOME=./.bundle rails serverPostgres config is in config/database.yml (env vars: PGUSER, PGPASSWORD, PGHOST, PGPORT).
- Health:
GET /api/v1/health - Classify:
POST /api/v1/classifywith headerX-Api-Keyand body{ "text": "I need a hotel booking system" }- Returns matched industry
{ id, name, code, description, score } - Logs every call in
classification_requests.
- Returns matched industry
- Projects:
GET/POST/PATCH/DELETE /admin/projects - API keys:
GET/POST/PATCH/DELETE /admin/projects/:project_id/api_keys - Industries catalog:
GET/POST/PATCH/DELETE /admin/industries - Project industries:
GET/POST/DELETE /admin/projects/:project_id/industries
- Project:
Leadhub(status: active) - Industries: Construction, Healthcare, IT, Hospitality, Real Estate
- Default API key attached to Leadhub (token printed in DB, generated automatically)
- Fast import (CSV or JSON) to a project:
DISABLE_SPRING=1 BUNDLE_USER_HOME=./.bundle rails import:industries[PROJECT_ID,/absolute/path/to/file.csv]- The file must have
name,code,description. - Imports also link the industries to the given project; names must be unique per project (case-insensitive).
- The file must have
- Rebuild embeddings (all or per project):
DISABLE_SPRING=1 BUNDLE_USER_HOME=./.bundle rails embeddings:rebuild[PROJECT_ID]
- CSV headers:
name,code,description,external_id,search_terms,categoryexternal_idrecommended if you want to round-trip the source ID.search_termscan be JSON array or plain text; stored as array.- Example:
name,code,description,external_id,search_terms,category "Hotel Services","HOTEL","Hotel and accommodation","49213","[""hotel"",""lodging""]","Hospitality" "AI Consulting","AI","AI & data projects","AI-001","[""machine learning"",""ml""]","Technology"
- JSON array; camelCase accepted:
[ { "name": "Hotel Services", "code": "HOTEL", "description": "Hotel and accommodation", "industryId": "49213", "searchTerms": ["hotel", "lodging"], "category": "Hospitality" }, { "name": "AI Consulting", "code": "AI", "description": "AI & data projects", "industryId": "AI-001", "searchTerms": ["machine learning", "ml"], "category": "Technology" } ]
POST /api/v1/classifyandPOST /api/v1/semantic_searchreturn industry fields:id, name, code, description, external_id, category, search_terms(plusscore).