feat: Initialize relevance inferencing for bills #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a relevance scoring system for bills. It uses an LLM to analyze each bill's text and estimate how relevant it is to builders and entrepreneurs (scored 1-10), along with an estimated GDP impact percentage. The analysis includes justifications for both scores, the primary mechanism of economic impact, and implementation timeline.
Results are stored in MongoDB and surfaced on the frontend in two places: as color-coded badges on bill cards in the list view (Low/Relevant/Very Relevant), and as a full "Relevance to Builders" section on individual bill detail pages showing the score breakdown, justifications, and economic impact details. Users can also filter bills by minimum relevance score and sort by relevance instead of date.
How bills get relevance analysis:
Automatically when someone views a bill detail page: If a bill exists in the database but doesn't have a relevance score yet, the system fetches the bill markdown, sends it to the LLM for analysis, and persists the results to MongoDB. This happens during page load.
Running the bulk analysis script
To test on a small set of bills first:
bash pnpm tsx src/scripts/bulk-analyze-bills.ts --url https://www.buildcanada.com/bills --bills C-14 C-18 S-5
To preview what would happen without actually running:
bash pnpm tsx src/scripts/bulk-analyze-bills.ts --url https://www.buildcanada.com/bills --dry-run
To run on all bills missing relevance scores:
bash pnpm tsx src/scripts/bulk-analyze-bills.ts --url https://www.buildcanada.com/bills