Skip to content

Commit

Permalink
refactor: refactor destination hierarchy into a three-tier setup (Bas…
Browse files Browse the repository at this point in the history
…eDestination → VectorDBDestination and GraphDBDestination) for better separation and future extensibility.
  • Loading branch information
lennertjansen committed Feb 4, 2025
1 parent 698519a commit 8190682
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
48 changes: 44 additions & 4 deletions backend/app/platform/destinations/_base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Base destination class."""
"""Base destination classes."""

from abc import abstractmethod
from abc import ABC, abstractmethod
from uuid import UUID

from app import schemas
from app.platform.chunks._base import BaseChunk


class BaseDestination:
"""Base destination class."""
class BaseDestination(ABC):
"""Common base destination class. This is the umbrella interface for all destinations."""

@abstractmethod
async def create(self, user: schemas.User) -> None:
Expand Down Expand Up @@ -45,6 +45,46 @@ async def search_for_sync_id(self, sync_id: UUID) -> None:
"""Search for a sync_id in the destination."""
pass

@abstractmethod
async def get_credentials(self, user: schemas.User) -> None:
"""Get credentials for the destination."""
pass


class VectorDBDestination(BaseDestination):
"""Abstract base class for destinations backed by a vector database.
Inherits from BaseDestination and can have additional vector-specific methods if necessary.
"""

# For now, no additional abstract methods are defined here; it uses BaseDestination's interface.
pass


class GraphDBDestination(BaseDestination):
"""Abstract base class for destinations backed by a graph database.
This interface defines additional methods specific to graph operations.
"""

@abstractmethod
async def create_node(self, node_properties: dict, label: str) -> None:
"""Create a node in the graph database."""
pass

@abstractmethod
async def create_relationship(
self, from_node_id: str, to_node_id: str, rel_type: str, properties: dict = None
) -> None:
"""Create a relationship between two nodes in the graph database."""
pass

@abstractmethod
async def bulk_create_nodes(self, nodes: list[dict]) -> None:
"""Bulk create nodes in the graph database."""
pass

@abstractmethod
async def bulk_create_relationships(self, relationships: list[dict]) -> None:
"""Bulk create relationships in the graph database."""
pass
4 changes: 2 additions & 2 deletions backend/app/platform/destinations/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
from app.platform.chunks._base import BaseChunk
from app.platform.configs.auth import WeaviateAuthConfig
from app.platform.decorators import destination
from app.platform.destinations._base import BaseDestination
from app.platform.destinations._base import VectorDBDestination
from app.platform.embedding_models._adapters import WeaviateModelAdapter
from app.platform.embedding_models._base import BaseEmbeddingModel
from app.vector_db.weaviate_service import WeaviateService


@destination("Weaviate", "weaviate", AuthType.config_class, "WeaviateAuthConfig")
class WeaviateDestination(BaseDestination):
class WeaviateDestination(VectorDBDestination):
"""Weaviate destination implementation."""

def __init__(self):
Expand Down

0 comments on commit 8190682

Please sign in to comment.