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

chore: add hybrid search control #39258

Merged
merged 2 commits into from
Feb 14, 2025
Merged

chore: add hybrid search control #39258

merged 2 commits into from
Feb 14, 2025

Conversation

KelvinOm
Copy link
Collaborator

@KelvinOm KelvinOm commented Feb 13, 2025

Description

Add hybrid search control for UQI forms.

Снимок экрана 2025-02-14 в 10 06 28

Example of usage:

{
  "isRequired": false,
  "configProperty": "actionConfiguration.formData.hybridSearch",
  "controlType": "HYBRID_SEARCH",
  "initialValue": {
      "isEnabled": true,
      "keywordWeight": 0.5,
      "semanticWeight": 0.5
  }
}

Fixes #39236

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13324291818
Commit: 9495722
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Fri, 14 Feb 2025 07:52:38 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced a new hybrid search control in the form. Users can now easily adjust search parameters with intuitive sliders for keyword and semantic weights, along with a toggle to activate or deactivate hybrid search.
    • Added a new control type for hybrid search to the form control registry, enhancing the flexibility of form configurations.

@KelvinOm KelvinOm requested a review from jsartisan February 13, 2025 18:12
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

This PR introduces a new hybrid search control by adding the HybridSearchControl component that renders UI elements such as two sliders for adjusting "Keyword Weight" and "Semantic Weight" and a switch to enable or disable the feature. Additionally, it registers the new control in the FormControlRegistry with a corresponding entry HYBRID_SEARCH in the form control types definition.

Changes

File(s) Change Summary
app/client/src/components/formControls/HybridSearch.tsx Introduces HybridSearchControl component extending BaseControl; defines HybridSearchControlProps; renders sliders and a switch to manage hybrid search functionality.
app/client/src/utils/formControl/FormControlRegistry.tsx, app/client/src/utils/formControl/formControlTypes.ts Registers HYBRID_SEARCH control type in FormControlRegistry, and adds the HYBRID_SEARCH entry in the form control types list.

Possibly related PRs

  • chore: add slider control #39058: Introduced a similar component (SliderControl) extending BaseControl and managing state with redux-form, indicating a structural similarity.

Suggested labels

Task, Query & JS Pod, Integrations Product, Integrations Pod General

Suggested reviewers

  • nsarupr
  • jsartisan

Poem

In the realm of code so fine,
A hybrid search starts to shine.
Sliders glide and toggles play,
Bringing fresh logic into the fray.
Cheers to new controls lighting the way!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1e27ad and 9495722.

📒 Files selected for processing (3)
  • app/client/src/components/formControls/HybridSearch.tsx (1 hunks)
  • app/client/src/utils/formControl/FormControlRegistry.tsx (2 hunks)
  • app/client/src/utils/formControl/formControlTypes.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/client/src/utils/formControl/formControlTypes.ts
  • app/client/src/utils/formControl/FormControlRegistry.tsx
  • app/client/src/components/formControls/HybridSearch.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@KelvinOm KelvinOm requested a review from nsarupr February 13, 2025 18:12
@github-actions github-actions bot added Anvil Pod Issue related to Anvil project skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Feb 13, 2025
@KelvinOm KelvinOm force-pushed the chore/hybrid-search branch from 2964f57 to f1e27ad Compare February 13, 2025 18:14
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 2

🧹 Nitpick comments (2)
app/client/src/components/formControls/HybridSearch.tsx (2)

36-42: Consider using more precise weight calculations.

The current implementation scales values by 10 to avoid floating-point issues, but this approach might still lead to precision errors. Consider using a more robust solution.

-      semanticWeight: (10 - value * 10) / 10, // Scale by 10 to avoid floating-point issues
+      semanticWeight: Math.round((1 - value) * 100) / 100, // Round to 2 decimal places

Also applies to: 43-49


7-9: Document the inverse relationship between weights.

The weights are inversely related (when one increases, the other decreases) but this isn't documented in the interface.

 export interface HybridSearchControlProps
   extends ControlProps,
