From 66b40dfcd09f4a0d1e00dcecb40c867b6f7298fa Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:09:01 +0100 Subject: [PATCH] Prepare for the presentation, add info --- Demo_graph.ipynb | 380 +++++++++++++++++- cognitive_architecture/config.py | 2 +- .../databases/graph/get_graph_client.py | 27 ++ .../databases/graph/networkx/adapter.py | 2 +- .../modules/cognify/graph/__init__.py | 1 + .../cognify/graph/create_semantic_graph.py | 17 + 6 files changed, 412 insertions(+), 17 deletions(-) create mode 100644 cognitive_architecture/infrastructure/databases/graph/get_graph_client.py create mode 100644 cognitive_architecture/modules/cognify/graph/__init__.py create mode 100644 cognitive_architecture/modules/cognify/graph/create_semantic_graph.py diff --git a/Demo_graph.ipynb b/Demo_graph.ipynb index a3bb35221..3cdd4fd5b 100644 --- a/Demo_graph.ipynb +++ b/Demo_graph.ipynb @@ -351,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 27, "id": "f97f11f1-4490-49ea-b193-1f858e72893b", "metadata": {}, "outputs": [], @@ -586,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "f06edd84-c455-4034-a38b-3a7d2f746f42", "metadata": {}, "outputs": [ @@ -953,6 +953,366 @@ "Remember, the knowledge graph should be coherent and easily understandable,\n", " so maintaining consistency in entity references is crucial.\n", "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Narrative Structure`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Character Identification`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Emotional Trajectories`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Thematic Elements`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Cultural and Social Context`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Temporal Aspects`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Language and Style`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Interpersonal Dynamics`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Symbolism and Metaphors`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", + "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n", + "You are a top-tier algorithm\n", + "designed for extracting information in structured formats to build a knowledge graph.\n", + "- **Nodes** represent entities and concepts. They're akin to Wikipedia nodes.\n", + "- **Edges** represent relationships between concepts. They're akin to Wikipedia links.\n", + "- The aim is to achieve simplicity and clarity in the\n", + "knowledge graph, making it accessible for a vast audience.\n", + "YOU ARE ONLY EXTRACTING DATA FOR COGNITIVE LAYER `Intertextuality`\n", + "## 2. Labeling Nodes\n", + "- **Consistency**: Ensure you use basic or elementary types for node labels.\n", + " - For example, when you identify an entity representing a person,\n", + " always label it as **\"person\"**.\n", + " Avoid using more specific terms like \"mathematician\" or \"scientist\".\n", + " - Include event, entity, time, or action nodes to the category.\n", + " - Classify the memory type as episodic or semantic.\n", + "- **Node IDs**: Never utilize integers as node IDs.\n", + " Node IDs should be names or human-readable identifiers found in the text.\n", + "## 3. Handling Numerical Data and Dates\n", + "- Numerical data, like age or other related information,\n", + "should be incorporated as attributes or properties of the respective nodes.\n", + "- **No Separate Nodes for Dates/Numbers**:\n", + "Do not create separate nodes for dates or numerical values.\n", + " Always attach them as attributes or properties of nodes.\n", + "- **Property Format**: Properties must be in a key-value format.\n", + "- **Quotation Marks**: Never use escaped single or double quotes within property values.\n", + "- **Naming Convention**: Use camelCase for property keys, e.g., `birthDate`.\n", + "## 4. Coreference Resolution\n", + "- **Maintain Entity Consistency**:\n", + "When extracting entities, it's vital to ensure consistency.\n", + "If an entity, such as \"John Doe\", is mentioned multiple times\n", + "in the text but is referred to by different names or pronouns (e.g., \"Joe\", \"he\"),\n", + "always use the most complete identifier for that entity throughout the knowledge graph.\n", + " In this example, use \"John Doe\" as the entity ID.\n", + "Remember, the knowledge graph should be coherent and easily understandable,\n", + " so maintaining consistency in entity references is crucial.\n", + "## 5. Strict Compliance\n", "Adhere to the rules strictly. Non-compliance will result in termination\"\"\"\n" ] } @@ -984,21 +1344,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "4a19cc82-b892-47f3-99db-b70edccefda5", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "None\n" - ] - } - ], - "source": [ - "print(layer_1_graph)" - ] + "outputs": [], + "source": [] }, { "cell_type": "code", diff --git a/cognitive_architecture/config.py b/cognitive_architecture/config.py index 9e38813a9..0ca37d6d6 100644 --- a/cognitive_architecture/config.py +++ b/cognitive_architecture/config.py @@ -40,7 +40,7 @@ class Config: db_user: str = os.getenv("DB_USER", "cognee") db_password: str = os.getenv("DB_PASSWORD", "cognee") sqlalchemy_logging: bool = os.getenv("SQLALCHEMY_LOGGING", True) - graph_name = os.getenv("GRAPH_NAME", "cognee_graph.pkl") + graph_filename = os.getenv("GRAPH_NAME", "cognee_graph.pkl") # Model parameters model: str = "gpt-4-1106-preview" diff --git a/cognitive_architecture/infrastructure/databases/graph/get_graph_client.py b/cognitive_architecture/infrastructure/databases/graph/get_graph_client.py new file mode 100644 index 000000000..d6a4559a7 --- /dev/null +++ b/cognitive_architecture/infrastructure/databases/graph/get_graph_client.py @@ -0,0 +1,27 @@ +"""Factory function to get the appropriate graph client based on the graph type.""" +from typing import Type +from cognitive_architecture.config import Config +from .graph_db_interface import GraphDBInterface +from .networkx.adapter import NetworXAdapter +# Assuming Neo4jAdapter is defined somewhere +# from .neo4j.adapter import Neo4jAdapter +from enum import Enum, auto + + +config = Config() +config.load() + +class GraphDBType(Enum): + NETWORKX = auto() + NEO4J = auto() +def get_graph_client(graph_type: GraphDBType, graph_filename: str) -> Type[GraphDBInterface]: + """Factory function to get the appropriate graph client based on the graph type.""" + if graph_filename is not None: + config.graph_filename = graph_filename + if graph_type == GraphDBType.NETWORKX: + return NetworXAdapter(filename = config.graph_filename) # Adjust as needed for NetworkX adapter configuration + elif graph_type == GraphDBType.NEO4J: + # return Neo4jAdapter(config.neo4j_config) # Uncomment and adjust as needed for Neo4j adapter configuration + raise NotImplementedError("Neo4j adapter is not implemented yet.") + else: + raise ValueError("Unsupported graph database type.") \ No newline at end of file diff --git a/cognitive_architecture/infrastructure/databases/graph/networkx/adapter.py b/cognitive_architecture/infrastructure/databases/graph/networkx/adapter.py index 320c2cfc9..6b888ecc7 100644 --- a/cognitive_architecture/infrastructure/databases/graph/networkx/adapter.py +++ b/cognitive_architecture/infrastructure/databases/graph/networkx/adapter.py @@ -5,7 +5,7 @@ import networkx as nx from cognitive_architecture.infrastructure.databases.graph.graph_db_interface import GraphDBInterface import logging -class NetworXDB(GraphDBInterface): +class NetworXAdapter(GraphDBInterface): def __init__(self, filename="cognee_graph.pkl"): self.filename = filename self.graph = nx.MultiDiGraph() diff --git a/cognitive_architecture/modules/cognify/graph/__init__.py b/cognitive_architecture/modules/cognify/graph/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/cognitive_architecture/modules/cognify/graph/__init__.py @@ -0,0 +1 @@ + diff --git a/cognitive_architecture/modules/cognify/graph/create_semantic_graph.py b/cognitive_architecture/modules/cognify/graph/create_semantic_graph.py new file mode 100644 index 000000000..7317bbebc --- /dev/null +++ b/cognitive_architecture/modules/cognify/graph/create_semantic_graph.py @@ -0,0 +1,17 @@ +from cognitive_architecture.infrastructure.graph.get_graph_client import get_graph_client + + + + +def create_semantic_graph( + text_input: str, + filename: str, + context, + response_model: Type[BaseModel] +) -> KnowledgeGraph: + graph_type = GraphDBType.NEO4J + + # Call the get_graph_client function with the selected graph type + graph_client = get_graph_client(graph_type) + +GraphDBInterface \ No newline at end of file