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

feat/reranker+optional_ovos_classifiers #529

Merged
merged 8 commits into from
Aug 4, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Aug 3, 2024

ovos-classifiers is still in pre-alpha and wont have a stable release anytime soon, make it an optional dependency of ovos-core 0.0.8

related #488

solves TODO to allow reranker to come from config instead of being hardcoded, closes #436

improves logs about reranking process for clarity

a new config option (default False) allows using the reranker while ignoring the skill self reported confidences

in example below wolfram alpha would normally be selected, but the reranker preferred the duck duck go answer

2024-08-04 01:46:56.692 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:269 - DEBUG - Tied skills: ['skill-ovos-ddg.openvoiceos', 'skill-ovos-wikipedia.openvoiceos', 'skill-ovos-wolfie.openvoiceos']
2024-08-04 01:46:56.693 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:275 - DEBUG - ReRanking answers from skills
2024-08-04 01:46:56.974 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9994009733200073 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-ddg.openvoiceos', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second.', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second.'}, 'conf': 2.229565217391304}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9994009733200073 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-wikipedia.openvoiceos', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second .', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'image': 'https://upload.wikimedia.org/wikipedia/commons/2/2e/Earth_to_Sun_-_en.png', 'title': 'Speed Of Light', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second .'}, 'conf': 2.1133333333333333}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9967312812805176 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-wolfie.openvoiceos', 'answer': 'The speed of light has a value of about 300 million meters per second', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'answer': 'The speed of light has a value of about 300 million meters per second'}, 'conf': 2.8085714285714287}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:287 - INFO - Handling with: skill-ovos-ddg.openvoiceos

recommend plugin: https://github.com/TigreGotico/ovos-flashrank-reranker-plugin

Summary by CodeRabbit

  • New Features

    • Improved error handling for the answer selection process, ensuring service functionality even if the re-ranking component is unavailable.
    • Conditional loading of classifiers based on configuration settings to enhance performance and efficiency.
    • Enhanced entity extraction logic to prevent errors when necessary keywords are unavailable.
    • Introduced a flexible configuration mechanism for dynamic retrieval of settings related to common query functionality.
  • Bug Fixes

    • Adjusted logic to default to a random answer when the re-ranker is not available, avoiding potential failures.
  • Chores

    • Removed unnecessary dependency on ovos-classifiers, simplifying project requirements.
    • Added ovos-classifiers dependency to the testing requirements for enhanced testing capabilities.

ovos-classifiers is still in pre-alpha and wont have a stable release anytime soon, make it an optional dependency of ovos-core 0.0.8
@JarbasAl JarbasAl added packaging dependency updates or packaging changes dependencies Pull requests that update a dependency file labels Aug 3, 2024
Copy link

coderabbitai bot commented Aug 3, 2024

Walkthrough

The recent updates enhance the stability and efficiency of the CommonQAService and OCPService classes by improving error handling and resource management. Key changes include a dynamic loading mechanism for re-ranking components and conditional imports for classifiers based on configuration settings. Additionally, the removal of the ovos-classifiers dependency simplifies project requirements, reflecting a strategic shift in functionality while ensuring the system remains robust and adaptable.

Changes

File Change Summary
ovos_core/intent_services/commonqa_service.py Added optional config parameter for dynamic re-ranker loading; improved fallback logic for answer selection.
ovos_core/intent_services/ocp_service.py Conditional import of classifiers based on config flags; lazy initialization of ocp_keywords for better resource management; refined entity extraction logic.
requirements/requirements.txt Removed ovos-classifiers dependency, simplifying project requirements.
requirements/tests.txt Added ovos-classifiers with version constraint for testing-related enhancements.
test/unittests/skills/test_ocp.py Updated import path for KeywordFeaturesVectorizer.load_entities to reflect module reorganization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommonQAService
    participant Reranker

    User->>CommonQAService: Ask a question
    CommonQAService->>CommonQAService: Check for Reranker
    alt Reranker available
        CommonQAService->>Reranker: Use to select answer
    else Reranker not available
        CommonQAService->>CommonQAService: Randomly select first answer
    end
    CommonQAService->>User: Provide answer
