Skip to content

feat(backend): labor pricing from historical jobs (TF-IDF RAG)#190

Open
anumukul wants to merge 2 commits intoNOVUS-X:mainfrom
anumukul:feature/labor-pricing-rag-engine
Open

feat(backend): labor pricing from historical jobs (TF-IDF RAG)#190
anumukul wants to merge 2 commits intoNOVUS-X:mainfrom
anumukul:feature/labor-pricing-rag-engine

Conversation

@anumukul
Copy link
Copy Markdown

Summary

Adds a labor pricing suggestion flow that uses completed bookings as historical context: TF‑IDF + cosine similarity over job descriptions (RAG-style retrieval), averages the top matches’ labor reference amounts, then applies urgency and optional artisan rating multipliers.

API

  • POST /api/v1/pricing/labor/suggest (client or artisan): sow_text, zip_code, optional urgency (low / normal / high), optional artisan_average_rating (1–5). Returns baseline average, suggested price, region_scope (local vs expanded if no ZIP matches), and anonymized match metadata.
  • POST /api/v1/pricing/labor/reindex (admin): rebuilds the in-memory index from completed jobs (service text, parsed ZIP, costs only—no client PII in vectors).

Data model

  • Nullable labor_cost and material_cost on bookings; pricing prefers labor_cost when set, otherwise estimated_cost.

Dependencies

  • scikit-learn, numpy

Other fixes (on main baseline)

  • Register missing stats router import in api.py.
  • PublicRoleEnum uses StrEnum (fixes missing Enum import).
  • Artisan counts: json.loads instead of undefined _json.

Tests

  • app/tests/test_labor_pricing.py covering engine behavior and auth/admin endpoints.

closes #157

- Add POST /pricing/labor/suggest for clients/artisans: TF-IDF similarity
  over completed jobs, top-5 average labor reference, urgency and rating
  multipliers.
- Add POST /pricing/labor/reindex (admin) to hydrate in-memory job rows
  from completed bookings (anonymized: service text, zip, costs only).
- Prefer labor_cost when set, else estimated_cost; add nullable labor_cost
  and material_cost on Booking.
- Dependencies: scikit-learn, numpy.
- Tests for engine and API; fix stats import, PublicRoleEnum, artisan json.

Made-with: Cursor
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@anumukul Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

ISSUE-16 · 🔵 (Agentic) — RAG Labor Pricing Oracle

1 participant