Skip to content

Conversation

@hajdul88
Copy link
Collaborator

@hajdul88 hajdul88 commented Mar 17, 2025

Description

Exposes the query method of the adapter in the search interface for Kuzu and Neo4j (cypher compatible adapters)

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

  • New Features
    • Introduced a new cypher-based search option that expands the app's search functionality.
    • Enabled asynchronous processing for advanced query execution.
    • Enhanced error messaging for unsupported search types and query execution issues.
    • Added a new enumeration value for CYPHER to support the new search type.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

Walkthrough

This pull request introduces a new cypher search retrieval feature to the Cognee API. A new file with the CypherSearchRetriever class is added, implementing asynchronous methods for handling cypher queries and context retrieval with appropriate error handling through custom exceptions. The updates also include adding a new search type CYPHER to the SearchType enumeration and mapping it to the retrieval method in the search module. Additionally, a dedicated exceptions module is created to support these changes.

Changes

File Change Summary
cognee/modules/retrieval/cypher_search_retriever.py Added new file with CypherSearchRetriever class, including async get_context and get_completion methods for cypher-based searches.
cognee/modules/retrieval/exceptions/__init__.py
cognee/modules/retrieval/exceptions/exceptions.py
Created a new exceptions module and added SearchTypeNotSupported and CypherSearchError exception classes for handling cypher search related errors.
cognee/modules/search/methods/search.py Updated specific_search to map SearchType.CYPHER to CypherSearchRetriever().get_completion, integrating the new search feature.
cognee/modules/search/types/SearchType.py Added a new enumeration value CYPHER to the SearchType class.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SearchModule as specific_search
  participant Retriever as CypherSearchRetriever
  participant GraphEngine

  Client->>SearchModule: Initiate CYPHER query
  SearchModule->>Retriever: Call get_completion(query)
  Retriever->>GraphEngine: Retrieve graph engine instance
  GraphEngine-->>Retriever: Return graph engine
  alt GraphEngine is NetworkXAdapter
    Retriever->>Retriever: Raise SearchTypeNotSupported error
  else Valid GraphEngine
    Retriever->>GraphEngine: Execute cypher query asynchronously
    GraphEngine-->>Retriever: Return query result
  end
  Retriever-->>SearchModule: Return result/context
  SearchModule-->>Client: Provide search result
Loading

Possibly related PRs

Suggested reviewers

  • borisarzentar

Poem

In a meadow of code, I hop and play,
New features bloom in a bright array.
Cypher queries dance, swift and neat,
Exceptions catch errors in every beat.
With each line of code, my joy does grow—🐰
Hopping through changes in a rhythmic flow!
Let’s celebrate with a jaunty, bug-free show!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 f85a30a and d81c1b5.

📒 Files selected for processing (2)
  • cognee/modules/search/methods/search.py (2 hunks)
  • cognee/modules/search/types/SearchType.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cognee/modules/search/types/SearchType.py
🧰 Additional context used
🧬 Code Definitions (1)
cognee/modules/search/methods/search.py (1)
cognee/modules/retrieval/cypher_search_retriever.py (2) (2)
  • CypherSearchRetriever (12-44)
  • get_completion (40-44)
⏰ Context from checks skipped due to timeout of 90000ms (35)
  • GitHub Check: Test on macos-15
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on macos-15
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: lint (ubuntu-latest, 3.10.x)
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: Test on macos-13
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_multimedia_example_test / 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: Test on ubuntu-22.04
  • GitHub Check: chromadb test
  • GitHub Check: run_simple_example_test
  • GitHub Check: Test cognee server start
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: docker-compose-test
  • GitHub Check: Build Cognee Backend Docker App Image
🔇 Additional comments (2)
cognee/modules/search/methods/search.py (2)

15-15: LGTM: Import statement added for the new CypherSearchRetriever

The import statement is correctly placed with other retriever imports, following the established pattern in the file.


69-69: LGTM: New search type correctly added to search_tasks dictionary

The SearchType.CYPHER is properly mapped to the CypherSearchRetriever().get_completion method, following the same pattern as other search types. This implementation enables the specific_search function to handle cypher queries as required by the PR objectives.