Loading
sequenceDiagram
    participant User
    participant OCPService
    participant Classifier

    User->>OCPService: Submit media
    OCPService->>OCPService: Check if Classifier is enabled
    alt Classifier enabled
        OCPService->>Classifier: Classify media
    else Classifier not enabled
        OCPService->>OCPService: Skip classification
    end
    OCPService->>User: Provide results
Loading

Poem

🐰 In the code where bunnies hop,
Changes made, we’ll never stop!
Rerank or random, answers flow,
With classifiers, watch us grow!
Dependencies trimmed, we bound so free,
Code so fine, just like me! 🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e10e010 and ca7bd9f.

Files selected for processing (3)
  • ovos_core/intent_services/commonqa_service.py (3 hunks)
  • ovos_core/intent_services/ocp_service.py (7 hunks)
  • requirements/requirements.txt (1 hunks)
Files skipped from review due to trivial changes (1)
  • requirements/requirements.txt
Additional comments not posted (8)
ovos_core/intent_services/commonqa_service.py (2)

46-55: Improved error handling for re-ranking component initialization.

The try-except block ensures that the service remains functional even if the BM25MultipleChoiceSolver import fails. This improves the robustness of the service.


264-270: Enhanced decision-making process for selecting the best answer.

The changes ensure that the service can still function even when the re-ranking component is unavailable. This improves the robustness of the service.

ovos_core/intent_services/ocp_service.py (6)

Line range hint 152-157:
Conditional import of SklearnOVOSClassifier for binary classifiers.

The conditional import ensures that the classifier is only imported when necessary, potentially reducing overhead during initialization. This improves resource management and performance.


Line range hint 163-168:
Conditional import of SklearnOVOSClassifier for media type classifiers.

The conditional import ensures that the classifier is only imported when necessary, potentially reducing overhead during initialization. This improves resource management and performance.


Line range hint 732-745:
Efficient media type classification using conditional import of SklearnOVOSClassifier.

The conditional import and use of the classifier ensure that the media type is determined efficiently based on the query. This improves resource management and performance.


Line range hint 758-772:
Efficient playback question classification using conditional import of SklearnOVOSClassifier.

The conditional import and use of the classifier ensure that the playback question is determined efficiently based on the query. This improves resource management and performance.


1250-1254: Lazy initialization of KeywordFeaturesVectorizer in OCPFeaturizer.

The lazy initialization strategy ensures that the vectorizer is only created when explicitly needed, optimizing resource usage.


1250-1254: Lazy initialization of KeywordFeaturesVectorizer in OCPFeaturizer.

The lazy initialization strategy ensures that the vectorizer is only created when explicitly needed, optimizing resource usage.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca7bd9f and f60e12a.

Files selected for processing (3)
  • ovos_core/intent_services/ocp_service.py (10 hunks)
  • requirements/tests.txt (1 hunks)
  • test/unittests/skills/test_ocp.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ovos_core/intent_services/ocp_service.py
Additional comments not posted (2)
requirements/tests.txt (1)

22-23: LGTM! Verify compatibility with other dependencies.

The addition of the ovos-classifiers package with the specified version constraint and the accompanying comment is appropriate.

However, ensure that this new dependency does not conflict with existing ones.

Verification successful

No conflicts found with the addition of ovos-classifiers dependency.

The ovos-classifiers package with the specified version constraint does not conflict with existing dependencies in requirements/tests.txt.

  • requirements/tests.txt contains unique package names with no overlapping version constraints.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility of `ovos-classifiers` with other dependencies.

# Test: Check for conflicts. Expect: No conflicts.
pip install -r requirements/tests.txt

Length of output: 110


Script:

