Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Job Similarity Visualization Feature with New API Routes and Page #167

Closed
wants to merge 38 commits into from

Conversation

thomasdavis
Copy link
Member

@thomasdavis thomasdavis commented Dec 19, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new API endpoints for fetching job similarity and resume similarity data.
    • Added a new link in the Menu for navigating to the Job Similarity page.
    • Implemented a new component for visualizing job market similarities using graph algorithms.
  • Improvements

    • Adjusted the default limit for resume retrieval from 3000 to 2000.
    • Enhanced error handling for API requests.
  • Dependencies

    • Added several new packages for data visualization and JSON resume themes in the project.

Copy link

alwaysmeticulous bot commented Dec 19, 2024

🤖 No test run has been triggered as your Meticulous project has been deactivated (since you haven't viewed any test results in a while). Click here to reactivate.

Last updated for commit 47b6d73. This comment will update as new commits are pushed.

Copy link

changeset-bot bot commented Dec 19, 2024

⚠️ No Changeset found

Latest commit: 47b6d73

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jsonresume-org-homepage2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 1:47pm
jsonresume-org-registry ❌ Failed (Inspect) Dec 19, 2024 1:47pm

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/registry/app/api/job-similarity/route.js

Oops! Something went wrong! :(

ESLint: 8.55.0

ESLint couldn't find the config "next" to extend from. Please check that the name of the config is correct.

The config "next" was referenced from the config file in "/packages/eslint-config-custom/index.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces a comprehensive job similarity visualization feature in the registry application. It adds new API routes for fetching job and resume similarity data, creates a new /job-similarity page with advanced graph visualization capabilities, updates the application's menu to include navigation to the new page, and adds several dependencies to support complex data rendering and processing.

Changes

File Change Summary
apps/registry/app/api/job-similarity/route.js New API endpoint for fetching job similarity data from Supabase
apps/registry/app/api/resumes/route.js Modified default limit parameter from 3000 to 2000
apps/registry/app/api/similarity/route.js New API endpoint for fetching resume similarity data
apps/registry/app/components/Menu.js Added new navigation link to /job-similarity
apps/registry/app/job-similarity/page.js New React component for job similarity graph visualization
apps/registry/package.json Added visualization and data processing dependencies

Sequence Diagram

sequenceDiagram
    participant Client
    participant JobSimilarityAPI
    participant Supabase
    
    Client->>JobSimilarityAPI: Request job similarity data
    JobSimilarityAPI->>Supabase: Query job records
    Supabase-->>JobSimilarityAPI: Return job data
    JobSimilarityAPI->>JobSimilarityAPI: Process and parse job embeddings
    JobSimilarityAPI-->>Client: Return processed job similarity data
Loading

Possibly related PRs

Poem

🐰 Hop, hop, through data's dense terrain,
Similarities bloom like a graph's refrain,
Embeddings dance, connections take flight,
Job worlds converge in algorithmic might!
A rabbit's view of knowledge's delight! 📊


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai Add Job Similarity Visualization Feature with New API Routes and Page Dec 19, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (6)
apps/registry/app/api/similarity/route.js (2)

4-5: Consider placing the Supabase URL in an environment variable.
Exposing the full Supabase URL in code may be acceptable, but it could also create a dependency on the code level. Moving it to an environment variable would ensure better maintainability and a clear separation of configuration.


41-64: Potential performance concern with parsing large embeddings.
When users request a large 'limit' of resumes, the array of embeddings could become quite large. Parsing and returning every embedding for each record might cause high memory usage. Consider sending minimal data or adding pagination to further limit memory overhead.

apps/registry/app/api/job-similarity/route.js (2)

4-5: Keep Supabase URL configurable.
Same as in similarity/route.js, managing URLs in environment variables could improve maintainability and security posture.


41-66: Assess the scaling implications of returning high-volume embeddings.
As with the resume similarity endpoint, consider returning partial or paginated data to avoid loading large embeddings into memory on a single request.

apps/registry/app/job-similarity/page.js (1)

488-509: Consolidate color management for consistent theming.
You have a large static array of colors. Consider using a coloring library or consistently applying a site-wide color palette for better maintainability across the app.

apps/registry/app/components/Menu.js (1)

47-56: LGTM! Consider adding path check for nested routes.

The new "Similarity" menu item follows the established patterns for styling and active states. However, for consistency with the Jobs link which checks for nested routes (pathname.startsWith('/jobs/')), consider extending the active state check to include potential nested routes under /job-similarity/.

-                isActive('/job-similarity')
+                isActive('/job-similarity') || pathname.startsWith('/job-similarity/')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76a3f7f and 47b6d73.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • apps/registry/app/api/job-similarity/route.js (1 hunks)
  • apps/registry/app/api/resumes/route.js (1 hunks)
  • apps/registry/app/api/similarity/route.js (1 hunks)
  • apps/registry/app/components/Menu.js (1 hunks)
  • apps/registry/app/job-similarity/page.js (1 hunks)
  • apps/registry/package.json (3 hunks)
🔇 Additional comments (5)
apps/registry/app/api/similarity/route.js (1)

9-16: Prevent possible undefined behavior for supabaseUrl.
Although the code checks for SUPABASE_KEY, it doesn't verify that supabaseUrl is valid or non-empty, which may result in unexpected behavior if the constant is changed or if the environment changes.

apps/registry/app/api/job-similarity/route.js (1)

9-16: Validate supabaseUrl.
Similar to the resume similarity endpoint, ensure supabaseUrl is non-empty to avoid potential runtime errors if the URL or environment changes.

apps/registry/app/job-similarity/page.js (1)

611-619: Ensure valid navigation links for node clicks.
When opening job or resume links in a new tab, the code relies on the first UUID or username. If multiple records are associated with that node, only the first is used. Confirm whether you want to show multiple links or handle them differently.

apps/registry/app/api/resumes/route.js (1)

22-22: Confirm the new limit.
Lowering the default limit from 3000 to 2000 may reduce memory usage and load times but might also impact client-facing queries that expect more data. Ensure that this aligns with your current performance and data retrieval goals.

apps/registry/package.json (1)

34-34: Consider optimizing visualization package imports.

The addition of multiple visualization libraries (d3-force, plotly.js, react-force-graph) could significantly increase the bundle size. Consider:

  1. Using dynamic imports to load these packages only when needed
  2. Evaluating if all visualization packages are necessary or if some functionality could be consolidated
  3. Using the core plotly.js package instead of plotly.js-dist if you're only using specific plot types

Let's analyze the usage of these packages:

Also applies to: 97-97, 105-106, 108-108

Comment on lines +44 to +92
const algorithms = {
mst: {
name: 'Minimum Spanning Tree',
compute: (nodes, minSimilarity = 0.3) => {
// Kruskal's algorithm for MST
const links = [];
const parent = new Array(nodes.length).fill(0).map((_, i) => i);

function find(x) {
if (parent[x] !== x) parent[x] = find(parent[x]);
return parent[x];
}

function union(x, y) {
parent[find(x)] = find(y);
}

// Create all possible edges with weights
const edges = [];
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
const similarity = cosineSimilarity(
nodes[i].avgEmbedding,
nodes[j].avgEmbedding
);
if (similarity > minSimilarity) {
edges.push({ i, j, similarity });
}
}
}

// Sort edges by similarity (descending)
edges.sort((a, b) => b.similarity - a.similarity);

// Build MST
edges.forEach(({ i, j, similarity }) => {
if (find(i) !== find(j)) {
union(i, j);
links.push({
source: nodes[i].id,
target: nodes[j].id,
value: similarity,
});
}
});

return links;
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor repeated similarity checks across algorithms.
Many algorithms re-compute cosine similarities. You could avoid repeated calculations by preprocessing a distance matrix or similarity matrix once. This can significantly reduce repeated work for large node sets.

Comment on lines +11 to +21
// Helper function to compute cosine similarity
const cosineSimilarity = (a, b) => {
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return 0;

const dotProduct = a.reduce((sum, _, i) => sum + a[i] * b[i], 0);
const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));

return dotProduct / (magnitudeA * magnitudeB);
};

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure divisor non-zero guard in cosineSimilarity.
Though the function checks array format, consider handling the case if one (or both) of the magnitude calculations is zero, which can lead to NaN or Infinity.

 const cosineSimilarity = (a, b) => {
   if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return 0;

   const dotProduct = a.reduce((sum, _, i) => sum + a[i] * b[i], 0);
   const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
   const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));

+  if (magnitudeA === 0 || magnitudeB === 0) {
+    return 0;
+  }

   return dotProduct / (magnitudeA * magnitudeB);
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Helper function to compute cosine similarity
const cosineSimilarity = (a, b) => {
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return 0;
const dotProduct = a.reduce((sum, _, i) => sum + a[i] * b[i], 0);
const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));
return dotProduct / (magnitudeA * magnitudeB);
};
// Helper function to compute cosine similarity
const cosineSimilarity = (a, b) => {
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return 0;
const dotProduct = a.reduce((sum, _, i) => sum + a[i] * b[i], 0);
const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));
if (magnitudeA === 0 || magnitudeB === 0) {
return 0;
}
return dotProduct / (magnitudeA * magnitudeB);
};

@@ -14,10 +14,10 @@
"dependencies": {
"@ai-sdk/openai": "^0.0.14",
"@faker-js/faker": "^8.0.2",
"@jsonresume/jsonresume-theme-professional": "workspace:*",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate theme package entry.

The package @jsonresume/jsonresume-theme-professional appears to be listed twice in the dependencies. According to the AI summary, one entry was supposed to be removed.

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.

1 participant