This change also aligns well with the implementation of the CypherSearchRetriever class, which includes proper error handling for unsupported adapters and execution errors.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@hajdul88 hajdul88 self-assigned this Mar 17, 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

🧹 Nitpick comments (4)
cognee/modules/retrieval/exceptions/exceptions.py (1)

1-13: Consider using a more generic error message

The SearchTypeNotSupported exception looks well-defined, but the default error message is very specific to CYPHER search: "CYPHER search type not supported by the adapter." Since this exception class could potentially be used for other search types, consider using a more generic message.

-        message: str = "CYPHER search type not supported by the adapter.",
+        message: str = "Search type not supported by the adapter.",
cognee/modules/retrieval/cypher_search_retriever.py (3)

12-14: Docstring clarity.

The docstring for CypherSearchRetriever is concise. Consider adding more details on prerequisites and usage context, such as mentioning which graph database adapters are supported or potential use cases.


15-23: Initialization logic is fine.

The initializer sets default user and system prompt paths. If these files are intended for dynamic prompt loading, consider adding basic file existence checks or exception handling for advanced usage scenarios.


24-41: Typographical fix in error message and broad exception catch.

  1. There's a small typo in the error log (“execture” instead of “execute”).
  2. The broad except Exception as e: might also catch non-query-related errors, potentially masking deeper issues. Consider refining it to catch more specific exceptions if feasible.
-logger.error("Failed to execture cypher search retrieval: %s", str(e))
+logger.error("Failed to execute cypher search retrieval: %s", str(e))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b9fe48 and 628aedb.

📒 Files selected for processing (5)
  • cognee/modules/retrieval/cypher_search_retriever.py (1 hunks)
  • cognee/modules/retrieval/exceptions/__init__.py (1 hunks)
  • cognee/modules/retrieval/exceptions/exceptions.py (1 hunks)
  • cognee/modules/search/methods/search.py (2 hunks)
  • cognee/modules/search/types/SearchType.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (34)
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-15
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on macos-13
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: Test cognee server start
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: run_notebook_test / test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: run_notebook_test / test
  • GitHub Check: test
  • GitHub Check: windows-latest
  • GitHub Check: test
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: chromadb test
  • GitHub Check: run_simple_example_test
  • GitHub Check: docker-compose-test
  • GitHub Check: run_simple_example_test
🔇 Additional comments (7)
cognee/modules/retrieval/exceptions/__init__.py (1)

1-7: Module structure looks clean and well-documented

The exceptions module is well-structured with a clear docstring explaining its purpose. The import statement correctly brings in the specific exceptions from the .exceptions module.

cognee/modules/search/types/SearchType.py (1)

12-12: LGTM: Addition of CYPHER_SEARCH enum value

The new CYPHER_SEARCH enum value is properly added to the SearchType class, following the same naming pattern as the existing enum values. This aligns with the PR objective to enhance search capabilities for Kuzu and Neo4j.

cognee/modules/search/methods/search.py (2)

15-15: Import statement properly placed

The import for CypherSearchRetriever is correctly placed with the other retriever imports.


69-69: CYPHER_SEARCH properly integrated

The new SearchType.CYPHER_SEARCH is properly mapped to the appropriate retriever method, following the same pattern as existing search types.

cognee/modules/retrieval/exceptions/exceptions.py (1)

15-22: CypherSearchError implementation looks good

The CypherSearchError exception is well-defined with an appropriate error message and HTTP 500 status code, which is suitable for runtime errors during query execution.

cognee/modules/retrieval/cypher_search_retriever.py (2)

1-10: Imports and logger initialization look good.

All required modules are correctly imported, and the logger is properly configured to track retrieval-related logs.


42-47: Evaluate usage of imported completion utility.

Although you import generate_completion at line 6, it’s not used in get_completion. If you intend to transform or augment the retrieved context, consider integrating generate_completion. Otherwise, remove the unused import to keep the code clean.

@hajdul88 hajdul88 requested a review from borisarzentar March 17, 2025 14:30
borisarzentar
borisarzentar previously approved these changes Mar 19, 2025
@hajdul88 hajdul88 merged commit 1c65682 into dev Mar 19, 2025
42 checks passed
@hajdul88 hajdul88 deleted the feature/cog-1469-create-a-cypher-query-search-type branch March 19, 2025 14:01
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