Skip to content

Feature/typedb integration #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ascender1729
Copy link
Contributor

@ascender1729 ascender1729 commented Mar 30, 2025

Add TypeDB Integration

Description

This PR adds TypeDB integration to the Swarms project, providing a robust graph database wrapper for knowledge representation and relationship modeling. The implementation includes:

  1. TypeDBWrapper Class:

    • Connection management with configurable settings
    • Schema definition and management
    • CRUD operations (Create, Read, Update, Delete)
    • Transaction handling
    • Error handling and logging
    • Context manager support
  2. Features:

    • Type-safe schema definitions
    • Efficient query execution
    • Automatic connection management
    • Comprehensive error handling
    • Detailed logging
    • Example usage
  3. Example Implementation:

    • Knowledge graph schema
    • Data insertion and querying
    • Relationship modeling
    • Data deletion and verification

Issue

Fixes #794 (Integration with the TypeDB graph database)

Dependencies

Added to requirements.txt:

  • typedb-client>=2.25.0
  • typedb-protocol>=2.25.0
  • typedb-driver>=2.25.0

Testing

Added comprehensive test suite in tests/utils/test_typedb_wrapper.py:

  • Connection management tests
  • Schema definition tests
  • CRUD operation tests
  • Error handling tests
  • Context manager tests

All tests can be run using:

pytest tests/utils/test_typedb_wrapper.py -v

Tag Maintainer

@kyegomez (General / Misc)

Twitter Handle

@the_complex_one

Example Usage

from swarms.utils.typedb_wrapper import TypeDBWrapper, TypeDBConfig

# Initialize wrapper
config = TypeDBConfig(
    uri="localhost:1729",
    database="swarms_example"
)

# Use context manager for automatic cleanup
with TypeDBWrapper(config) as db:
    # Define schema
    schema = """
    define
    person sub entity,
        owns name: string,
        owns age: long;
    """
    db.define_schema(schema)
    
    # Insert data
    query = """
    insert
    $p isa person, has name "John Doe", has age 30;
    """
    db.insert_data(query)
    
    # Query data
    results = db.query_data("match $p isa person; get;")
    print(results)

Benefits

  1. Enhanced knowledge representation
  2. Efficient relationship modeling
  3. Type-safe schema definitions
  4. Robust error handling
  5. Easy integration with existing code
  6. Comprehensive documentation and examples

📚 Documentation preview 📚: https://swarms--803.org.readthedocs.build/en/803/

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here: https://app.greptile.com/review/github.

💡 (4/5) You can add custom instructions or style guidelines for the bot here!

12 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

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.

[Function] Integration with the TypeDB graph database
1 participant