Skip to content

Conversation

matea16
Copy link
Contributor

@matea16 matea16 commented Apr 17, 2025

Description

This PR adds support for the Memgraph graph database following the graph database integration guide:

  • Implemented MemgraphAdapter for interfacing with Memgraph.
  • Updated get_graph_engine.py to return MemgraphAdapter when appropriate.
  • Added a test script: test_memgraph.py.
  • Created a dedicated test workflow: .github/workflows/test_memgraph.yml.

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.

Copy link

Please make sure all the checkboxes are checked:

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have added end-to-end and unit tests (if applicable).
  • I have updated the documentation and README.md file (if necessary).
  • I have removed unnecessary code and debug statements.
  • PR title is clear and follows the convention.
  • I have tagged reviewers or team members for feedback.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change introduces support for the Memgraph graph database within the Cognee infrastructure. It adds a new MemgraphAdapter class implementing asynchronous graph database operations and metrics, integrates Memgraph into the graph engine factory, and provides a comprehensive asynchronous test script to validate Memgraph integration. The adapter supports node and edge management, graph traversals, data extraction, and advanced graph metrics. The test script exercises the main functionalities, including data ingestion, search, and cleanup, ensuring correct operation and isolation of the Memgraph backend.

Changes

File(s) Change Summary
cognee/infrastructure/databases/graph/get_graph_engine.py Added a conditional branch to the create_graph_engine function to support "memgraph" as a graph database provider. This includes credential checking and dynamic import/instantiation of the new MemgraphAdapter.
cognee/infrastructure/databases/graph/memgraph/adapter.py Introduced the MemgraphAdapter class, an asynchronous adapter for Memgraph. Implements node/edge management, graph queries, traversals, batch operations, property serialization, and advanced metrics calculations. Provides a rich API for graph manipulation and analysis, including error handling and concurrency optimizations.
cognee/tests/test_memgraph.py Added an asynchronous test script for Memgraph integration. Configures Cognee to use Memgraph, performs data setup and teardown, runs cognification, executes multiple search types, validates search history, and ensures data/system cleanup. Designed for isolated, repeatable testing of Memgraph backend functionality.

Sequence Diagram(s)

sequenceDiagram
    participant TestScript
    participant Cognee
    participant MemgraphAdapter
    participant MemgraphDB

    TestScript->>Cognee: Configure with Memgraph provider
    TestScript->>Cognee: Add dataset (file, string)
    TestScript->>Cognee: Run cognify on dataset
    Cognee->>MemgraphAdapter: Add nodes/edges
    MemgraphAdapter->>MemgraphDB: Execute Cypher queries

    TestScript->>Cognee: Get vector engine and search
    Cognee->>MemgraphAdapter: Query nodes/edges
    MemgraphAdapter->>MemgraphDB: Execute search queries

    TestScript->>Cognee: Get user and search history
    Cognee->>MemgraphAdapter: Query search history

    TestScript->>Cognee: Prune data and system metadata
    Cognee->>MemgraphAdapter: Delete nodes/edges
    MemgraphAdapter->>MemgraphDB: Execute deletion queries

    TestScript->>MemgraphAdapter: Validate graph is empty
    MemgraphAdapter->>MemgraphDB: Check node/edge count
Loading

Possibly related PRs

  • topoteretes/cognee#483: Adds a placeholder get_graph_metrics method to the graph database interface and dummy implementations in other adapters, which the current PR builds upon by providing a full implementation in the new MemgraphAdapter.

Suggested reviewers

  • lxobr
  • borisarzentar

Poem

In the warren of code, a new path appears,
Memgraph hops in, dispelling old fears.
Nodes and edges, metrics galore,
Async adventures—oh, data to explore!
With every test run, the rabbits all cheer,
For graphy new wonders are finally here!
🐇✨


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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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: 6

🧹 Nitpick comments (3)
cognee/infrastructure/databases/graph/memgraph/adapter.py (1)

539-544: Drop redundant f‑prefix to silence Ruff F541

There are no placeholders in the string.

-node_labels_query = f"""
+node_labels_query = """
🧰 Tools
🪛 Ruff (0.8.2)

539-544: f-string without any placeholders

Remove extraneous f prefix

(F541)

cognee/infrastructure/databases/graph/get_graph_engine.py (1)

70-80: Normalise provider name to lowercase for consistency

Other branches compare the lower‑cased value ("neo4j", "falkordb",
etc.). Using the raw string for Memgraph causes a mismatch when the config
holds "Memgraph" or "MEMGRAPH".

-    elif graph_database_provider == "memgraph":
+    elif graph_database_provider.lower() == "memgraph":
cognee/tests/test_memgraph.py (1)

1-107: Consider converting the script into a proper test case

The file contains a standalone async main() and uses bare assert
statements. Adapting it to pytest or unittest.IsolatedAsyncioTestCase
would:

  • integrate with existing CI tooling,
  • provide nicer reporting (assert rewrites, xfail/skip markers),
  • allow easy parametrisation for different graph back‑ends.

This is optional but will improve maintainability and observability of
future regressions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee34aac and d5d83cb.

⛔ Files ignored due to path filters (1)
  • .github/workflows/test_memgraph.yml is excluded by !**/*.yml
📒 Files selected for processing (3)
  • cognee/infrastructure/databases/graph/get_graph_engine.py (1 hunks)
  • cognee/infrastructure/databases/graph/memgraph/adapter.py (1 hunks)
  • cognee/tests/test_memgraph.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
cognee/infrastructure/databases/graph/get_graph_engine.py (1)
cognee/infrastructure/databases/graph/memgraph/adapter.py (1)
  • MemgraphAdapter (19-687)
🪛 Ruff (0.8.2)
cognee/infrastructure/databases/graph/memgraph/adapter.py

184-184: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


429-429: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


539-544: f-string without any placeholders

Remove extraneous f prefix

(F541)

@matea16 matea16 changed the base branch from main to dev April 18, 2025 07:29
@Vasilije1990 Vasilije1990 changed the title Add Memgraph integration feat: Add Memgraph integration Apr 29, 2025
@Vasilije1990 Vasilije1990 self-requested a review April 30, 2025 10:03
Vasilije1990
Vasilije1990 previously approved these changes Apr 30, 2025
@matea16 matea16 dismissed Vasilije1990’s stale review April 30, 2025 10:03

The merge-base changed after approval.

Copy link

gitguardian bot commented Apr 30, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9573981 Triggered Generic Password 84479ba .github/workflows/relational_db_migration_tests.yml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Member

@borisarzentar borisarzentar left a comment

Choose a reason for hiding this comment

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

@matea16 Thanks for the contribution! I left couple of comments and please look at coderabbit suggestions.

@Vasilije1990 Vasilije1990 self-requested a review May 7, 2025 17:08
@borisarzentar borisarzentar merged commit 5d415dc into topoteretes:dev May 10, 2025
12 of 28 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants