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

Test: Parse context pieces separately in MusiqueQAAdapter and adjust tests [cog-1234] #561

Merged
merged 7 commits into from
Feb 20, 2025

Conversation

alekszievr
Copy link
Contributor

@alekszievr alekszievr commented Feb 19, 2025

Description

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin

Summary by CodeRabbit

  • Tests

    • Updated evaluation checks by removing assertions related to the relationship between corpus_list and qa_pairs, now focusing solely on qa_pairs limits.
  • Refactor

    • Improved content processing to append each paragraph individually to corpus_list, enhancing clarity in data structure.
    • Simplified type annotations in the load_corpus method across multiple adapters, ensuring consistency in return types.
  • Chores

    • Updated dependency installation commands in GitHub Actions workflows for Python 3.10, 3.11, and 3.12 to include additional evaluation-related dependencies.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes involve updates to the test cases in the benchmark adapters test file and modifications to the MusiqueQAAdapter class. The test file no longer asserts that the lengths of corpus_list and qa_pairs are equal or that corpus_list meets a specific limit, focusing only on qa_pairs. In the adapter implementation, each paragraph's text is now appended individually to corpus_list, altering its structure. Additionally, the GitHub Actions workflows for Python 3.10, 3.11, and 3.12 have been updated to include extra dependencies during installation.

Changes

File(s) Change Summary
cognee/tests/.../benchmark_adapters_test.py Removed assertions comparing lengths of corpus_list and qa_pairs, and eliminated the limit check on corpus_list; now only checks qa_pairs.
evals/eval_framework/.../musique_adapter.py Modified MusiqueQAAdapter.load_corpus to append each paragraph's text individually rather than concatenating them, resulting in separate entries in corpus_list.
.github/workflows/test_python_3_10.yml Updated dependency installation command to include -E evals for additional evaluation-related dependencies.
.github/workflows/test_python_3_11.yml Updated dependency installation command to include -E evals for additional evaluation-related dependencies.
.github/workflows/test_python_3_12.yml Updated dependency installation command to include -E evals for additional evaluation-related dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant A as MusiqueQAAdapter
    participant D as Dataset

    C->>A: Call load_corpus(limit)
    A->>D: Load dataset items
    loop For each item in dataset
        A->>A: Iterate over paragraphs
        A->>A: Append each paragraph text individually to corpus_list
    end
    A->>C: Return corpus_list and qa_pairs
Loading

Possibly related PRs

  • Add musique adapter base #525: Modifications in test assertions in this PR are directly related to changes in the MusiqueQAAdapter’s load_corpus method adjustments.

Suggested reviewers

  • hajdul88

Poem

In the code’s warren I hop and play,
Changes unfurled in a bright new way.
Each paragraph now stands on its own,
Assertions refined, neatly shown.
With every fix my heart does skip —
A joyful hop from every byte and bit!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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.

@alekszievr alekszievr self-assigned this Feb 19, 2025
@alekszievr alekszievr force-pushed the test/cog-1234-test-eval-framework branch from 912fd88 to ef83afc Compare February 19, 2025 14:35
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 (1)
evals/eval_framework/benchmark_adapters/musique_adapter.py (1)

67-68: LGTM! Consider documenting the change in behavior.

The change to process each paragraph separately aligns with the PR objectives and provides more granular context pieces. This is a good improvement as it allows for more flexible processing downstream.

Consider updating the docstring to clarify that corpus_list now contains individual paragraphs rather than concatenated texts. Apply this diff:

     def load_corpus(
         self,
         limit: Optional[int] = None,
         seed: int = 42,
         auto_download: bool = True,
     ) -> tuple[list[str], list[dict[str, Any]]]:
         """
         Loads the Musique QA dataset.
 
         :param limit: If set, randomly sample 'limit' items.
         :param seed: Random seed for sampling.
         :param auto_download: If True, attempt to download + unzip the dataset
             from Google Drive if the .jsonl file is not present locally.
+        :return: A tuple containing:
+            - corpus_list: List of paragraph texts, where each paragraph is a separate entry
+            - question_answer_pairs: List of dictionaries containing question-answer pairs
         """
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a167fa and 912fd88.

📒 Files selected for processing (2)
  • cognee/tests/unit/eval_framework/benchmark_adapters_test.py (1 hunks)
  • evals/eval_framework/benchmark_adapters/musique_adapter.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (27)
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-15
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: Test on macos-13
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: windows-latest
  • GitHub Check: Build Cognee Backend Docker App Image
  • GitHub Check: docker-compose-test
🔇 Additional comments (1)
cognee/tests/unit/eval_framework/benchmark_adapters_test.py (1)

67-67: LGTM! The test changes align with the PR objectives.

The removal of assertions about corpus_list length makes sense since we're now parsing context pieces separately in MusiqueQAAdapter, which means corpus_list can have a different length than qa_pairs. The remaining assertions still ensure the core functionality and data structure requirements are met.

@alekszievr alekszievr changed the title Test: Parse context pieces separately in MusiqueQAAdapter and adjust tests Test: Parse context pieces separately in MusiqueQAAdapter and adjust tests [cog-1234] Feb 19, 2025
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

🔭 Outside diff range comments (2)
evals/eval_framework/benchmark_adapters/twowikimultihop_adapter.py (1)

20-29: 🛠️ Refactor suggestion

Add error handling for file operations and HTTP requests.

