Skip to content

Conversation

@soobrosa
Copy link
Contributor

@soobrosa soobrosa commented Feb 27, 2025

Description

Delete legacy search implementations after migrating to new retriever classes

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

    • Enhanced search and retrieval capabilities, providing improved context resolution for code queries, completions, summaries, and graph connections.
  • Refactor

    • Shifted to a modular, object-oriented approach that consolidates query logic and streamlines error management for a more robust and scalable experience.
  • Bug Fixes

    • Improved error handling for unsupported search types and retrieval operations.

@soobrosa soobrosa requested a review from lxobr February 27, 2025 13:06
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Walkthrough

This pull request transitions the project’s retrieval logic from a procedural to an object‐oriented architecture. The changes replace direct function calls with the instantiation and use of various Retriever classes (e.g., CodeRetriever, ChunksRetriever, CompletionRetriever, and others) across API routers, modules, and tasks. Legacy files and functions related to code graph retrieval, search comparisons, and query implementations have been removed. New methods, such as as_search and resolve_edges_to_text, have been introduced to encapsulate retrieval and context resolution logic with improved modularity and dependency management.

Changes

File(s) Change Summary
cognee/api/v1/cognify/routers/get_code_pipeline_router.py Replaced direct call to code_graph_retrieval with instantiation of CodeRetriever and use of its get_context method.
cognee/modules/retrieval/{__init__.py, base_retriever.py, utils/code_graph_retrieval.py} Updated imports: removed code_graph_retrieval, added CodeRetriever; added new as_search method in BaseRetriever; removed deprecated retrieval utilities.
cognee/modules/search/methods/search.py Refactored search functionality to use new retriever classes (e.g., SummariesRetriever, InsightsRetriever, etc.) instead of legacy task functions.
cognee/tasks/{chunks, completion, graph, summarization}/* Replaced legacy asynchronous query functions with implementations that instantiate respective Retriever classes; removed several standalone query implementation files.
evals/qa_context_provider_utils.py, examples/python/graphiti_example.py Modified context resolution to utilize GraphCompletionRetriever and its resolve_edges_to_text method instead of legacy functions.
notebooks/cognee_graphiti_demo.ipynb Updated import statements and context preparation to adopt the new object-oriented retrieval approach via GraphCompletionRetriever.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API_Router
    participant CodeRetriever
    participant Backend_Service

    User->>API_Router: Send retrieval query
    API_Router->>CodeRetriever: Instantiate & call get_context(query)
    CodeRetriever->>Backend_Service: Process query & retrieve context
    Backend_Service-->>CodeRetriever: Return context data
    CodeRetriever-->>API_Router: Return context result
    API_Router-->>User: Deliver JSON response
Loading

Possibly related PRs

  • feat: codegraph improvements and new CODE search [COG-1351] #581: The changes in the main PR, which involve modifying the retrieval mechanism in the code_pipeline_retrieve function to use the CodeRetriever class, are related to the changes in the retrieved PR, which also introduces the CodeRetriever class and modifies the code_graph_retrieval function, indicating a direct connection at the code level.
  • Feat/cog 1365 unify retrievers #572: The changes in the main PR, which involve the introduction of the CodeRetriever class and modifications to the retrieval mechanism, are directly related to the changes in the retrieved PR, as both involve the implementation and restructuring of retrieval classes, specifically the CodeRetriever and its integration into a unified framework for various retrievers.

Suggested reviewers

  • lxobr
  • borisarzentar
  • hajdul88

Poem

I hopped through lines of code today,
Switching functions to classes in a clever way.
With CodeRetriever leading my quest,
I found fresh paths that work the best.
In my burrow of modules, logic’s all anew,
A joyful rabbit cheers for code that’s true!
🐇✨


📜 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 b02231d and 931717e.

📒 Files selected for processing (9)
  • cognee/api/v1/cognify/routers/get_code_pipeline_router.py (2 hunks)
  • cognee/modules/retrieval/base_retriever.py (2 hunks)
  • cognee/tasks/chunks/__init__.py (0 hunks)
  • cognee/tasks/completion/__init__.py (1 hunks)
  • cognee/tasks/graph/__init__.py (0 hunks)
  • cognee/tasks/summarization/__init__.py (0 hunks)
  • evals/qa_context_provider_utils.py (2 hunks)
  • examples/python/graphiti_example.py (2 hunks)
  • notebooks/cognee_graphiti_demo.ipynb (2 hunks)
💤 Files with no reviewable changes (3)
  • cognee/tasks/summarization/init.py
  • cognee/tasks/graph/init.py
  • cognee/tasks/chunks/init.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • examples/python/graphiti_example.py
  • cognee/api/v1/cognify/routers/get_code_pipeline_router.py
  • cognee/tasks/completion/init.py
  • cognee/modules/retrieval/base_retriever.py
  • notebooks/cognee_graphiti_demo.ipynb
  • evals/qa_context_provider_utils.py
⏰ Context from checks skipped due to timeout of 90000ms (29)
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on macos-15
  • GitHub Check: run_multimedia_example_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_notebook_test / test
  • GitHub Check: run_networkx_metrics_test / test
  • GitHub Check: Test on macos-13
  • GitHub Check: Test on macos-13
  • GitHub Check: run_simple_example_test / test
  • GitHub Check: run_dynamic_steps_example_test / test
  • GitHub Check: Test on macos-15
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: run_notebook_test / test
  • GitHub Check: test
  • GitHub Check: run_eval_framework_test / test
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: Test on macos-13
  • GitHub Check: test
  • GitHub Check: windows-latest
  • GitHub Check: test
  • GitHub Check: Test on ubuntu-22.04
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Build Cognee Backend Docker App Image
  • GitHub Check: docker-compose-test

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: 1

🧹 Nitpick comments (2)
cognee/tasks/chunks/__init__.py (1)

1-14: Implementation looks good, consider adding error handling

The transition to an object-oriented retriever approach looks clean. The function correctly awaits the retriever's get_completion method.

For improved robustness, consider adding error handling:

async def query_chunks(query: str):
+    try:
        return await chunks_retriever.get_completion(query)
+    except Exception as e:
+        # Log the error
+        logger.error(f"Error querying chunks: {e}")
+        # Re-raise or handle appropriately
+        raise
cognee/tasks/completion/__init__.py (1)

6-6: Unused exception import.

NoRelevantDataFound is imported but never used. Consider removing it if not needed, or handle the exception if it is expected to be raised.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b7c21d and 30927d7.

📒 Files selected for processing (19)
  • cognee/api/v1/cognify/routers/get_code_pipeline_router.py (2 hunks)
  • cognee/modules/retrieval/__init__.py (1 hunks)
  • cognee/modules/retrieval/base_retriever.py (2 hunks)
  • cognee/modules/retrieval/utils/code_graph_retrieval.py (0 hunks)
  • cognee/modules/retrieval/utils/run_search_comparisons.py (0 hunks)
  • cognee/modules/search/methods/search.py (2 hunks)
  • cognee/tasks/chunks/__init__.py (1 hunks)
  • cognee/tasks/chunks/query_chunks.py (0 hunks)
  • cognee/tasks/completion/__init__.py (1 hunks)
  • cognee/tasks/completion/graph_query_completion.py (0 hunks)
  • cognee/tasks/completion/graph_query_summary_completion.py (0 hunks)
  • cognee/tasks/completion/query_completion.py (0 hunks)
  • cognee/tasks/graph/__init__.py (1 hunks)
  • cognee/tasks/graph/query_graph_connections.py (0 hunks)
  • cognee/tasks/summarization/__init__.py (1 hunks)
  • cognee/tasks/summarization/query_summaries.py (0 hunks)
  • evals/qa_context_provider_utils.py (2 hunks)
  • examples/python/graphiti_example.py (2 hunks)
  • notebooks/cognee_graphiti_demo.ipynb (2 hunks)
💤 Files with no reviewable changes (8)
  • cognee/tasks/summarization/query_summaries.py
  • cognee/tasks/chunks/query_chunks.py
  • cognee/tasks/graph/query_graph_connections.py
  • cognee/tasks/completion/query_completion.py
  • cognee/tasks/completion/graph_query_completion.py
  • cognee/modules/retrieval/utils/run_search_comparisons.py
  • cognee/tasks/completion/graph_query_summary_completion.py
  • cognee/modules/retrieval/utils/code_graph_retrieval.py
✅ Files skipped from review due to trivial changes (1)
  • cognee/modules/retrieval/init.py
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint (ubuntu-latest, 3.10.x)
  • GitHub Check: Build Cognee Backend Docker App Image
  • GitHub Check: docker-compose-test
🔇 Additional comments (18)
cognee/tasks/graph/__init__.py (1)

3-12:

Details

❓ Verification inconclusive

Implementation looks good, import path consistency should be reviewed

The transition to using a retriever instance is well-implemented with proper async/await pattern.

I notice that InsightsRetriever is imported from cognee.modules.retrieval.retrievers while other retrievers in this PR are imported from cognee.modules.retrieval.base_retriever. This inconsistency might be intentional due to different implementations, but it's worth verifying that this is the correct import path to maintain consistency in code organization.


🏁 Script executed:

#!/bin/bash
# Verify import paths for retriever classes
echo "Checking import paths for various retriever classes:"
rg -A 1 "from cognee\.modules\.retrieval" --glob "*.py"

Length of output: 7042


Ensure Consistent Import Paths for Retrievers

The asynchronous implementation using InsightsRetriever is correctly set up with proper async/await usage. However, there's an inconsistency in the import paths. In cognee/tasks/graph/__init__.py, InsightsRetriever is imported from cognee.modules.retrieval.retrievers, whereas in other parts of the code (e.g., in cognee/modules/search/methods/search.py), it's imported directly from cognee.modules.retrieval.insights_retriever. Please verify whether this discrepancy is intentional. If not, consider unifying the import paths to maintain consistent code organization.

cognee/tasks/summarization/__init__.py (1)

1-11: Consistent retriever implementation, nice job!

This implementation follows the same pattern used in the other task modules, creating a single reusable retriever instance and wrapping it with an async function that maintains the same interface as before.

The code is clean, concise, and properly implements the async/await pattern. This approach provides better modularity and makes the codebase more maintainable.

examples/python/graphiti_example.py (2)

15-15: Import updated to use the new retriever class

This change aligns with the PR objective to transition to the new retriever classes, replacing the legacy search implementations.


52-54: Refactored to use object-oriented GraphCompletionRetriever

Good replacement of the legacy function call with the instantiation of GraphCompletionRetriever and its resolve_edges_to_text method. This makes the code more modular and follows the new retriever architecture.

cognee/api/v1/cognify/routers/get_code_pipeline_router.py (2)

7-7: Import updated to use the new retriever class

This change aligns with the PR objective to transition to the new retriever classes, replacing the legacy search implementations.


46-47: Refactored to use object-oriented CodeRetriever

Good replacement of the legacy code_graph_retrieval function with the instantiation of CodeRetriever and its get_context method. This follows the new retriever architecture pattern being established across the codebase.

notebooks/cognee_graphiti_demo.ipynb (2)

40-40: Import updated to use the new retriever class

This change aligns with the PR objective to transition to the new retriever classes, replacing the legacy search implementations.


189-190: Refactored to use object-oriented GraphCompletionRetriever

Good replacement of the legacy function call with the instantiation of GraphCompletionRetriever and its resolve_edges_to_text method. This change is consistent with similar refactoring in other files, showing a systematic approach to the transition.

evals/qa_context_provider_utils.py (2)

5-5: Import updated to use the new retriever class

This change aligns with the PR objective to transition to the new retriever classes, replacing the legacy search implementations.


125-126: Refactored to use object-oriented GraphCompletionRetriever

Good replacement of the legacy function call with the instantiation of GraphCompletionRetriever and its resolve_edges_to_text method. This change maintains consistent behavior while adopting the new retriever architecture.

cognee/tasks/completion/__init__.py (6)

1-5: All good on the base retriever imports.

These imports correctly reference the new retriever classes. No issues spotted with the import statements.


8-11: Singleton usage of retrievers.

Instantiating retrievers at the module level might be safe if they have no risky shared state. Otherwise, consider scoping them per-request or function for improved concurrency and debugging.


14-16: Async entry point is straightforward.

query_completion defers everything to completion_retriever with no intermediate logic. This is fine for clarity, though ensure error handling is done upstream if NoRelevantDataFound is raised.


19-21: Graph completion function is consistent.

Similar to query_completion. Confirm you have tests that cover scenarios with no or partial graph results.


23-25: Graph summary completion function.

Implementation is consistent with the overall pattern, returning graph_summary_completion_retriever.get_completion(query).


27-28: Edge resolution logic.

resolve_graph_context defers to graph_completion_retriever.resolve_edges_to_text. Looks good. Verify the call meets expected input/output format.

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

6-14: Retriever-based imports successfully replace legacy implementations.

The new imports for ChunksRetriever, InsightsRetriever, SummariesRetriever, and others align with the transition to an object-oriented retriever architecture. These changes appear consistent with the project’s broader refactor.


50-56: search_tasks dictionary refactor.

Switching to .as_search() references centralizes retrieval logic. This approach is clean and maintainable, enabling further extension as new retrievers are added.

Comment on lines +18 to +21
@classmethod
def as_search(cls) -> Callable:
"""Creates a search function from the retriever class."""
return lambda query: cls().get_completion(query)
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 27, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add await to async method call in lambda

The as_search method returns a lambda that calls get_completion without awaiting it, but get_completion is an async method as defined in lines 13-16. This will return a coroutine object instead of the actual completion result.

@classmethod
def as_search(cls) -> Callable:
    """Creates a search function from the retriever class."""
-    return lambda query: cls().get_completion(query)
+    return lambda query: await cls().get_completion(query)

Additionally, since this returns an awaitable function, you should update the return type annotation to reflect this:

@classmethod
-def as_search(cls) -> Callable:
+def as_search(cls) -> Callable[[str], Awaitable[Any]]:

This will require adding Awaitable to your imports.

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I agree with the rabbit here, but I tested and both seem to work. Conceptually, it does seem like we should await for the .get_completion somewhere.
I would probably go with the implementation that defines an inner function, for neatness, but up to you:

        async def search(query):
            return await cls().get_completion(query)

        return search

@hajdul88 , please chime in as you are the one with the most experience with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure we have to await it here as it is a lambda definition no?

Copy link
Collaborator

@lxobr lxobr left a comment

Choose a reason for hiding this comment

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

Nice work, looks good to me.

@soobrosa soobrosa merged commit d27f847 into dev Feb 27, 2025
36 checks passed
@soobrosa soobrosa deleted the feature/cog-1403-transition-to-new-retrievers-update-searches branch February 27, 2025 14:25
This was referenced Sep 11, 2025
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