Skip to content

Conversation

@hajdul88
Copy link
Collaborator

@hajdul88 hajdul88 commented Mar 4, 2025

…l to avoid additional params

Introduces lambda currying in question answering non parallel function to avoid unnecessary params

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

  • Refactor
    • Streamlined the question-answering process for cleaner, more efficient query handling.
    • Updated the handling of parameters in the answer generation process, allowing for a more dynamic integration of context.
    • Simplified test setups by reducing the number of parameters involved in the mock answer resolver.

@hajdul88 hajdul88 self-assigned this Mar 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

This pull request updates the answer generation module by modifying function signatures and call flows. In the executor, the callable in the engine options is updated to expect two string arguments instead of one, and the method no longer accepts a separate system prompt parameter. Meanwhile, the run module now wraps the answer resolver in a lambda that injects the system prompt at call time. These changes adjust how queries and prompts are passed without altering core functionality.

Changes

File(s) Change Summary
cognee/.../answer_generation_executor.py Updated the type signature of question_answering_engine_options from accepting one string to two. Removed the system_prompt parameter from question_answering_non_parallel and updated the resolver call accordingly.
cognee/.../answer_generation/run_question_answering_module.py Modified the assignment of answer_resolver by wrapping it in a lambda that supplies both the query and the system prompt, instead of passing the prompt as a separate argument to the executor method.
cognee/.../answer_generation_test.py Updated mock_answer_resolver to only take one parameter (query) and removed the system_prompt argument from the call to question_answering_non_parallel, aligning with the updated mock behavior.

Possibly related PRs

  • test: answer generation [COG-1234] #569: The changes in the main PR directly modify the question_answering_non_parallel method's signature and its invocation, which is also reflected in the test updates in the retrieved PR that remove the system_prompt parameter when calling this method.

Suggested reviewers

  • borisarzentar

Poem

I'm a bunny with a code-side hop,
New signatures made my heart go "pop!"
Lambda wraps the prompt just right,
Guiding queries in swift flight.
In the fields of clean code, I cheer with delight 🐰✨.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 98c8c71 and 552e77c.

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

15-15: Simplified mock function aligns with lambda currying approach.

The mock answer resolver side effect has been updated to only accept a query parameter, removing the system_prompt parameter that was previously required. This correctly mirrors the function signature changes made in the implementation.


18-20: Test updated correctly to match the new API design.

The call to question_answering_non_parallel has been modified to remove the system_prompt parameter, aligning with the PR objective of introducing lambda currying. The system prompt is now likely injected at a higher level, resulting in a cleaner function signature.


22-31:

Details

❓ Verification inconclusive

Verify that existing assertions still provide adequate test coverage.

The test assertions remain unchanged, which is appropriate since the functional behavior (receiving a mock answer) should be the same despite the signature changes. However, it might be worth adding a test to verify that the system prompt is correctly injected through the currying mechanism.


🏁 Script executed:

#!/bin/bash
# Check if there are other tests that might verify the system prompt injection
rg -A 3 -B 3 "system_prompt" --glob "cognee/tests/**/*.py"

# Look for the implementation of the answer resolver to understand how currying is implemented
fd -t f -e py "answer_generation" --exec grep -l "answer_resolver" {} \;

Length of output: 265


Action Required: Enhance Test Coverage for System Prompt Injection

The current assertions appropriately verify that questions, golden answers, and the generated mock answer are passed correctly despite the signature changes. However, because the executor now uses a currying mechanism to inject the system prompt (as seen in cognee/eval_framework/answer_generation/answer_generation_executor.py), please add a test case that explicitly verifies this injection. This additional coverage will ensure that the system prompt is correctly integrated and that future modifications to the currying logic won’t inadvertently break its functionality.

  • File: cognee/tests/unit/eval_framework/answer_generation_test.py
    (Current assertions verify core functionality but don’t address system prompt injection.)
  • File: cognee/eval_framework/answer_generation/answer_generation_executor.py
    (Validate that the currying mechanism correctly injects the system prompt.)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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.

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)
cognee/eval_framework/answer_generation/answer_generation_executor.py (1)

26-26: Consider updating parameter type annotation for clarity.

While functionally correct, there's a slight discrepancy between the type annotation and the actual usage pattern. The type annotation indicates a function that takes only one string parameter, but the actual function being passed from run_question_answering_module.py is a curried function that internally calls a two-parameter function.

Consider revising the type annotation to make this pattern more explicit, possibly with a comment:

- answer_resolver: Callable[[str], Awaitable[List[str]]],
+ answer_resolver: Callable[[str], Awaitable[List[str]]],  # Curried function that handles system_prompt internally
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cade574 and 98c8c71.

📒 Files selected for processing (2)
  • cognee/eval_framework/answer_generation/answer_generation_executor.py (2 hunks)
  • cognee/eval_framework/answer_generation/run_question_answering_module.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (32)
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • 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
  • GitHub Check: test
  • GitHub Check: windows-latest
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: run_simple_example_test
  • GitHub Check: lint (ubuntu-latest, 3.11.x)
  • GitHub Check: lint (ubuntu-latest, 3.10.x)
  • GitHub Check: docker-compose-test
  • GitHub Check: Build Cognee Backend Docker App Image
🔇 Additional comments (3)
cognee/eval_framework/answer_generation/run_question_answering_module.py (1)

51-53: Excellent implementation of lambda currying for the answer_resolver.

The lambda function elegantly injects the system_prompt parameter, simplifying the interface between run_question_answering and the question_answering_non_parallel method. This approach correctly implements the PR objective of introducing lambda currying to streamline the function calls.

cognee/eval_framework/answer_generation/answer_generation_executor.py (2)

5-5: Type signature update correctly reflects the enhanced callable interface.

The updated type signature now accurately indicates that the callables in the question_answering_engine_options dictionary accept two string parameters instead of one, which aligns perfectly with how the functions are actually defined in the code.


33-33: Method call simplified as a result of lambda currying.

This simplification is a direct benefit of the lambda currying approach implemented in the run_question_answering module. The code is now cleaner as it no longer needs to handle the system_prompt parameter explicitly at this level.

@hajdul88 hajdul88 changed the title chore: introducting lambda currying in question_answering_non_paralle… Adds currying to question_answering_non_paralle… Mar 4, 2025
@hajdul88 hajdul88 requested a review from borisarzentar March 4, 2025 14:32
@borisarzentar borisarzentar changed the title Adds currying to question_answering_non_paralle… fix: add currying to question_answering_non_parallel Mar 4, 2025
@hajdul88 hajdul88 merged commit 3e93dbe into dev Mar 4, 2025
40 checks passed
@hajdul88 hajdul88 deleted the feature/cog-1488-changing-question-answering-non-parallel-to-lambda-answer branch March 4, 2025 15:09
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.

3 participants