The current implementation could fail in several scenarios:

  1. File operations might fail due to permissions or disk space
  2. HTTP request might fail (only status code is checked)
  3. JSON parsing might fail due to malformed data

Consider wrapping the operations in try-except blocks:

         if os.path.exists(filename):
-            with open(filename, "r", encoding="utf-8") as f:
-                corpus_json = json.load(f)
+            try:
+                with open(filename, "r", encoding="utf-8") as f:
+                    corpus_json = json.load(f)
+            except (IOError, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Failed to load corpus from {filename}: {str(e)}")
         else:
-            response = requests.get(self.dataset_info["URL"])
-            response.raise_for_status()
-            corpus_json = response.json()
+            try:
+                response = requests.get(self.dataset_info["URL"], timeout=30)
+                response.raise_for_status()
+                corpus_json = response.json()
+            except (requests.RequestException, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Failed to fetch corpus from {self.dataset_info['URL']}: {str(e)}")

-            with open(filename, "w", encoding="utf-8") as f:
-                json.dump(corpus_json, f, ensure_ascii=False, indent=4)
+            try:
+                with open(filename, "w", encoding="utf-8") as f:
+                    json.dump(corpus_json, f, ensure_ascii=False, indent=4)
+            except IOError as e:
+                raise RuntimeError(f"Failed to save corpus to {filename}: {str(e)}")
evals/eval_framework/benchmark_adapters/hotpot_qa_adapter.py (1)

22-31: 🛠️ Refactor suggestion

Add error handling for file operations and HTTP requests.

The current implementation could fail in several scenarios:

  1. File operations might fail due to permissions or disk space
  2. HTTP request might fail (only status code is checked)
  3. JSON parsing might fail due to malformed data

Consider wrapping the operations in try-except blocks:

         if os.path.exists(filename):
-            with open(filename, "r", encoding="utf-8") as f:
-                corpus_json = json.load(f)
+            try:
+                with open(filename, "r", encoding="utf-8") as f:
+                    corpus_json = json.load(f)
+            except (IOError, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Failed to load corpus from {filename}: {str(e)}")
         else:
-            response = requests.get(self.dataset_info["url"])
-            response.raise_for_status()
-            corpus_json = response.json()
+            try:
+                response = requests.get(self.dataset_info["url"], timeout=30)
+                response.raise_for_status()
+                corpus_json = response.json()
+            except (requests.RequestException, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Failed to fetch corpus from {self.dataset_info['url']}: {str(e)}")

-            with open(filename, "w", encoding="utf-8") as f:
-                json.dump(corpus_json, f, ensure_ascii=False, indent=4)
+            try:
+                with open(filename, "w", encoding="utf-8") as f:
+                    json.dump(corpus_json, f, ensure_ascii=False, indent=4)
+            except IOError as e:
+                raise RuntimeError(f"Failed to save corpus to {filename}: {str(e)}")
🧹 Nitpick comments (1)
evals/eval_framework/benchmark_adapters/hotpot_qa_adapter.py (1)

10-15: Address TODO comments in dataset_info.

The dataset_info dictionary contains TODO comments about deleting files after changing URLs. These comments should be addressed.

Would you like me to help create an issue to track the cleanup of these TODO comments?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa62be6 and f7a2000.

📒 Files selected for processing (4)
  • evals/eval_framework/benchmark_adapters/dummy_adapter.py (1 hunks)
  • evals/eval_framework/benchmark_adapters/hotpot_qa_adapter.py (2 hunks)
  • evals/eval_framework/benchmark_adapters/musique_adapter.py (2 hunks)
  • evals/eval_framework/benchmark_adapters/twowikimultihop_adapter.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • evals/eval_framework/benchmark_adapters/musique_adapter.py
⏰ Context from checks skipped due to timeout of 90000ms (28)
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: windows-latest
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Build Cognee Backend Docker App Image
  • GitHub Check: docker-compose-test
🔇 Additional comments (3)
evals/eval_framework/benchmark_adapters/dummy_adapter.py (1)

1-1: LGTM! Type annotations simplified without affecting functionality.

The changes simplify the type annotations by using just str instead of Union[LiteralString, str], which is appropriate since the implementation only returns regular strings.

Also applies to: 9-9

evals/eval_framework/benchmark_adapters/twowikimultihop_adapter.py (1)

5-5: LGTM! Type annotations simplified without affecting functionality.

The changes simplify the type annotations by using just str instead of Union[LiteralString, str], which is appropriate since the implementation only returns regular strings.

Also applies to: 17-17

evals/eval_framework/benchmark_adapters/hotpot_qa_adapter.py (1)

5-5: LGTM! Type annotations simplified without affecting functionality.

The changes simplify the type annotations by using just str instead of Union[LiteralString, str], which is appropriate since the implementation only returns regular strings.

Also applies to: 19-19

@alekszievr alekszievr requested a review from hajdul88 February 19, 2025 15:53
@@ -47,7 +47,7 @@ jobs:
installer-parallel: true

- name: Install dependencies
run: poetry install --no-interaction -E docs
run: poetry install --no-interaction -E docs -E evals
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we install evals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we need the gdown library for testing the Musique adapter

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we test it in the regular cognify pipeline?

Copy link
Contributor

@hajdul88 hajdul88 left a comment

Choose a reason for hiding this comment

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

Tested it I think the article handling is correct now in musique

@alekszievr alekszievr merged commit 17231de into dev Feb 20, 2025
35 checks passed
@alekszievr alekszievr deleted the test/cog-1234-test-eval-framework branch February 20, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants