Skip to content

Feature/smart engine - #769

Open
jdelagarzaf wants to merge 96 commits into
mainfrom
feature/smart-engine
Open

Feature/smart engine#769
jdelagarzaf wants to merge 96 commits into
mainfrom
feature/smart-engine

Conversation

@jdelagarzaf

@jdelagarzaf jdelagarzaf commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Context

Nonprofits on the platform are hard to discover for users who don't know what they're looking for. This PR introduces Smart Match — an AI-powered quiz that takes a user through 8–9 questions about their needs, interests, and location, then returns the 3 nonprofit organizations that best fit their profile.

Matching is driven by vector embeddings (semantic similarity via a Python microservice running BAAI/bge-large-en-v1.5) combined with attribute scoring (cause alignment, beneficiary match, geographic distance) so results are meaningful rather than just keyword-based.

What changed

Quiz wizard
3 user type flows (service seeker, volunteer, donor) with 8–9 steps each, session-based state, back navigation with pre-selection, animated progress bar, and mobile-responsive layout
Stimulus controller handles card selection, checkbox toggling, accordion expand/collapse, and Next button validation

Matching engine
SmartMatch::EmbeddingClient — HTTP client to the Python embedding service with retry and EmbeddingUnavailableError
SmartMatch::SimilarityQuery — PostGIS nearest-neighbor search with automatic radius expansion (5 → 10 → 25 → 50 mi → state-wide fallback)
SmartMatch::Scorer — composite ranking: 70% semantic similarity + 20% attribute bonus + 10% distance
SmartMatch::SubmissionProcessor — orchestrates the full quiz → embedding → match → persist pipeline

Models & jobs
QuizSubmission, OrganizationMatch, OrganizationEmbedding, UserIntent
EmbedOrganizationJob and EmbedAllOrganizationsJob keep org embeddings current; rake smart_match:embed_all backfills existing orgs

How to test it

  • Start the embedding service: cd embedding-service && uvicorn main:app --reload
  • Start Redis and the Rails server
  • Run rake smart_match:embed_all to generate embeddings for existing organizations
  • Navigate to /smart_match and complete the quiz as each user type — verify 3 ranked results appear
  • Navigate back through steps and confirm previous answers remain selected
  • Submit the quiz, then refresh the results page — confirm no duplicate submission is created in the DB
  • Stop the embedding service and submit — confirm the "temporarily unavailable" error state renders gracefully
  • Click "Retake Quiz" and confirm the session is fully cleared and the wizard restarts at step 1

References

ClickUp ticket

aliciapaz and others added 30 commits February 12, 2026 20:33
Debug 503 responses from /up health check - log the actual exception
class and message to identify what's failing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Same fix applied in production.rb — use credentials.dig(:staging, :host)
instead of credentials.dig(:staging)[:host] which crashes when the
staging credentials section doesn't exist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- HealthController: inherit from ActionController::Base to skip
  authenticate_user! and Pundit — health checks must work without auth
- Move Rack::Attack health-check safelist to rack_attack.rb initializer
- Replace `defined?(Rake)` guard with `SECRET_KEY_BASE` build check
- Fix shared mutable redis_config hash in sidekiq.rb (use method)
- Puma: default to 0 workers in development to avoid forking issues
- Dockerfile: add comment noting x86_64-specific jemalloc path
- Fix asset_host: use string instead of hash in production.rb/staging.rb
- Remove unused sentence-transformers from embedding-service requirements
- Add trailing newline to .gitignore
- Add request spec for health check endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HealthController intentionally inherits from ActionController::Base
to bypass Devise authentication for Kamal health checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add .compound-engineering to gitignore. Only keep docs or plans when relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants