Skip to content

Conversation

@sid597
Copy link
Collaborator

@sid597 sid597 commented May 17, 2025

Summary by CodeRabbit

  • New Features

    • Introduced enhanced suggestion functionality for discourse relationships, providing more relevant node suggestions using similarity-based search.
    • Added visual feedback with a loading spinner during suggestion searches and clearer messaging when no relevant relations are found.
  • Bug Fixes

    • Improved error handling to ensure the suggestion list resets gracefully if a search fails.

@linear
Copy link

linear bot commented May 17, 2025

@vercel
Copy link

vercel bot commented May 17, 2025

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
discourse-graph ⬜️ Skipped (Inspect) May 21, 2025 5:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 17, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update overhauls the suggestion mechanism in the DiscourseContextOverlay component by introducing a HyDE-based similarity search. It adds new state variables, types, and helper functions to extract relation details and filter candidate nodes, replacing the previous direct filtering logic with a multi-step, embedding-driven approach for suggesting discourse relationships. Additionally, the hyde.ts utility was simplified by removing the embedding property from candidate nodes and returning full node objects in ranking.

Changes

File(s) Change Summary
apps/roam/src/components/DiscourseContextOverlay.tsx Replaced previous suggestion logic with a HyDE-based similarity search; added new state variables (isSearchingHyde, hydeFilteredNodes); introduced memoized uniqueRelationTypeTriplets; added async HyDE search function placeholder; updated UI to show spinner and filtered results; improved error handling; modified block creation handler to update filtered nodes.
apps/roam/src/utils/hyde.ts Removed embedding property from CandidateNodeWithEmbedding type; simplified rankNodes function by directly using full node objects as SuggestedNode without omitting properties.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DiscourseContextOverlay
    participant HyDEEngine

    User->>DiscourseContextOverlay: Selects a page/discourse node
    DiscourseContextOverlay->>DiscourseContextOverlay: Extract unique relation label-type triplets
    DiscourseContextOverlay->>DiscourseContextOverlay: Filter candidate nodes
    alt Valid candidates and relations exist
        DiscourseContextOverlay->>HyDEEngine: runHydeSearch(candidates, relations)
        HyDEEngine-->>DiscourseContextOverlay: Return similarity-ranked suggestions
        DiscourseContextOverlay->>User: Show spinner, then display suggestions
    else No valid candidates
        DiscourseContextOverlay->>User: Show "No relevant relations found"
    end
    User->>DiscourseContextOverlay: Creates block from suggestion
    DiscourseContextOverlay->>DiscourseContextOverlay: Remove used node from suggestions
Loading

Possibly related PRs

  • DiscourseGraphs/discourse-graph#147: Introduces and exposes the findSimilarNodesUsingHyde function, which is directly integrated and utilized in this PR for HyDE-based similarity searches in the overlay component.

Suggested reviewers

  • mdroidian

Poem

In the overlay’s gentle light,
HyDE now helps us find what’s right.
With embeddings deep and context wide,
Suggestions surface, side by side.
Relations mapped, connections spun—
The discourse graph’s new search begun!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@sid597
Copy link
Collaborator Author

sid597 commented May 17, 2025

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 17, 2025

✅ Actions performed

Full review triggered.

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: 0

🧹 Nitpick comments (2)
apps/roam/src/components/DiscourseContextOverlay.tsx (2)

107-158: Functions well but could benefit from optional chaining

The getUniqueLabelTypeTriplets function is well-structured and correctly extracts relationship details between nodes. However, the conditional checks on lines 125 and 135 can be simplified using optional chaining.