-    Omit<SliderProps, "id" | "label"> {}
+    Omit<SliderProps, "id" | "label"> {
+  /** The weights are inversely related - they always sum to 1 */
+}
🛑 Comments failed to post (2)
app/client/src/components/formControls/HybridSearch.tsx (1)

57-88: 🛠️ Refactor suggestion

Add input validation and error handling.

The component lacks validation for edge cases:

  1. No validation that weights sum to 1
  2. No error handling for invalid input values
  3. Missing disabled state handling for the sliders when switch is off

Consider adding a validation function:

const validateWeights = (keywordWeight: number, semanticWeight: number): boolean => {
  return Math.abs(keywordWeight + semanticWeight - 1) < 0.001;
};
app/client/src/utils/formControl/FormControlRegistry.tsx (1)

230-230: 🛠️ Refactor suggestion

Use specific props type for hybrid search control.

The control is using SliderControlProps but should use its own HybridSearchControlProps interface for better type safety.

-      buildPropertyControl(controlProps: SliderControlProps): JSX.Element {
+      buildPropertyControl(controlProps: HybridSearchControlProps): JSX.Element {
📝 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.

      buildPropertyControl(controlProps: HybridSearchControlProps): JSX.Element {

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 (4)
app/client/src/components/formControls/HybridSearch.tsx (3)

11-27: Add JSDoc documentation for the component class.

Consider adding JSDoc documentation to describe the component's purpose, props, and usage.

+/**
+ * HybridSearchControl provides a UI for configuring hybrid search parameters
+ * including keyword and semantic weights.
+ */
 export class HybridSearchControl extends BaseControl<HybridSearchControlProps> {

36-49: Extract magic numbers into named constants.

The scaling factor of 10 is used to avoid floating-point issues, but it should be extracted into a named constant for better maintainability.

+const WEIGHT_SCALE_FACTOR = 10;
+
 const onKeywordWeightChange = (value: number) => {
   input?.onChange({
     ...input?.value,
     keywordWeight: value,
-    semanticWeight: (10 - value * 10) / 10,
+    semanticWeight: (WEIGHT_SCALE_FACTOR - value * WEIGHT_SCALE_FACTOR) / WEIGHT_SCALE_FACTOR,
   });
 };

57-89: Enhance accessibility for the form controls.

Add ARIA labels and roles to improve accessibility for screen readers.

 <Flex flexDirection="column" gap="spaces-4">
   <Flex width="150px">
     <Switch
+      aria-label="Toggle hybrid search"
       defaultSelected={input?.value.isEnabled}
       onChange={onSwitchChange}
     >
       Hybrid search
     </Switch>
   </Flex>
   <Flex alignItems="center" gap="spaces-4">
     <Slider
+      aria-label="Adjust keyword weight"
       isDisabled={!input?.value.isEnabled}
       label="Keyword weight"
app/client/src/utils/formControl/FormControlRegistry.tsx (1)

229-233: Consider using more specific props type.

The control is using SliderControlProps but should use HybridSearchControlProps for better type safety.

-      buildPropertyControl(controlProps: SliderControlProps): JSX.Element {
+      buildPropertyControl(controlProps: HybridSearchControlProps): JSX.Element {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2964f57 and f1e27ad.

📒 Files selected for processing (3)
  • app/client/src/components/formControls/HybridSearch.tsx (1 hunks)
  • app/client/src/utils/formControl/FormControlRegistry.tsx (2 hunks)
  • app/client/src/utils/formControl/formControlTypes.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/utils/formControl/formControlTypes.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
🔇 Additional comments (1)
app/client/src/components/formControls/HybridSearch.tsx (1)

1-10: LGTM! Clean imports and interface definition.

The imports are well-organized and the interface properly extends the base types while handling potential conflicts.

jsartisan
jsartisan previously approved these changes Feb 14, 2025
@nsarupr nsarupr added the ok-to-test Required label for CI label Feb 14, 2025
@KelvinOm KelvinOm merged commit 0e67bbc into release Feb 14, 2025
47 checks passed
@KelvinOm KelvinOm deleted the chore/hybrid-search branch February 14, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anvil Pod Issue related to Anvil project ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add custom Hybrid Search component to UQI forms
3 participants