#!/bin/bash
# Description: Check for version conflicts in requirements/tests.txt

# List all packages with their version constraints in the requirements file
cat requirements/tests.txt | grep -E '^[a-zA-Z0-9\-]+[<>=!~]'

# Check for any overlapping or conflicting version constraints
awk '/^[a-zA-Z0-9\-]+[<>=!~]/ {print $1}' requirements/tests.txt | sort | uniq -d

Length of output: 507

test/unittests/skills/test_ocp.py (1)

21-21: LGTM! Verify the new import path.

The modification to the import path for the load_entities method is appropriate given the context.

However, ensure that the new import path is correct and that the method functions as expected.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f60e12a and 6de6954.

Files selected for processing (1)
  • ovos_core/intent_services/ocp_service.py (13 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ovos_core/intent_services/ocp_service.py

Copy link

codecov bot commented Aug 3, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 75.37%. Comparing base (41fb56b) to head (6b268fb).
Report is 1 commits behind head on dev.

Files Patch % Lines
ovos_core/intent_services/commonqa_service.py 59.37% 13 Missing ⚠️
ovos_core/intent_services/ocp_service.py 78.37% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #529      +/-   ##
==========================================
- Coverage   75.70%   75.37%   -0.34%     
==========================================
  Files          15       15              
  Lines        3042     3086      +44     
==========================================
+ Hits         2303     2326      +23     
- Misses        739      760      +21     
Flag Coverage Δ
unittests 75.37% <70.00%> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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

Outside diff range, codebase verification and nitpick comments (1)
ovos_core/intent_services/commonqa_service.py (1)

34-34: Constructor Update: Ensure all instantiations are updated.

The constructor now accepts an optional config parameter. Ensure all instantiations of CommonQAService are updated to pass the new parameter if needed. Specifically, update the instantiation in test/unittests/common_query/test_common_query.py to include the config parameter if configuration testing is required.

  • test/unittests/common_query/test_common_query.py: Update instantiation to include config.
Analysis chain

Constructor Update: Ensure all instantiations are updated.

The constructor now accepts an optional config parameter. Ensure all instantiations of CommonQAService are updated to pass the new parameter if needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` are updated to pass the new `config` parameter if needed.

# Test: Search for the class instantiation. Expect: Occurrences of the new signature.
rg --type python -A 5 $'CommonQAService('

Length of output: 125


Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` are updated to pass the new `config` parameter if needed.

# Test: Search for the class instantiation. Expect: Occurrences of the new signature.
rg --type python -A 5 $'CommonQAService\\('

Length of output: 74


Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` are updated to pass the new `config` parameter if needed.

# Test: Search for the class instantiation. Expect: Occurrences of the new signature.
rg -t py -A 5 $'CommonQAService\\('

Length of output: 1652

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6de6954 and 0cf8096.

Files selected for processing (2)
  • ovos_core/intent_services/init.py (1 hunks)
  • ovos_core/intent_services/commonqa_service.py (3 hunks)
Additional comments not posted (2)
ovos_core/intent_services/commonqa_service.py (1)

263-269: Robustness Improvement: Default behavior for missing re-ranker.

The changes improve robustness by ensuring the service remains functional even when the re-ranker is unavailable. The default behavior of picking the first answer is a reasonable fallback.

ovos_core/intent_services/__init__.py (1)

67-67: Configuration Update: Ensure consistency with CommonQAService.

The change ensures that the CommonQAService is instantiated with the appropriate configuration, aligning with the changes made in commonqa_service.py.

ovos_core/intent_services/commonqa_service.py Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0cf8096 and 1a0565e.

Files selected for processing (1)
  • ovos_core/intent_services/commonqa_service.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ovos_core/intent_services/commonqa_service.py

@JarbasAl
Copy link
Member Author

JarbasAl commented Aug 3, 2024

closes #436

@JarbasAl JarbasAl added this to the 0.1.0 milestone Aug 3, 2024
@JarbasAl JarbasAl added the enhancement New feature or request label Aug 3, 2024
@JarbasAl JarbasAl modified the milestones: 0.1.0, 0.0.8 Aug 3, 2024
```
2024-08-04 01:46:56.692 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:269 - DEBUG - Tied skills: ['skill-ovos-ddg.openvoiceos', 'skill-ovos-wikipedia.openvoiceos', 'skill-ovos-wolfie.openvoiceos']
2024-08-04 01:46:56.693 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:275 - DEBUG - ReRanking answers from skills
2024-08-04 01:46:56.974 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9994009733200073 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-ddg.openvoiceos', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second.', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second.'}, 'conf': 2.229565217391304}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9994009733200073 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-wikipedia.openvoiceos', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second .', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'image': 'https://upload.wikimedia.org/wikipedia/commons/2/2e/Earth_to_Sun_-_en.png', 'title': 'Speed Of Light', 'answer': 'The speed of light in vacuum, commonly denoted c, is a universal physical constant that is exactly equal to 299,792,458 metres per second .'}, 'conf': 2.1133333333333333}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:280 - INFO - ReRanked score: 0.9967312812805176 - {'phrase': 'what is the speed of light', 'skill_id': 'skill-ovos-wolfie.openvoiceos', 'answer': 'The speed of light has a value of about 300 million meters per second', 'handles_speech': True, 'callback_data': {'query': 'what is the speed of light', 'answer': 'The speed of light has a value of about 300 million meters per second'}, 'conf': 2.8085714285714287}
2024-08-04 01:46:56.975 - skills - ovos_core.intent_services.commonqa_service:_query_timeout:287 - INFO - Handling with: skill-ovos-ddg.openvoiceos
```

add "ignore_skill_scores" config option, rely on the reranker for best answer selection while ignore self reported confidence by skills
@JarbasAl JarbasAl changed the title packaging/optional_ovos_classifiers feat/reranker+optional_ovos_classifiers Aug 4, 2024
Copy link

@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

Outside diff range, codebase verification and nitpick comments (1)
ovos_core/intent_services/commonqa_service.py (1)

35-59: Constructor changes approved.

The changes enhance flexibility and robustness by allowing dynamic configuration and handling potential plugin loading failures. However, the instantiation in the test file should be updated to pass the config parameter.

  • test/unittests/common_query/test_common_query.py: Update the instantiation to include the config parameter.
Analysis chain

Constructor changes approved.

The changes enhance flexibility and robustness by allowing dynamic configuration and handling potential plugin loading failures.

However, ensure that all instantiations of CommonQAService pass the correct configuration.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` pass the correct configuration.

# Test: Search for the class instantiation. Expect: Occurrences of the new constructor signature.
rg --type python -A 5 $'CommonQAService('

Length of output: 125


Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` pass the correct configuration.

# Test: Search for the class instantiation. Expect: Occurrences of the new constructor signature.
rg --type python -A 5 'CommonQAService\('

Length of output: 74


Script:

#!/bin/bash
# Description: Verify all instantiations of `CommonQAService` pass the correct configuration.

# Test: Search for the class instantiation. Expect: Occurrences of the new constructor signature.
rg --type py -A 5 'CommonQAService\('

Length of output: 1656

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a0565e and 6b268fb.

Files selected for processing (1)
  • ovos_core/intent_services/commonqa_service.py (3 hunks)
Additional comments not posted (1)
ovos_core/intent_services/commonqa_service.py (1)

257-284: Answer selection logic changes approved.

The changes improve the answer selection process by utilizing the re-ranking functionality if available.

@JarbasAl JarbasAl merged commit e5e0316 into dev Aug 4, 2024
7 of 8 checks passed
@JarbasAl JarbasAl deleted the packaging/optional_ovos_classifiers branch August 4, 2024 01:34
This was referenced Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request packaging dependency updates or packaging changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat - CommonQuery Disambiguation
1 participant