-      if (destinationNode && destinationNode.text && destinationNode.format) {
+      if (destinationNode?.text && destinationNode?.format) {
         targetNodeDetails = {
           text: destinationNode.text,
           format: destinationNode.format,
         };
       }
-      if (sourceNode && sourceNode.text && sourceNode.format) {
+      if (sourceNode?.text && sourceNode?.format) {
         targetNodeDetails = {
           text: sourceNode.text,
           format: sourceNode.format,
         };
       }
🧰 Tools
🪛 Biome (1.9.4)

[error] 125-125: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 135-135: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


351-359: Consider extracting node transformation logic

This transformation logic is well-implemented but could be extracted into a separate helper function for better reusability, especially if similar transformations are needed elsewhere.

+ const transformToNodeWithEmbedding = (node: SuggestedNode): CandidateNodeWithEmbedding => ({
+   uid: node.uid,
+   text: node.text,
+   type: node.type,
+   embedding: [] as number[],
+ });
+
  const runHydeSearch = async ({
    currentSuggestions,
    currentNodeText,
    relationDetails,
  }: RunHydeSearchArgs): Promise<SuggestedNode[]> => {
    // ... existing validation ...

    try {
-      const candidateNodesForHyde = currentSuggestions.map((node) => {
-        const nodeWithEmbedding = {
-          uid: node.uid,
-          text: node.text,
-          type: node.type,
-          embedding: [] as number[],
-        };
-        return nodeWithEmbedding as CandidateNodeWithEmbedding;
-      });
+      const candidateNodesForHyde = currentSuggestions.map(transformToNodeWithEmbedding);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a80026 and 65e076f.

📒 Files selected for processing (1)
  • apps/roam/src/components/DiscourseContextOverlay.tsx (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/roam/src/components/DiscourseContextOverlay.tsx (2)
apps/roam/src/utils/getDiscourseRelations.ts (1)
  • DiscourseRelation (12-19)
apps/roam/src/utils/hyde.ts (4)
  • RelationDetails (27-31)
  • SuggestedNode (23-25)
  • CandidateNodeWithEmbedding (18-21)
  • findSimilarNodesUsingHyde (321-375)
🪛 Biome (1.9.4)
apps/roam/src/components/DiscourseContextOverlay.tsx

[error] 125-125: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 135-135: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
apps/roam/src/components/DiscourseContextOverlay.tsx (6)

298-321: Good implementation of async search with proper state management

The implementation of the HyDE search within the useEffect hook is well-structured with appropriate state management. The code correctly handles loading states, error handling, and updates the UI accordingly.


331-375: Well-structured HyDE search function with proper error handling

The runHydeSearch function is well-implemented with clear input validation, proper error handling, and returns the expected result. It correctly transforms the candidate nodes to include empty embeddings for the HyDE search.


337-349: Good input validation with early returns

The input validation at the beginning of the function is excellent. Early returns for invalid inputs prevent unnecessary processing and potential errors.


424-443: Good UI feedback with loading state and empty state handling

The UI implementation provides excellent feedback to users with a loading spinner during search and appropriate messaging when no results are found. This enhances the user experience by keeping them informed about the current state.


323-329: Excellent update to filtered list after node selection

The handleCreateBlock function correctly removes the selected node from the filtered list after adding it to the block, preventing duplicate suggestions and providing a better user experience.


216-264: Well-optimized context data computation with useMemo

The suggestionContextData implementation efficiently uses useMemo to avoid unnecessary recomputation of relationship triplets and valid types. The logic for determining valid types and unique relation triplets is well-structured.

@sid597 sid597 requested a review from mdroidian May 19, 2025 12:14
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Multiple clarifying questions/context needed which will likely trigger changes and another review.

@mdroidian
Copy link
Contributor

mdroidian commented May 19, 2025

Reminder: use the linear copy git branch name when creating the branch. (as specified in DevOps)

image

@mdroidian
Copy link
Contributor

Reminder: add a loom video to the PR to help explain the context. Especially for anything user-facing.

@sid597
Copy link
Collaborator Author

sid597 commented May 20, 2025

Reminder: add a loom video to the PR to help explain the context. Especially for anything user-facing.

I want to defer this to a later pr maybe the api routes one, the functionality would not work on this one, would require some merging to another branch resolving conflits then demoing it, other way is using dummy functions but then would have to remove them. Both cases require work that would only be for demo and would also be done again in a later branch anyway.

@sid597 sid597 requested a review from mdroidian May 20, 2025 08:15
@mdroidian
Copy link
Contributor

mdroidian commented May 20, 2025

Reminder: add a loom video to the PR to help explain the context. Especially for anything user-facing.

I want to defer this to a later pr maybe the api routes one, the functionality would not work on this one, would require some merging to another branch resolving conflits then demoing it, other way is using dummy functions but then would have to remove them. Both cases require work that would only be for demo and would also be done again in a later branch anyway.

@sid597 This is all context that should be added to the PR so that the reviewer (or anyone viewing it for that matter) would understand the intentions and choices made.

@mdroidian
Copy link
Contributor

@CodeRabbit full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 20, 2025

✅ Actions performed

Full review triggered.

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: 1

🧹 Nitpick comments (1)
apps/roam/src/components/DiscourseContextOverlay.tsx (1)

155-233: Well-structured logic for extracting relation details.

The suggestionContextData useMemo properly extracts and organizes relation details needed for the HyDE search. The code:

  1. Finds relations connecting to the current node
  2. Maps them to appropriate RelationDetails objects
  3. Filters valid relation types

The nested useMemo for uniqueTriplets could be moved outside to avoid recreating functions on each render.

Consider extracting the nested useMemo to its own variable:

- const uniqueTriplets = useMemo(() => {
-   const relatedNodeType = selfNode.type;
-   // ... rest of implementation
- }, [relationsConnectingToSelf, selfNode.type, allNodes]);

+ const relatedNodeType = selfNode.type;
+ const uniqueTriplets = useMemo(() => {
+   // ... rest of implementation
+ }, [relationsConnectingToSelf, relatedNodeType, allNodes]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a80026 and f362843.

📒 Files selected for processing (2)
  • apps/roam/src/components/DiscourseContextOverlay.tsx (6 hunks)
  • apps/roam/src/utils/hyde.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/roam/src/components/DiscourseContextOverlay.tsx (1)
apps/roam/src/utils/hyde.ts (3)
  • SuggestedNode (22-24)
  • RelationDetails (26-30)
  • findSimilarNodesUsingHyde (319-373)
🔇 Additional comments (8)
apps/roam/src/utils/hyde.ts (1)

310-310: Good simplification of the code.

The change to directly assign fullNode to suggestedNodeObject without destructuring eliminates unnecessary code. This simplification is appropriate since embedding property has been removed from the CandidateNodeWithEmbedding type, as confirmed in past reviews.

apps/roam/src/components/DiscourseContextOverlay.tsx (7)

8-8: Nice addition of loading state and feedback.

Adding the Spinner component import and introducing state variables for HyDE search status provides better user feedback during async operations.

Also applies to: 114-117


33-38: Good organization of imports from the hyde utility.

Proper imports of the required types and functions from the hyde utility file support the integration with clear type definitions.


250-267: Effective type-narrowing with filter operators.

Good use of TypeScript type predicates in the filter to ensure type safety, especially with the filter((node): node is SuggestedNode => node !== null) pattern to narrow down the types.


269-292: Good async handling with proper loading states.

The implementation properly manages loading states and error handling during the HyDE search:

  1. Sets loading state before search
  2. Clears results before fetching new ones
  3. Handles errors and resets state
  4. Uses finally block to ensure loading state is reset

This provides a robust user experience even when errors occur.


302-342: Well-structured HyDE search function with good error handling.

The runHydeSearch function is well-organized with:

  1. Clear parameter typing
  2. Input validation
  3. Try-catch blocks for error handling
  4. Appropriate logging of errors

This ensures that async operations are handled robustly.


391-410: Good UI feedback during loading and empty states.

The UI properly shows:

  1. A spinner during the HyDE search
  2. The filtered nodes when available
  3. A "No relevant relations found" message when appropriate

This provides clear feedback to users about the state of the search operation.


294-300: Simple and effective node removal on add.

The handleCreateBlock function effectively updates the UI state by removing added nodes from the suggestion list, providing immediate feedback to the user.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

https://www.loom.com/share/af0f0551346a4b07b0d122eef86d3121

I get this error on trying to load just the overlay icon.
This means that the rest of the UI cannot be reviewed because it doesn't load.
We also can't confirm that the code is functional in any meaningful sense.

If this is intentional, please comment in the code (or in the GitHub PR UI) where/why this is happening, and how this works into the overall flow.

If a simple stub function can fix this, please add it. Eg:

PR Body / Loom Video:

This PR adds the UI and front end scaffolding for the upcoming backend HyDe search API's.  There is a stub function that just returns the suggested nodes without sorting them.
  // TODO: Remove this once the HyDE search is working
  const tempFindSimilarNodesUsingHyde = async ({
    candidateNodes,
    currentNodeText,
    relationDetails,
  }: {
    candidateNodes: SuggestedNode[];
    currentNodeText: string;
    relationDetails: RelationDetails[];
  }): Promise<SuggestedNode[]> => {
    return candidateNodes;
  };

  // TODO: Remove this once the HyDE search is working
  const foundNodes: SuggestedNode[] = await tempFindSimilarNodesUsingHyde({
    candidateNodes: candidateNodesForHyde,
    currentNodeText: currentNodeText,
    relationDetails: relationDetails,
  });
  // TODO: Uncomment this once the HyDE search is working
  // const foundNodes: SuggestedNode[] = await findSimilarNodesUsingHyde({
  //   candidateNodes: candidateNodesForHyde,
  //   currentNodeText: currentNodeText,
  //   relationDetails: relationDetails,
  // });

@sid597
Copy link
Collaborator Author

sid597 commented May 21, 2025

https://www.loom.com/share/aa5b0523f6ed4d8c829219e70a22ec33?sid=6f258300-ecdd-4492-a959-438d846e8c3a

@mdroidian addressed all the review points, previously I was using cursor for all the work, I reviewed the code, parts of it seemed correct, things which did not I asked it to correct, it corrected the part i wanted it to fix but left the unused code from previous run. In my mind it was reviewed and only some new function was added which lead to these situation.

For this run I actually reviewed using my brains instead of outsourcing to llm, I think its correct this time and covers the practices we want to follow.

@sid597
Copy link
Collaborator Author

sid597 commented May 21, 2025

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 2025

✅ Actions performed

Full review triggered.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a80026 and 0e73c4f.

📒 Files selected for processing (2)
  • apps/roam/src/components/DiscourseContextOverlay.tsx (7 hunks)
  • apps/roam/src/utils/hyde.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/roam/src/components/DiscourseContextOverlay.tsx (1)
apps/roam/src/utils/hyde.ts (2)
  • SuggestedNode (22-24)
  • RelationDetails (26-30)
🔇 Additional comments (14)
apps/roam/src/utils/hyde.ts (1)

310-310: Direct use of fullNode improves code clarity.

The change to directly use fullNode as the node property simplifies the code by avoiding unnecessary object restructuring. This aligns with previous feedback about redundant variable usage.

apps/roam/src/components/DiscourseContextOverlay.tsx (13)

7-8: Added Spinner component for loading state indication.

Good addition of the Spinner component from Blueprint for providing visual feedback during asynchronous operations.


31-35: Imported necessary types and functions from hyde utility.

The imports have been updated to include the required functions and types for the HyDE-based search implementation.


111-114: Added state for HyDE search process.

These new state variables appropriately track the loading state and results of the HyDE similarity search.


152-160: Simplified validRelations calculation.

The logic to determine valid relations has been streamlined to filter relations where either the source or destination matches the self type.


162-198: Created relation details extraction for HyDE search.

This memoized function extracts the necessary relation details (label, related node text, format) needed for the HyDE similarity search. The logic correctly handles both source and destination relationships.


200-217: Updated validTypes dependency on validRelations.

The validTypes calculation now correctly depends on the validRelations computed earlier, maintaining proper dependency chains.


228-228: Reset HyDE filtered nodes when page selection changes.

Good practice to clear previous results when the selection changes.


236-249: Enhanced node filtering logic.

The node filtering process now:

  1. Checks for valid node types
  2. Uses proper type assertion with the SuggestedNode type
  3. Excludes nodes that already exist in the results

251-290: Implemented asynchronous HyDE search workflow.

This implementation correctly:

  1. Sets loading state during search
  2. Prepares candidate nodes for the HyDE search
  3. Uses a temporary function with appropriate TODOs for future implementation
  4. Updates state with search results
  5. Includes proper error handling
  6. Cleans up loading state in finally block

The implementation is well-structured and handles edge cases appropriately.


293-303: Created temporary HyDE search function.

The placeholder function maintains the expected interface while allowing development to continue before the final implementation is ready.


305-311: Updated handleCreateBlock to use SuggestedNode and maintain filtered list.

The function now accepts a SuggestedNode parameter and updates the filtered list to remove nodes after they're added, preventing duplicate additions.


360-362: Added loading spinner during search.

Good UI improvement to show a loading indicator during the asynchronous search operation.


364-379: Updated UI to display HyDE search results.

The UI now conditionally renders:

  1. The filtered nodes with add buttons when available
  2. A helpful message when no relevant relations are found
  3. Nothing during the loading state

This provides a good user experience with appropriate feedback.

@sid597 sid597 requested a review from mdroidian May 21, 2025 17:51
@mdroidian mdroidian merged commit 9e7cad6 into eng-233-suggestive-mode-internal May 27, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General May 27, 2025
@mdroidian mdroidian deleted the dg-suggestion-component branch May 27, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants