Entity

Bases: BaseModel

An entity (node) in a knowledge graph.

Attributes:
  • id (Optional[str]) –

    the unique id for the entity

  • label (Optional[str]) –

    an optional label for the entity

  • metadata (Optional[dict]) –

    optional information about the entity

Source code in wiseagents/graphdb/wise_agent_graph_db.py
12
13
14
15
16
17
18
19
20
21
22
23
class Entity(BaseModel):
    """
    An entity (node) in a knowledge graph.

    Attributes:
        id (Optional[str]): the unique id for the entity
        label (Optional[str]): an optional label for the entity
        metadata (Optional[dict]): optional information about the entity
    """
    id: Optional[str] = Field(default_factory=lambda: str(uuid.uuid4()))
    label: Optional[str] = "entity"
    metadata: Optional[dict] = Field(default_factory=dict)

GraphDocument

Bases: BaseModel

A graph document is a collection of entities and relationships that are part of a knowledge graph.

Attributes:
  • entities (List[Entity]) –

    the entities in the graph document

  • relationships (List[Relationship]) –

    the relationships in the graph document

  • source (Source) –

    the source that contains the entities and relationships

Source code in wiseagents/graphdb/wise_agent_graph_db.py
56
57
58
59
60
61
62
63
64
65
66
67
class GraphDocument(BaseModel):
    """
    A graph document is a collection of entities and relationships that are part of a knowledge graph.

    Attributes:
        entities (List[Entity]): the entities in the graph document
        relationships (List[Relationship]): the relationships in the graph document
        source (Source): the source that contains the entities and relationships
    """
    entities: List[Entity]
    relationships: List[Relationship]
    source: Source

Relationship

Bases: BaseModel

A relationship (edge) in a knowledge graph.

Attributes:
  • label (str) –

    a description of the relationship

  • source (Entity) –

    the source entity

  • target (Entity) –

    the target entity

  • metadata (Optional[dict]) –

    optional information about the relationship

Source code in wiseagents/graphdb/wise_agent_graph_db.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Relationship(BaseModel):
    """
    A relationship (edge) in a knowledge graph.

    Attributes:
        label (str): a description of the relationship
        source (Entity): the source entity
        target (Entity): the target entity
        metadata (Optional[dict]): optional information about the relationship
    """
    label: str
    source: Entity
    target: Entity
    metadata: Optional[dict] = Field(default_factory=dict)

Source

Bases: BaseModel

Information about a source from which entities and relationships have been derived from.

Attributes:
  • content (str) –

    the content of the source

  • id (str) –

    the optional id associated with the source

  • metadata (Optional[dict]) –

    optional information about the source

Source code in wiseagents/graphdb/wise_agent_graph_db.py
42
43
44
45
46
47
48
49
50
51
52
53
class Source(BaseModel):
    """
    Information about a source from which entities and relationships have been derived from.

    Attributes:
        content (str): the content of the source
        id (str): the optional id associated with the source
        metadata (Optional[dict]): optional information about the source
    """
    content: str
    id: Optional[str] = Field(default_factory=lambda: str(uuid.uuid4()))
    metadata: Optional[dict] = {}

WiseAgentGraphDB

Bases: WiseAgentsYAMLObject

Abstract class to define the interface for a WiseAgentGraphDB.

