Skip to content

Feature/cog 1369 quick fix dynamic collection handling in search#567

Merged
borisarzentar merged 11 commits intodevfrom
feature/cog-1369-quick-fix-dynamic-collection-handling-in-search
Feb 21, 2025
Merged

Feature/cog 1369 quick fix dynamic collection handling in search#567
borisarzentar merged 11 commits intodevfrom
feature/cog-1369-quick-fix-dynamic-collection-handling-in-search

Conversation

@hajdul88
Copy link
Collaborator

@hajdul88 hajdul88 commented Feb 20, 2025

Description

Fixes search dynamic collection mapping in graph completion search

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
    • Adjusted graph processing to remove extraneous notifications when expected data elements are absent.
    • Updated query processing to ensure a more consistent selection of related data types.
    • Streamlined database error handling by aligning exception management with standard practices.

With the new dynamic collection handling edge collection is also getting mapped to nodes which will produce error messages.
@hajdul88 hajdul88 self-assigned this Feb 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

The pull request updates error handling and import logic in the graph modules and exception classes. In the CogneeGraph class, the method map_vector_distances_to_graph_nodes has been modified to remove a print statement for missing nodes, resulting in silent failures. In the graph_query_completion function, the import of ExtendableDataPoint is replaced by DataPoint, and the subclass retrieval is updated accordingly. Additionally, the EntityNotFoundError now inherits directly from Python’s built-in Exception with a simplified constructor. Public APIs remain unchanged.

Changes

File Path(s) Change Summary
cognee/modules/graph/.../CogneeGraph.py
cognee/tasks/completion/graph_query_completion.py
CogneeGraph.py: Removed the print feedback for missing nodes in map_vector_distances_to_graph_nodes.
graph_query_completion.py: Updated the import from ExtendableDataPoint to DataPoint and adjusted the subclass retrieval accordingly.
cognee/infrastructure/databases/exceptions/exceptions.py Modified EntityNotFoundError to inherit directly from Exception with a simplified constructor; removed legacy error logging comments.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client
    participant CG as map_vector_distances_to_graph_nodes
    participant Lookup as Node Lookup
    Caller->>CG: Invoke mapping with input vector IDs
    CG->>Lookup: Search for node by ID
    alt Node exists
        Lookup-->>CG: Return node data
        CG->>Caller: Process mapping with node data
    else Node missing
        Lookup-->>CG: No node found
        CG->>Caller: Proceed silently (no error message)
    end
Loading
sequenceDiagram
    participant Client as Client
    participant GQC as graph_query_completion
    participant DP as DataPoint
    Client->>GQC: Request graph query completion
    GQC->>DP: Execute get_all_subclasses(DataPoint)
    DP-->>GQC: Return list of subclasses
    GQC->>Client: Process query and provide results
Loading

Poem

In the realm of codes and bytes so fleet,
I hop through changes with joyful beat.
Missing nodes now quietly hide,
Imports refreshed on a brighter ride.
A tweak here, a shift there, my work’s complete—
A bunny’s code leap, oh so sweet! 🐇✨

✨ 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.

…llection handling it is normal and not an error
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

🔭 Outside diff range comments (1)
cognee/infrastructure/databases/exceptions/exceptions.py (1)

5-14: 💡 Verification agent

🧩 Analysis chain

Consider maintaining consistency in error hierarchy.

The change from CogneeApiError to Exception as the base class creates an inconsistency in the error hierarchy, as EntityAlreadyExistsError still inherits from CogneeApiError. This might lead to inconsistent error handling across the codebase.

Let's verify the impact of this change:


🏁 Script executed:

#!/bin/bash
# Search for catch blocks handling these exceptions
rg -A 3 "except (EntityNotFoundError|CogneeApiError)" 

Length of output: 432


Action Required: Refactor Error Hierarchy for Consistency

The recent change in EntityNotFoundError—switching its inheritance from CogneeApiError to the builtin Exception—creates an inconsistency with other error classes (e.g., EntityAlreadyExistsError still inherits from CogneeApiError). Although the catch block in cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py explicitly handles EntityNotFoundError, this split in the error hierarchy could lead to unpredictable handling when catching a general CogneeApiError in other parts of the codebase.

  • Impact: If parts of the application rely on a common base for error handling (i.e., CogneeApiError), they might not catch EntityNotFoundError as expected.
  • Recommendation: Revisit the error hierarchy and either have all custom errors (including EntityNotFoundError) extend CogneeApiError or refactor the others for uniformity.
🧹 Nitpick comments (1)
cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py (1)

218-220: Consider logging table not found errors.

Silently returning an empty list when a collection is not found might hide potential issues. Consider adding debug logging to help track these occurrences.

         except EntityNotFoundError:
+            logging.debug(f"Collection {collection_name} not found, returning empty list")
             # Ignore if collection does not exist
             return []
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1eca7e and 048fb88.

📒 Files selected for processing (2)
  • cognee/infrastructure/databases/exceptions/exceptions.py (1 hunks)
  • cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (28)
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-15
  • GitHub Check: run_simple_example_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: Test on macos-13
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • 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: Test on ubuntu-22.04
  • GitHub Check: windows-latest
  • GitHub Check: test
  • GitHub Check: Build Cognee Backend Docker App Image
  • GitHub Check: docker-compose-test

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

🔭 Outside diff range comments (2)
cognee/infrastructure/databases/exceptions/exceptions.py (2)

5-5: ⚠️ Potential issue

Inconsistency with PR objectives detected.

The AI summary indicates that EntityNotFoundError should inherit from Exception, but it's still inheriting from CogneeApiError. This inconsistency needs to be resolved.

Apply this diff to align with the PR objectives:

-class EntityNotFoundError(CogneeApiError):
+class EntityNotFoundError(Exception):

20-29: 💡 Verification agent

🧩 Analysis chain

Verify consistency in exception handling approach.

Given the changes to EntityNotFoundError, should EntityAlreadyExistsError follow the same pattern? Please verify if this class should also:

  1. Inherit from Exception instead of CogneeApiError
  2. Update its error logging behavior

🏁 Script executed:

#!/bin/bash
# Search for usage patterns of both exception classes
echo "Searching for EntityNotFoundError usage..."
rg "EntityNotFoundError" -A 5

echo "Searching for EntityAlreadyExistsError usage..."
rg "EntityAlreadyExistsError" -A 5

Length of output: 22687


Action Required: Standardize Exception Initialization

After reviewing the usage across the codebase, here are the findings:

  • Both EntityNotFoundError and EntityAlreadyExistsError consistently inherit from CogneeApiError across modules. There’s no indication that either should inherit directly from Exception.
  • In the infrastructure module (cognee/infrastructure/databases/exceptions/exceptions.py), the two exception classes use different initialization patterns:
    • EntityNotFoundError assigns instance attributes directly.
    • EntityAlreadyExistsError calls super().__init__.
  • There’s no evidence from the usage that an updated error logging behavior is necessary.

Recommendation:
For consistency, consider aligning the __init__ implementation of both exception classes. If the new pattern (direct attribute assignment) for EntityNotFoundError is intentional, then update EntityAlreadyExistsError to follow suit. Alternatively, revert the change in EntityNotFoundError to use super().__init__.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 048fb88 and 2f20c99.

📒 Files selected for processing (1)
  • cognee/infrastructure/databases/exceptions/exceptions.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (28)
  • GitHub Check: run_dynamic_steps_example_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: Test on macos-13
  • GitHub Check: Test on macos-15
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: test
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: windows-latest
  • GitHub Check: docker-compose-test
  • GitHub Check: Build Cognee Backend Docker App Image
🔇 Additional comments (2)
cognee/infrastructure/databases/exceptions/exceptions.py (2)

17-17:

Details

✅ Verification successful

Verify the impact of disabling error logging.

The TODO comment suggests that error logging is being disabled due to dynamic exception handling. Let's verify if this change aligns with the error handling requirements across the codebase.


🏁 Script executed:

#!/bin/bash
# Search for error logging patterns and exception handling in the codebase
echo "Searching for error logging patterns..."
rg "log.*error|log.*exception" -A 5

echo "Searching for dynamic exception handling patterns..."
rg "except.*as.*:|raise.*Exception|raise.*Error" -A 5

Length of output: 69040


Impact of Disabling Internal Error Logging in Exceptions Module

After verifying the repository’s error logging practices, it’s clear that the dynamic exception handling strategy now logs errors at higher levels (e.g., in service and route handlers) rather than within the exception class itself. Disabling internal error logging in cognee/infrastructure/databases/exceptions/exceptions.py is consistent with this approach and avoids redundant log entries.

  • The commented-out logger call in the exceptions module aligns with the established pattern found throughout the codebase.
  • All critical errors continue to be logged externally when caught, ensuring no loss in error visibility.

Overall, this change should have a minimal impact on error tracking while streamlining error handling.


1-2:

Details

✅ Verification successful

Review import requirements.

If both exception classes are changed to inherit from Exception, the CogneeApiError import would no longer be needed.


🏁 Script executed:

#!/bin/bash
# Check if CogneeApiError is used elsewhere in this directory
rg "CogneeApiError" ./cognee/infrastructure/databases/

Length of output: 588


Ensure consistency in your exception inheritance strategy.

The search confirms that both exception classes in cognee/infrastructure/databases/exceptions/exceptions.py still inherit from CogneeApiError and that it’s also used in EmbeddingException.py. Therefore, the import of CogneeApiError remains necessary. If you plan on refactoring these exceptions to inherit directly from Python’s built-in Exception, please ensure that all related exception classes across the codebase are updated accordingly.

@hajdul88
Copy link
Collaborator Author

Tests are failing because of the benchmark adapter unit tests from dev (google drive ban) otherwise this can be merged.

@soobrosa soobrosa self-requested a review February 20, 2025 15:43
@borisarzentar borisarzentar merged commit eba1515 into dev Feb 21, 2025
35 checks passed
@borisarzentar borisarzentar deleted the feature/cog-1369-quick-fix-dynamic-collection-handling-in-search branch February 21, 2025 12:45
ajuijas pushed a commit to ajuijas/cognee that referenced this pull request Mar 9, 2026
- Removed 5 legacy caching TODOs from cache_db_interface.py, test_fs_adapter_crud.py, and test_redis_adapter_crud.py referencing backward compatibility that was completed in PR topoteretes#2077.

- Removed 1 outdated dynamic exception handling TODO attached to dead code in exceptions.py from PR topoteretes#567.
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.

2 participants