Source code in wiseagents/graphdb/wise_agent_graph_db.py
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class WiseAgentGraphDB(WiseAgentsYAMLObject):
    """Abstract class to define the interface for a WiseAgentGraphDB."""


    def __init__(self):
        enforce_no_abstract_class_instances(self.__class__, WiseAgentGraphDB)

    @abstractmethod
    def get_schema(self) -> str:
        """
        Get the schema of the graph DB.

        Returns:
            str: the schema of the graph DB
        """
        ...

    @abstractmethod
    def refresh_schema(self):
        """
        Refresh the schema of the graph DB.
        """
        ...

    @abstractmethod
    def query(self, query: str, params: Optional[dict] = None) -> Any:
        """
        Query the graph DB.


        Args:
            query (str): the query to execute
            params (dict): the optional parameters for the query

        Returns:
            Any: the result of the query
        """
        ...

    @abstractmethod
    def insert_entity(self, entity: Entity, source: Source):
        """
        Insert an entity into the graph DB.


        Args:
            entity (Entity): the entity to insert
            source (Source): information about the source from which the entity has been derived from
        """
        ...

    @abstractmethod
    def insert_relationship(self, relationship: Relationship, source: Source):
        """
        Insert a relationship into the graph DB.


        Args:
            relationship (Relationship): the relationship to insert
            source (Source): information about the source from which the relationship has been derived from
        """
        ...

    @abstractmethod
    def insert_graph_documents(self, graph_documents: List[GraphDocument]):
        """
        Insert a list of graph documents into the graph DB.


        Args:
            graph_documents (List[GraphDocuments]): the graph documents to insert
        """
        ...

get_schema() abstractmethod

Get the schema of the graph DB.

Returns:
  • str( str ) –

    the schema of the graph DB

Source code in wiseagents/graphdb/wise_agent_graph_db.py
77
78
79
80
81
82
83
84
85
@abstractmethod
def get_schema(self) -> str:
    """
    Get the schema of the graph DB.

    Returns:
        str: the schema of the graph DB
    """
    ...

insert_entity(entity, source) abstractmethod

Insert an entity into the graph DB.

Parameters:
  • entity (Entity) –

    the entity to insert

  • source (Source) –

    information about the source from which the entity has been derived from

Source code in wiseagents/graphdb/wise_agent_graph_db.py
109
110
111
112
113
114
115
116
117
118
119
@abstractmethod
def insert_entity(self, entity: Entity, source: Source):
    """
    Insert an entity into the graph DB.


    Args:
        entity (Entity): the entity to insert
        source (Source): information about the source from which the entity has been derived from
    """
    ...

insert_graph_documents(graph_documents) abstractmethod

Insert a list of graph documents into the graph DB.

Parameters:
  • graph_documents (List[GraphDocuments]) –

    the graph documents to insert

Source code in wiseagents/graphdb/wise_agent_graph_db.py
133
134
135
136
137
138
139
140
141
142
@abstractmethod
def insert_graph_documents(self, graph_documents: List[GraphDocument]):
    """
    Insert a list of graph documents into the graph DB.


    Args:
        graph_documents (List[GraphDocuments]): the graph documents to insert
    """
    ...

insert_relationship(relationship, source) abstractmethod

Insert a relationship into the graph DB.

Parameters:
  • relationship (Relationship) –

    the relationship to insert

  • source (Source) –

    information about the source from which the relationship has been derived from

Source code in wiseagents/graphdb/wise_agent_graph_db.py
121
122
123
124
125
126
127
128
129
130
131
@abstractmethod
def insert_relationship(self, relationship: Relationship, source: Source):
    """
    Insert a relationship into the graph DB.


    Args:
        relationship (Relationship): the relationship to insert
        source (Source): information about the source from which the relationship has been derived from
    """
    ...

query(query, params=None) abstractmethod

Query the graph DB.

Parameters:
  • query (str) –

    the query to execute

  • params (dict, default: None ) –

    the optional parameters for the query

Returns:
  • Any( Any ) –

    the result of the query

Source code in wiseagents/graphdb/wise_agent_graph_db.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
@abstractmethod
def query(self, query: str, params: Optional[dict] = None) -> Any:
    """
    Query the graph DB.


    Args:
        query (str): the query to execute
        params (dict): the optional parameters for the query

    Returns:
        Any: the result of the query
    """
    ...

refresh_schema() abstractmethod

Refresh the schema of the graph DB.

Source code in wiseagents/graphdb/wise_agent_graph_db.py
87
88
89
90
91
92
@abstractmethod
def refresh_schema(self):
    """
    Refresh the schema of the graph DB.
    """
    ...