🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: support dynacmic graph via neo4j (#1254)
Neil Johnsonff6d71903809
diff --git a/README.md b/README.mdindex c9ac0fab7..53148eb21 100644--- a/README.md+++ b/README.md@@ -335,6 +335,7 @@ Practical guides and tutorials for implementing specific functionalities in CAME|:---|:---|| **[Role-Playing Scraper for Report & Knowledge Graph Generation](https://docs.camel-ai.org/cookbooks/applications/roleplaying_scraper.html)** | Create role-playing agents for data scraping and reporting. || **[Create A Hackathon Judge Committee with Workforce](https://docs.camel-ai.org/cookbooks/multi_agent_society/workforce_judge_committee.html)** | Building a team of agents for collaborative judging. |+| **[Dynamic Knowledge Graph Role-Playing: Multi-Agent System with dynamic, temporally-aware knowledge graphs](https://docs.camel-ai.org/cookbooks/applications/dyamic_knowledge_graph.html)** | Builds dynamic, temporally-aware knowledge graphs for financial applications using a multi-agent system. It processes financial reports, news articles, and research papers to help traders analyze data, identify relationships, and uncover market insights. The system also utilizes diverse and optional element node deduplication techniques to ensure data integrity and optimize graph structure for financial decision-making. || **[Customer Service Discord Bot with Agentic RAG](https://docs.camel-ai.org/cookbooks/applications/customer_service_Discord_bot_using_SambaNova_with_agentic_RAG.html)** | Learn how to build a robust customer service bot for Discord using Agentic RAG. || **[Customer Service Discord Bot with Local Model](https://docs.camel-ai.org/cookbooks/applications/customer_service_Discord_bot_using_local_model_with_agentic_RAG.html)** | Learn how to build a robust customer service bot for Discord using Agentic RAG which supports local deployment. |diff --git a/camel/agents/knowledge_graph_agent.py b/camel/agents/knowledge_graph_agent.pyindex 075a60d0a..714eb3f43 100644--- a/camel/agents/knowledge_graph_agent.py+++ b/camel/agents/knowledge_graph_agent.py@@ -226,7 +226,8 @@ class KnowledgeGraphAgent(ChatAgent):node_pattern = r"Node\(id='(.*?)', type='(.*?)'\)"rel_pattern = (r"Relationship\(subj=Node\(id='(.*?)', type='(.*?)'\), "- r"obj=Node\(id='(.*?)', type='(.*?)'\), type='(.*?)'\)"+ r"obj=Node\(id='(.*?)', type='(.*?)'\), "+ r"type='(.*?)'(?:, timestamp='(.*?)')?\)")nodes = {}@@ -243,13 +244,24 @@ class KnowledgeGraphAgent(ChatAgent):# Extract relationshipsfor match in re.finditer(rel_pattern, input_string):- subj_id, subj_type, obj_id, obj_type, rel_type = match.groups()+ groups = match.groups()+ if len(groups) == 6:+ subj_id, subj_type, obj_id, obj_type, rel_type, timestamp = (+ groups+ )+ else:+ subj_id, subj_type, obj_id, obj_type, rel_type = groups+ timestamp = Noneproperties = {'source': 'agent_created'}if subj_id in nodes and obj_id in nodes:subj = nodes[subj_id]obj = nodes[obj_id]relationship = Relationship(- subj=subj, obj=obj, type=rel_type, properties=properties+ subj=subj,+ obj=obj,+ type=rel_type,+ timestamp=timestamp,+ properties=properties,)if self._validate_relationship(relationship):relationships.append(relationship)diff --git a/camel/storages/graph_storages/graph_element.py b/camel/storages/graph_storages/graph_element.pyindex 656f146c0..5fd5dc976 100644--- a/camel/storages/graph_storages/graph_element.py+++ b/camel/storages/graph_storages/graph_element.py@@ -13,7 +13,7 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========from __future__ import annotations-from typing import List, Union+from typing import List, Optional, Unionfrom pydantic import BaseModel, ConfigDict, Field@@ -45,6 +45,7 @@ class Relationship(BaseModel):subj (Node): The subject/source node of the relationship.obj (Node): The object/target node of the relationship.type (str): The type of the relationship.+ timestamp (str, optional): The timestamp of the relationship.properties (dict): Additional properties associated with therelationship."""@@ -52,6 +53,7 @@ class Relationship(BaseModel):subj: Nodeobj: Nodetype: str = "Relationship"+ timestamp: Optional[str] = Noneproperties: dict = Field(default_factory=dict)diff --git a/camel/storages/graph_storages/neo4j_graph.py b/camel/storages/graph_storages/neo4j_graph.pyindex 8ab6623d9..92fabc41a 100644--- a/camel/storages/graph_storages/neo4j_graph.py+++ b/camel/storages/graph_storages/neo4j_graph.py@@ -339,18 +339,24 @@ class Neo4jGraph(BaseGraphStorage):])- def add_triplet(self, subj: str, obj: str, rel: str) -> None:- r"""Adds a relationship (triplet) between two entities in the database.+ def add_triplet(+ self, subj: str, obj: str, rel: str, timestamp: Optional[str] = None+ ) -> None:+ r"""Adds a relationship (triplet) between two entities+ in the database with a timestamp.Args:subj (str): The identifier for the subject entity.obj (str): The identifier for the object entity.rel (str): The relationship between the subject and object.+ timestamp (Optional[str]): The timestamp of the relationship.+ Defaults to None."""query = """MERGE (n1:`%s` {id:$subj})MERGE (n2:`%s` {id:$obj})- MERGE (n1)-[:`%s`]->(n2)+ MERGE (n1)-[r:`%s`]->(n2)+ SET r.timestamp = $timestamp"""prepared_statement = query % (@@ -361,7 +367,10 @@ class Neo4jGraph(BaseGraphStorage):# Execute the query within a database sessionwith self.driver.session(database=self.database) as session:- session.run(prepared_statement, {"subj": subj, "obj": obj})+ session.run(+ prepared_statement,+ {"subj": subj, "obj": obj, "timestamp": timestamp},+ )def _delete_rel(self, subj: str, obj: str, rel: str) -> None:r"""Deletes a specific relationship between two nodes in the Neo4j@@ -721,3 +730,68 @@ class Neo4jGraph(BaseGraphStorage):return result[0] if result else {}except CypherSyntaxError as e:raise ValueError(f"Generated Cypher Statement is not valid\n{e}")++ def get_triplet(+ self,+ subj: Optional[str] = None,+ obj: Optional[str] = None,+ rel: Optional[str] = None,+ ) -> List[Dict[str, Any]]:+ r"""+ Query triplet information. If subj, obj, or rel is+ not specified, returns all matching triplets.++ Args:+ subj (Optional[str]): The ID of the subject node.+ If None, matches any subject node.+ obj (Optional[str]): The ID of the object node.+ If None, matches any object node.+ rel (Optional[str]): The type of relationship.+ If None, matches any relationship type.++ Returns:+ List[Dict[str, Any]]: A list of matching triplets,+ each containing subj, obj, rel, and timestamp.+ """+ import logging++ logging.basicConfig(level=logging.DEBUG)+ logger = logging.getLogger(__name__)++ # Construct the query+ query = """+ MATCH (n1:Entity)-[r]->(n2:Entity)+ WHERE ($subj IS NULL OR n1.id = $subj)+ AND ($obj IS NULL OR n2.id = $obj)+ AND ($rel IS NULL OR type(r) = $rel)+ RETURN n1.id AS subj, n2.id AS obj,+ type(r) AS rel, r.timestamp AS timestamp+ """++ # Construct the query parameters+ params = {+ "subj": subj+ if subj is not None+ else None, # If subj is None, match any subject node+ "obj": obj+ if obj is not None+ else None, # If obj is None, match any object node+ "rel": rel+ if rel is not None+ else None, # If rel is None, match any relationship type+ }++ logger.debug(f"Executing query: {query}")+ logger.debug(f"Query parameters: {params}")++ with self.driver.session(database=self.database) as session:+ try:+ result = session.run(query, params)+ records = [record.data() for record in result]+ logger.debug(+ f"Query returned {len(records)} records: {records}"+ )+ return records+ except Exception as e:+ logger.error(f"Error executing query: {e}")+ return []diff --git a/docs/cookbooks/advanced_features/agents_with_dkg.ipynb b/docs/cookbooks/advanced_features/agents_with_dkg.ipynbnew file mode 100644index 000000000..f4c103597--- /dev/null+++ b/docs/cookbooks/advanced_features/agents_with_dkg.ipynb@@ -0,0 +1,1235 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "iOezyLjg0IX2"+ },+ "source": [+ "# 📊 Dynamic Knowledge Graph Construction for Financial Report with CAMEL"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "uM1bYd4z0Mn2"+ },+ "source": [+ "You can also check this cookbook in colab [here](https://drive.google.com/file/d/19EWVOVZl_nVCs0ERr6IEaxiXHGPObYS9/view?usp=sharing)\n",+ "\n",+ "<div class=\"align-center\">\n",+ " <a href=\"https://www.camel-ai.org/\"><img src=\"https://i.postimg.cc/KzQ5rfBC/button.png\"width=\"150\"></a>\n",+ " <a href=\"https://discord.camel-ai.org\"><img src=\"https://i.postimg.cc/L4wPdG9N/join-2.png\" width=\"150\"></a></a>\n",+ " \n",+ "⭐ <i>Star us on [*Github*](https://github.com/camel-ai/camel), join our [*Discord*](https://discord.camel-ai.org) or follow our [*X*](https://x.com/camelaiorg)\n",+ "</div>"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ymsq1Lw0VEqT"+ },+ "source": [+ "\n",+ "\n",+ "\n",+ "This notebook demonstrates how to build a dynamic knowledge graph using CAMEL's Knowledge Graph Agent and Neo4j. The knowledge graph is constructed by parsing PDF documents, extracting entities and relationships, and storing them in a Neo4j database. The graph is then queried to retrieve time-based relationships.\n",+ "\n",+ "In this notebook, you'll explore:\n",+ "\n",+ "- **CAMEL**: A powerful multi-agent framework that enables the construction of knowledge graphs from unstructured data.\n",+ "- **Neo4j**: A graph database used to store and query the knowledge graph.\n",+ "- **Together and SambaVerse Models**: Large language models used to generate the knowledge graph from parsed documents.\n",+ "- **Deduplication**: Techniques to ensure the uniqueness of nodes and relationships in the graph.\n",+ "\n",+ "This setup not only demonstrates a practical application of AI-driven knowledge graph construction but also provides a flexible framework that can be adapted to other real-world scenarios requiring dynamic graph generation and querying."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "0J0_iW-YVcq2"+ },+ "source": [+ "## 📦 Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "7p-JjpyNVcCT"+ },+ "source": [+ "First, install the CAMEL package with all its dependencies:\n",+ "Second, make sure that Neo4j is running and accessible from your local machine."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "0GXs2pruU9Vl"+ },+ "outputs": [],+ "source": [+ "pip install \"camel-ai[rag]==0.2.22\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "oVqPOJp90pYu"+ },+ "source": [+ "## 🚀 Launch Service\n",+ "\n",+ "Start Neo4j service in the background((using Ubuntu as an example))"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "VIcwscUz1LdT"+ },+ "outputs": [],+ "source": [+ "neo4j start"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "lfNvFbhD6o8B"+ },+ "source": [+ "## 🔑 Setting Up API Keys"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "jqV12oQfQTyl"+ },+ "source": [+ "You'll need to set up your API keys for Together and SambaVerse. This ensures that the tools can interact with external services securely."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Y8CJmIVEyGok",+ "outputId": "96c2ce0f-0228-4eed-c8fb-1d9b07a9209c"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32m✅ Loading environment variables successfully.\u001b[39m\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "import dotenv\n",+ "import colorama\n",+ "from getpass import getpass\n",+ "\n",+ "dotenv.load_dotenv()\n",+ "\n",+ "# Prompt for the TogetherAI API key securely\n",+ "together_api_key = getpass('Enter Together API key: ')\n",+ "os.environ[\"TOGETHER_API_KEY\"] = together_api_key\n",+ "\n",+ "# Prompt for the SambanovaAI API key securely\n",+ "sambanova_api_key = getpass('Enter Sambanova API key: ')\n",+ "os.environ[\"SAMBA_API_KEY\"] = sambanova_api_key\n",+ "\n",+ "# Prompt for the OpenAI API key securely\n",+ "openai_api_key = getpass('Enter OpenAI API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key\n",+ "\n",+ "print(\n",+ " colorama.Fore.GREEN\n",+ " + \"✅ Loading environment variables successfully.\"\n",+ " + colorama.Fore.RESET\n",+ ")\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "czxWvnvnAimt"+ },+ "source": [+ "## 🛠️ Setting Up Neo4j"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "wlNTpfRUxzis"+ },+ "source": [+ "To store and query the knowledge graph, you'll need a Neo4j instance. If you don't have one, you can set up a local instance or use a cloud service like Neo4j Aura.\n",+ "\n",+ "1. **Local Setup**: Download and install Neo4j Desktop from [here](https://neo4j.com/download/).\n",+ "2. **Cloud Setup**: Sign up for Neo4j Aura [here](https://neo4j.com/cloud/aura/).\n",+ "\n",+ "Once you have your Neo4j instance running, set up the connection details:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "T0FBl1WF6jFs"+ },+ "outputs": [],+ "source": [+ "# Prompt for Neo4j securely\n",+ "os.environ[\"NEO4J_URI\"] = getpass('Enter NEO4J_URI: ')\n",+ "os.environ[\"NEO4J_USERNAME\"] = getpass('Enter NEO4J_USERNAME: ')\n",+ "os.environ[\"NEO4J_PASSWORD\"] = getpass('Enter NEO4J_PASSWORD: ')"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "lij5h45Yw6R1"+ },+ "source": [+ "## 🧠 Setting Up the Knowledge Graph Agent"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "2xM10-BCgPXf"+ },+ "source": [+ "We will use CAMEL's Knowledge Graph Agent to parse PDF documents, extract entities and relationships, and store them in the Neo4j database. The agent uses Together and SambaVerse models for graph generation.\n",+ "\n",+ "Replace the file path in the code below with your own data directory path\n",+ "example_file_dir = Path(\"/home/mi/daily/fin-camel/pdf_tmp\")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "H6q5xbQtajUj",+ "outputId": "bd835605-8cca-413a-b4fe-4243abe262c2"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Clearing Neo4j database...\n",+ "✅ Neo4j database cleared successfully.\n",+ "Found 4 PDF files.\n"+ ]+ }+ ],+ "source": [+ "from pathlib import Path\n",+ "\n",+ "from tqdm import tqdm\n",+ "\n",+ "from camel.agents import KnowledgeGraphAgent\n",+ "from camel.configs import TogetherAIConfig, SambaCloudAPIConfig, ChatGPTConfig\n",+ "from camel.embeddings import MistralEmbedding\n",+ "from camel.loaders import UnstructuredIO\n",+ "from camel.models import ModelFactory\n",+ "from camel.storages import Neo4jGraph\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "\n",+ "# Set up Neo4j connection\n",+ "neo4j_graph = Neo4jGraph(\n",+ " url=os.environ[\"NEO4J_URI\"],\n",+ " username=os.environ[\"NEO4J_USERNAME\"],\n",+ " password=os.environ[\"NEO4J_PASSWORD\"],\n",+ ")\n",+ "\n",+ "# Clear the Neo4j database before starting\n",+ "print(\"Clearing Neo4j database...\")\n",+ "neo4j_graph.query(\"MATCH (n) DETACH DELETE n\")\n",+ "print(\"✅ Neo4j database cleared successfully.\")\n",+ "\n",+ "# Use TogetherAI model\n",+ "together_api_model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.TOGETHER,\n",+ " model_type=ModelType.TOGETHER_LLAMA_3_1_70B,\n",+ " model_config_dict=TogetherAIConfig(temperature=0.2).as_dict(),\n",+ ")\n",+ "\n",+ "# Use Samba Verse model\n",+ "sambaverse_api_model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.SAMBA,\n",+ " model_type=\"Meta-Llama-3.1-405B-Instruct\",\n",+ " model_config_dict=SambaCloudAPIConfig(max_tokens=2048).as_dict(),\n",+ " api_key=os.environ[\"SAMBA_API_KEY\"],\n",+ " url=\"https://api.sambanova.ai/v1\",\n",+ ")\n",+ "\n",+ "# Use OpenAI model\n",+ "openai_model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")\n",+ "\n",+ "# Set up the example files\n",+ "example_file_dir = Path(\"/home/mi/daily/fin-camel/pdf_kvue\")\n",+ "assert (\n",+ " example_file_dir.exists()\n",+ "), \"Please set the correct path to the example pdf files.\"\n",+ "\n",+ "example_pdf_files = list(example_file_dir.glob(\"*.pdf\"))\n",+ "print(f\"Found {len(example_pdf_files)} PDF files.\")\n",+ "\n",+ "# UnstructuredIO is a tool to parse and chunk the documents.\n",+ "uio = UnstructuredIO()\n",+ "\n",+ "# Together is a model to generate the knowledge graph.\n",+ "together_kg_agent = KnowledgeGraphAgent(model=together_api_model)\n",+ "\n",+ "# Samba Verse model is a model to generate the knowledge graph.\n",+ "llama_405b_kg_agent = KnowledgeGraphAgent(model=sambaverse_api_model)\n",+ "\n",+ "# OpenAI model is a model to generate the knowledge graph.\n",+ "openai_kg_agent = KnowledgeGraphAgent(model=openai_model)\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "OPr97YkP8yir"+ },+ "source": [+ "## 🏗️ Building the Knowledge Graph"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "wJgsOxiuWCMr"+ },+ "source": [+ "The ID normalization process ensures compliant Neo4j identifiers by sanitizing input strings (replacing non-alphanumeric characters with underscores), ensuring no numeric prefixes, splitting/cleaning components, and applying SHA-1 hashing truncation to enforce a maximum 64-character limit while preserving uniqueness and readability."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "9vJ-BFT5WCMr"+ },+ "outputs": [],+ "source": [+ "import hashlib\n",+ "\n",+ "def normalize_name(name: str, max_length: int = 64) -> str:\n",+ " \"\"\"Normalize the label name to comply with Neo4j's naming rules\"\"\"\n",+ " # Remove special characters and replace spaces with underscores\n",+ " normalized = \"\".join(c if c.isalnum() else \"_\" for c in name)\n",+ " # Ensure it does not start with a digit\n",+ " if normalized[0].isdigit():\n",+ " normalized = \"id_\" + normalized\n",+ " # Remove extra underscores\n",+ " normalized = \"_\".join(filter(None, normalized.split(\"_\")))\n",+ "\n",+ " # If the VID is too long, use a hash function to generate a fixed-length VID\n",+ " if len(normalized) > max_length:\n",+ " # Use the SHA-1 hash function to generate a fixed-length VID\n",+ " hash_value = hashlib.sha1(normalized.encode()).hexdigest()\n",+ " # Truncate to max_length\n",+ " normalized = hash_value[:max_length]\n",+ "\n",+ " return normalized"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "RedCQ_TWWCMr"+ },+ "source": [+ "Prompt we use for dynamic knowledge graph generation, which has timestamp in element."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "j1I8BchdWCMr"+ },+ "outputs": [],+ "source": [+ "custom_prompt = \"\"\"\n",+ "You are tasked with extracting nodes and relationships from given content and structuring them into Node and Relationship objects. Here's the outline of what you need to do:\n",+ "\n",+ "Content Extraction: You should be able to process input content and identify entities mentioned within it.\n",+ "\n",+ "Entities can be any noun phrases or concepts that represent distinct entities in the context of the given content.\n",+ "\n",+ "Node Extraction: For each identified entity, you should create a Node object. Each Node object should have a unique identifier (id) and a type (type).\n",+ "\n",+ "Additional properties associated with the node can also be extracted and stored.\n",+ "\n",+ "Relationship Extraction: You should identify relationships between entities mentioned in the content. For each relationship, create a Relationship object.\n",+ "\n",+ "A Relationship object should have a subject (subj) and an object (obj) which are Node objects representing the entities involved in the relationship.\n",+ "\n",+ "Each relationship should also have a type (type), and additional properties if applicable.\n",+ "\n",+ "Timestamp Requirement: For each relationship, you must assign a timestamp that reflects the time the relationship was established or mentioned based on the context of the provided content.\n",+ "\n",+ "If the timestamp cannot be derived from the content, assign None instead. The timestamp format should be: YYYY-MM-DDTHH:MM:SS (e.g., \"2025-02-13T19:41:48\").\n",+ "\n",+ "Output Formatting: The extracted nodes and relationships should be formatted as instances of the provided Node and Relationship classes.\n",+ "\n",+ "Ensure that the extracted data adheres to the structure defined by the classes. Output the structured data in a format that can be easily validated against the provided code.\n",+ "\n",+ "Instructions for you:\n",+ "\n",+ "Read the provided content thoroughly.\n",+ "Identify distinct entities mentioned in the content and categorize them as nodes.\n",+ "Determine relationships between these entities and represent them as directed relationships, including a timestamp for each relationship (or None if not applicable).\n",+ "Provide the extracted nodes and relationships in the specified format below.\n",+ "Example for you:\n",+ "\n",+ "Example Content: \"John works at XYZ Corporation since 2020. He is a software engineer. The company is located in New York City.\"\n",+ "\n",+ "Expected Output:\n",+ "\n",+ "Nodes:\n",+ "\n",+ "Node(id='John', type='Person')\n",+ "Node(id='XYZ Corporation', type='Organization')\n",+ "Node(id='New York City', type='Location')\n",+ "Relationships:\n",+ "\n",+ "Relationships:\n",+ "\n",+ "Relationship(subj=Node(id='John', type='Person'), obj=Node(id='XYZ Corporation', type='Organization'), type='WorksAt', timestamp='2025-02-13T19:41:48')\n",+ "Relationship(subj=Node(id='John', type='Person'), obj=Node(id='New York City', type='Location'), type='ResidesIn', timestamp='2025-02-13T19:47:39')\n",+ "\n",+ "===== TASK ===== Please extract nodes and relationships from the given content and structure them into Node and Relationship objects.\n",+ "\n",+ "{task}\n",+ "\"\"\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "PUw1bZRcWCMs"+ },+ "source": [+ "Here we iterate over each PDF file in the example_pdf_files list. For each file, it parses the content and chunks the elements based on titles, ensuring that each chunk does not exceed 2048 characters.Within the first loop, we process each chunked element. We run it through the openai_kg_agent to generate graph elements. Then, we iterate over each node in the graph element to adjust its type and normalize its ID.After processing the nodes, we prepare a list of node IDs to be used for embedding. This list will be used in the next step for deduplication."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Fwut5QqDWCMs",+ "outputId": "74eecaa9-a34e-4d92-bb3c-ea63031853bb"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "100%|██████████| 7/7 [01:27<00:00, 12.55s/it]\n",+ "100%|██████████| 398/398 [1:09:14<00:00, 10.44s/it]\n",+ "100%|██████████| 183/183 [31:56<00:00, 10.47s/it]\n",+ "100%|██████████| 7/7 [00:56<00:00, 8.05s/it]\n"+ ]+ }+ ],+ "source": [+ "from tqdm import tqdm\n",+ "\n",+ "node_texts = []\n",+ "graph_element_list = []\n",+ "for file in example_pdf_files:\n",+ " elements = uio.parse_file_or_url(str(file))\n",+ " chunk_elements = uio.chunk_elements(\n",+ " elements, chunk_type=\"chunk_by_title\", max_characters=2048\n",+ " )\n",+ "\n",+ " for element in tqdm(chunk_elements):\n",+ " graph_element = openai_kg_agent.run(\n",+ " element, parse_graph_elements=True, prompt=custom_prompt\n",+ " )\n",+ "\n",+ " # Add processing logic to rename 'Date' type\n",+ " for node in graph_element.nodes:\n",+ " if node.type == \"Date\":\n",+ " node.type = \"TimePoint\" # or another name that is not a reserved keyword\n",+ " elif node.type == \"{self.type}\":\n",+ " node.type = \"Node\" # Set default type\n",+ " node.id = normalize_name(\n",+ " node.id, max_length=64\n",+ " ) # Ensure VID length does not exceed 64\n",+ "\n",+ " # Prepare texts for embedding\n",+ " node_texts.extend([node.id for node in graph_element.nodes])\n",+ " graph_element_list.append(graph_element)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "jh2uWgw2WCMs"+ },+ "source": [+ "Perform internal deduplication on the node texts using the deduplicate_internally function. We set a threshold of 0.65 and specify the embedding strategy as \"top1\". The result provides unique IDs of the nodes."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ENfY2uoV8xh4"+ },+ "outputs": [],+ "source": [+ "from camel.utils import deduplicate_internally\n",+ "from camel.embeddings import SentenceTransformerEncoder\n",+ "\n",+ "# Perform internal deduplication\n",+ "sentence_encoder = SentenceTransformerEncoder(model_name='intfloat/e5-large-v2')\n",+ "deduplication_result = deduplicate_internally(\n",+ " texts=node_texts,\n",+ " threshold=0.65,\n",+ " embedding_instance=sentence_encoder,\n",+ " strategy=\"top1\",\n",+ " batch_size=10, # Adjust batch size as needed\n",+ ")\n",+ "\n",+ "# Get unique nodes\n",+ "unique_node_ids = {node_texts[i] for i in deduplication_result.unique_ids}"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "sSvHORUoWCMs"+ },+ "source": [+ "Filter relationships to include only those where both the subject and object nodes are unique, as determined by the deduplication step."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "mNgdL2MwWCMt"+ },+ "outputs": [],+ "source": [+ "unique_relationships = []\n",+ "for graph_unit in graph_element_list:\n",+ " for rel in graph_unit.relationships:\n",+ " if (\n",+ " rel.subj.id in unique_node_ids\n",+ " and rel.obj.id in unique_node_ids\n",+ " ):\n",+ " unique_relationships.append(rel)"+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "After running the program above, access results by navigating to https://console-preview.neo4j.io/tools/query in your web browser. Sign in using your Neo4j credentials (as specified in the configuration file), and you'll see the **knowledge graph with timestamps** displayed as shown below.\n",+ "\n",+ "\n",+ "\n"+ ],+ "metadata": {+ "id": "je7sLuwYqVxC"+ }+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "y1gPJRSOWCMt"+ },+ "source": [+ "Add the unique relationships to a Neo4j graph. For each relationship, we generate a timestamp and add the triplet to the graph."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Op_GleDUWCMt"+ },+ "outputs": [],+ "source": [+ "import time\n",+ "\n",+ "for rel in unique_relationships:\n",+ " current_time = time.strftime(\"%Y-%m-%dT%H:%M:%S\", time.localtime())\n",+ " timestamp = rel.timestamp if rel.timestamp is not None else current_time\n",+ " neo4j_graph.add_triplet(\n",+ " subj=rel.subj.id,\n",+ " obj=rel.obj.id,\n",+ " rel=rel.type,\n",+ " timestamp=timestamp,\n",+ " )"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Qub28k5cOLIJ"+ },+ "source": [+ "## 🔍 Querying the Knowledge Graph"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "oFZTLplLtB8R"+ },+ "source": [+ "Now that the knowledge graph is built, we can query it to retrieve time-based relationships."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ZeskKVDPtB8R",+ "outputId": "e096e184-2c06-4b62-d8ac-d14305597633"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: PARTOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: SEPARATION, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: INCORPORATEDASSUBSIDIARYOF, Timestamp: 2022-02-01T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Johnson_Johnson, Relationship: NETINVESTMENTFROM, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: SEPARATEDFROM, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Mr_Wolk, Object: Johnson_Johnson, Relationship: SERVESASCFO, Timestamp: 2018-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: OWNEDBY, Timestamp: 2024-01-24T00:00:00\n",+ "Subject: Kenvue, Object: Johnson_Johnson, Relationship: SPINOFFFROM, Timestamp: 2023-11-12T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue_Inc, Relationship: SPLITOFF, Timestamp: 2023-05-04T00:00:00\n",+ "Subject: PricewaterhouseCoopers_LLP, Object: Kenvue_Inc, Relationship: AUDITOROF, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue_Inc, Relationship: ENTEREDINTOAGREEMENT, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Kenvue_Inc, Relationship: SIGNEDBY, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Paul_Ruh, Object: Kenvue_Inc, Relationship: SIGNEDBY, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Seemantini_Godbole, Object: Kenvue_Inc, Relationship: SIGNEDBY, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Melanie_L_Healey, Object: Kenvue_Inc, Relationship: SIGNEDBY, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Betsy_D_Holden, Object: Kenvue_Inc, Relationship: SIGNEDBY, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue_Inc, Relationship: COMPLETEDSPLITOFF, Timestamp: 2023-05-04T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue_Inc, Relationship: OWNERSHIPSTAKE, Timestamp: 2023-07-24T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: PARENTCOMPANY, Timestamp: 2022-02-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: COMPLETEDTRANSFER, Timestamp: 2023-04-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: EXCHANGEOFFER, Timestamp: 2023-07-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: COMPLETEDEXCHANGE, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: COMPLETEDTRANSFEROFASSETS, Timestamp: 2023-04-01T00:00:00\n",+ "Subject: Founder_Shares, Object: Kenvue, Relationship: GRANTEDON, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Company, Object: Kenvue, Relationship: ESTABLISHEDAS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: INCURREDCOSTSFOR, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: REPLACEDBY, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Company, Object: Kenvue, Relationship: APPROVEDBY, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Compensation_Human_Capital_Committee, Object: Kenvue, Relationship: GRANTS, Timestamp: 2023-08-25T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Kenvue, Relationship: SEPARATIONCOMPLETED, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Jan_Meurer, Object: Kenvue, Relationship: MEMBEROFLEADERSHIP, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: NEOs, Object: Kenvue, Relationship: PLAYEDROLEIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: NEOs, Object: Kenvue, Relationship: RECEIVEDINCENTIVEAWARDS, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: APPROVEDCONVERSION, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Mr_Lawson, Object: Kenvue, Relationship: RECEIVESBENEFITS, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: TAXFREEDISPOSITION, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: TRANSFERREDINTELLECTUALPROPERTY, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: PROVIDES, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: CREDITS, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: Kenvue, Relationship: ESTABLISHEDIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Kenvue, Relationship: DIRECTORSINCE, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Seemantini_Godbole, Object: Kenvue, Relationship: DIRECTORSINCE, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Ms_Healey, Object: Kenvue, Relationship: SERVESASDIRECTOR, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Mr_Wolk, Object: Kenvue, Relationship: SERVESASDIRECTOR, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Mr_Lawson, Object: Kenvue, Relationship: RECEIVEDINCENTIVE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Ms_Xie, Object: Kenvue, Relationship: RECEIVEDINCENTIVE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Paul_Ruh, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Melanie_L_Healey, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Betsy_D_Holden, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Joseph_J_Wolk, Object: Kenvue, Relationship: BENEFICIALOWNER, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: SEPARATION, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Paul_Ruh, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Luani_Alvarado, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Charmaine_England, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Jan_Meurer, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Matthew_Orlando, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Kenvue, Relationship: SERVESAS, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Paul_Ruh, Object: Kenvue, Relationship: MEMBEROF, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Matthew_Orlando, Object: Kenvue, Relationship: MEMBEROF, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: J_J, Object: Kenvue, Relationship: ENTEREDINTOAGREEMENT, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Founder_Shares, Object: Kenvue, Relationship: GRANTEDTO, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Kenvue, Object: id_2024, Relationship: VALUATIONYEAR, Timestamp: 2024-11-08T00:00:00\n",+ "Subject: Engagement_Awards, Object: id_2024, Relationship: EARNEDIN, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2024, Relationship: CONDUCTSASSESSMENTIN, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: BECAMEINDEPENDENT, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: DEBUTYEAR, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: GENERATEDSALESIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: id_2023, Relationship: REPORTSFORYEAR, Timestamp: 2023-01-02T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: ESTABLISHEDIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: PERFORMANCEYEAR, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: id_2023, Relationship: DETERMINEDINCENTIVEDESIGN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: id_2023, Relationship: APPROVEDPERFORMANCEACHIEVEMENTLEVEL, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: INCURSCOSTS, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_2023, Relationship: PROJECTSREVENUEGROWTH, Timestamp: 2023-11-12T00:00:00\n",+ "Subject: Kenvue, Object: North_America, Relationship: OPERATESIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Asia_Pacific, Relationship: OPERATESIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Middle_East, Relationship: OPERATESIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Latin_America, Relationship: OPERATESIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Latin_America, Relationship: RESPONSIBLEFOR, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Consumer_Health_Business, Relationship: OWNS, Timestamp: 2021-11-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Consumer_Health_Business, Relationship: INTENDSTOSEPARATE, Timestamp: 2021-11-01T00:00:00\n",+ "Subject: J_J, Object: Consumer_Health_Business, Relationship: TRANSFER, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: Company, Object: Consumer_Health_Business, Relationship: HASSEGMENT, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: J_J, Object: Consumer_Health_Business, Relationship: ANNOUNCEDSEPARATION, Timestamp: 2021-11-12T00:00:00\n",+ "Subject: Kenvue, Object: Delaware, Relationship: INCORPORATEDIN, Timestamp: 2022-02-23T00:00:00\n",+ "Subject: Kenvue, Object: KVUE, Relationship: HASTICKERSYMBOL, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Kenvue, Object: KVUE, Relationship: TICKERSYMBOLFOR, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Kenvue, Object: Diversity_Equity_and_Inclusion, Relationship: COMMITSTO, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Over_the_Counter_Monograph_Safety_Innovation_and_Reform_Act, Object: FDA, Relationship: ENACTEDBY, Timestamp: 2020-03-01T00:00:00\n",+ "Subject: Nonprescription_Drugs_Advisory_Committee, Object: FDA, Relationship: ADVISES, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Johnson_Johnson_Consumer_Inc, Relationship: ENTEREDINTOAGREEMENT, Timestamp: 2023-04-03T00:00:00\n",+ "Subject: Johnson_Johnson_Consumer_Inc, Object: Neutrogena, Relationship: RECALLS, Timestamp: 2021-07-01T00:00:00\n",+ "Subject: Johnson_Johnson_Consumer_Inc, Object: Aveeno, Relationship: RECALLS, Timestamp: 2021-07-01T00:00:00\n",+ "Subject: FDA, Object: Company, Relationship: CONSIDERSINPUTFROM, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: J_J, Object: Company, Relationship: TRANSFERREDEQUITYINTERESTSTO, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: December_31_2023, Object: Company, Relationship: FISCALPERIODEND, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: January_1_2023, Object: Company, Relationship: FISCALPERIODEND, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: January_2_2022, Object: Company, Relationship: FISCALPERIODEND, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Management, Object: Company, Relationship: BELIEVES, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: J_J, Object: Company, Relationship: REPAIDLOAN, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: North_America, Object: Company, Relationship: NETSALESATTRIBUTION, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Asia_Pacific, Object: Company, Relationship: NETSALESATTRIBUTION, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Latin_America, Object: Company, Relationship: NETSALESATTRIBUTION, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Proxy_Statement, Object: Company, Relationship: DESCRIBES, Timestamp: 2024-01-01T00:00:00\n",+ "Subject: Self_Care, Object: Company, Relationship: PARTOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Skin_Health_and_Beauty, Object: Company, Relationship: PARTOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Essential_Health, Object: Company, Relationship: PARTOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Twelve_Months_Ended_December_31_2023, Object: Company, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Fiscal_Twelve_Months_Ended_January_1_2023, Object: Company, Relationship: REPORTS, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Twelve_Months_Ended_January_2_2022, Object: Company, Relationship: REPORTS, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: U_S_District_Court_for_the_District_of_New_Jersey, Relationship: DEFENDSAGAINST, Timestamp: 2023-10-01T00:00:00\n",+ "Subject: Company, Object: U_S_District_Court_for_the_District_of_New_Jersey, Relationship: INVOLVEDINLITIGATION, Timestamp: 2023-10-01T00:00:00\n",+ "Subject: Company, Object: Canada, Relationship: OPERATESIN, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: Company, Object: Canada, Relationship: INVOLVEDINLITIGATION, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: J_J, Object: Canada, Relationship: DISCONTINUEDIN, Timestamp: 2020-01-01T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: PARTOF, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: PARTOF, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Consumer_Health_Business, Object: J_J, Relationship: NOLONGERPARTICIPATESIN, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: Consumer_Health_Business_Transfer, Object: J_J, Relationship: DISTRIBUTESTO, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: IPOCOMPLETED, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: OPERATEDASSEGMENTOF, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: ENTEREDINTOAGREEMENT, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: ENTEREDINTO, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: PARTICIPATEDIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: LOANEDFUNDSTHROUGH, Timestamp: 2023-04-05T00:00:00\n",+ "Subject: Company, Object: J_J, Relationship: LENDS, Timestamp: 2023-04-05T00:00:00\n",+ "Subject: lease_liabilities, Object: J_J, Relationship: RELATEDTO, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Tax_Matters_Agreement, Object: J_J, Relationship: GOVERNS, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: BECAMEINDEPENDENTFROM, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: CEASEDRELATIONSHIPWITH, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: SEPARATIONFROM, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: The_Company, Object: J_J, Relationship: SEPARATIONFROM, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Shareholder_Engagement, Object: J_J, Relationship: SEPARATIONFROM, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: SEPARATEDFROM, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Board, Object: J_J, Relationship: SEPARATEDFROM, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: NEOs, Object: J_J, Relationship: RECEIVEDINCENTIVEAWARDS, Timestamp: 2023-02-01T00:00:00\n",+ "Subject: Kenvue, Object: J_J, Relationship: ENTERSINTOAGREEMENT, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: United_States, Relationship: DISCONTINUEDIN, Timestamp: 2020-01-01T00:00:00\n",+ "Subject: Russia_Ukraine_War, Object: Foreign_currency_volatility, Relationship: CAUSES, Timestamp: 2022-01-01T00:00:00\n",+ "Subject: Kenvue, Object: id_1_914_581_851, Relationship: HASSHARESOUTSTANDING, Timestamp: 2024-02-23T00:00:00\n",+ "Subject: Kenvue, Object: February_14_2024, Relationship: RECORDDATEFORNEXTDIVIDEND, Timestamp: 2024-02-14T00:00:00\n",+ "Subject: Kenvue_Inc, Object: December_31_2023, Relationship: STOCKTRADINGEND, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Net_Sales, Object: December_31_2023, Relationship: REPORTEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Cost_of_Sales, Object: December_31_2023, Relationship: REPORTEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Self_Care_Segment, Object: December_31_2023, Relationship: REPORTEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Stock_based_Compensation_Expense, Object: December_31_2023, Relationship: REPORTEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Self_Care_Segment, Object: December_31_2023, Relationship: FISCALPERIODENDED, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: FISCALENDDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Essential_Health_Segment, Object: December_31_2023, Relationship: FISCALENDDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Cash_and_Cash_Equivalents, Object: December_31_2023, Relationship: ASOF, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue_Inc, Object: December_31_2023, Relationship: FINANCIALSTATEMENTDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: KENVUE_INC, Object: December_31_2023, Relationship: FINANCIALSTATEMENTDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: CHANGEEFFECTIVEDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: ACCOUNTSPAYABLEBALANCE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: HASOUTSTANDINGBALANCES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: REPORTSON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: REPORTSFORDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Stock_Options, Object: December_31_2023, Relationship: UNRECOGNIZEDEXPENSEREPORTEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: id_2023, Object: December_31_2023, Relationship: ENDSFISCALYEAR, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: January_2_2022, Object: December_31_2023, Relationship: FISCALPERIODEND, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: December_31_2023, Relationship: ENDEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: REPORTEDBALANCESHEETASOF, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: December_31_2023, Relationship: FINANCIALREPORTINGDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: DETERMINEDASOF, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: December_31_2023, Relationship: FINANCIALREPORTINGPERIOD, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue_2023_Plan, Object: December_31_2023, Relationship: ESTABLISHEDON, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: NEOs, Object: December_31_2023, Relationship: TERMINATIONEFFECTIVEASOF, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: Separation, Relationship: COMPLETEDSEPARATION, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Kenvue, Object: Separation, Relationship: FOCUSAREA, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: Summit_New_Jersey, Relationship: HEADQUARTERSLOCATION, Timestamp: 2023-04-20T00:00:00\n",+ "Subject: Company, Object: Summit_New_Jersey, Relationship: HASLEASEIN, Timestamp: 2023-04-20T00:00:00\n",+ "Subject: Net_Income, Object: Fiscal_Year_2023, Relationship: REPORTEDIN, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Deferred_Income_Taxes, Object: Fiscal_Year_2023, Relationship: REPORTEDIN, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Fiscal_Year_2023, Relationship: ADOPTSSTANDARDASOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Fiscal_Year_2023, Relationship: REPORTSON, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Net_Sales, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: Net_Sales, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: Net_Sales, Relationship: REPRESENTS, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Fiscal_Twelve_Months_Ended_December_31_2023, Relationship: RESULTSFOR, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Fiscal_Twelve_Months_Ended_January_1_2023, Relationship: RESULTSFOR, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Twelve_Months_Ended_December_31_2023, Object: Other_operating_income_net, Relationship: REPORTEDMETRIC, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Net_Sales, Object: January_1_2023, Relationship: REPORTEDON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Cost_of_Sales, Object: January_1_2023, Relationship: REPORTEDON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Self_Care_Segment, Object: January_1_2023, Relationship: REPORTEDON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Stock_based_Compensation_Expense, Object: January_1_2023, Relationship: REPORTEDON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: FISCALSTARTDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Essential_Health_Segment, Object: January_1_2023, Relationship: FISCALSTARTDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Twelve_Months, Object: January_1_2023, Relationship: ENDSON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_Inc, Object: January_1_2023, Relationship: FINANCIALSTATEMENTDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: KENVUE_INC, Object: January_1_2023, Relationship: FINANCIALSTATEMENTDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: January_1_2023, Relationship: INCLUDEDIN, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: PRIORCHANGEDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: ACCOUNTSPAYABLEBALANCE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: REPORTSON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: REPORTSFORDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: id_2023, Object: January_1_2023, Relationship: ENDSFISCALYEAR, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: January_2_2022, Object: January_1_2023, Relationship: FISCALPERIODEND, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: January_1_2023, Relationship: REPORTEDBALANCESHEETASOF, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Cost_of_Sales, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Fiscal_Twelve_Months_Ended_January_1_2023, Object: Fiscal_Twelve_Months_Ended_January_2_2022, Relationship: COMPAREDWITH, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: Founder_Shares, Relationship: APPROVEDON, Timestamp: 2023-08-25T00:00:00\n",+ "Subject: Compensation_Human_Capital_Committee, Object: Founder_Shares, Relationship: APPROVED, Timestamp: 2023-08-25T00:00:00\n",+ "Subject: Kenvue, Object: Founder_Shares, Relationship: GRANTEDTO, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: P_Ruh, Object: Founder_Shares, Relationship: GRANTED, Timestamp: 2023-10-01T00:00:00\n",+ "Subject: M_Stevens, Object: Founder_Shares, Relationship: GRANTED, Timestamp: 2023-10-01T00:00:00\n",+ "Subject: J_J, Object: Cash_and_Cash_Equivalents, Relationship: RECEIVESDISTRIBUTION, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Kenvue, Object: U_S_Federal_consolidated_income_tax_return, Relationship: FILES, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Company, Object: U_S_Federal_consolidated_income_tax_return, Relationship: FILES, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Company, Object: GILTI, Relationship: CHANGEDACCOUNTINGPRINCIPLE, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: GILTI, Relationship: CHANGEDACCOUNTINGMETHOD, Timestamp: 2023-07-01T00:00:00\n",+ "Subject: J_J, Object: GILTI, Relationship: ELECTEDDEFERREDEFFECTS, Timestamp: 2018-01-01T00:00:00\n",+ "Subject: Company, Object: Self_Care, Relationship: HASSEGMENT, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Self_Care, Relationship: PERFORMSTESTON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Skin_Health_and_Beauty, Relationship: HASSEGMENT, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Skin_Health_and_Beauty, Relationship: PERFORMSTESTON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Essential_Health, Relationship: HASSEGMENT, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Company, Object: Essential_Health, Relationship: PERFORMSTESTON, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: Essential_Health, Relationship: INCLUDES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Net_Income, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Stock_based_Compensation_Expense, Object: January_2_2022, Relationship: REPORTEDON, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: KENVUE_INC, Object: January_2_2022, Relationship: FINANCIALSTATEMENTDATE, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: January_2_2022, Relationship: INCLUDEDIN, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: January_2_2022, Relationship: PRIORCHANGEDATE, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: January_2_2022, Relationship: PREVIOUSFISCALDATE, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: PSUs, Object: January_2_2022, Relationship: UNRECOGNIZEDEXPENSEREPORTEDON, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: id_2022, Object: January_2_2022, Relationship: ENDSFISCALYEAR, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Company, Object: January_2_2022, Relationship: REPORTEDBALANCESHEETASOF, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Kenvue, Object: id_13_8_billion, Relationship: DISTRIBUTIONTO, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: J_J, Object: Consolidated_Financial_Statements, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Consolidated_Financial_Statements, Relationship: DERIVEDFROM, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: J_J, Object: Consolidated_Financial_Statements, Relationship: INCLUDEDIN, Timestamp: 2023-04-04T00:00:00\n",+ "Subject: Company, Object: Consolidated_Financial_Statements, Relationship: IMPACTEDBYCHANGE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Audit_Committee, Object: Consolidated_Financial_Statements, Relationship: REVIEWS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Consolidated_Balance_Sheets, Relationship: REPORTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: lease_liabilities, Object: Consolidated_Balance_Sheets, Relationship: INCLUDEDIN, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Consolidated_Balance_Sheets, Relationship: RECOGNIZEDRECEIVABLE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Consolidated_Balance_Sheets, Relationship: RECOGNIZEDPAYABLE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Assets, Relationship: TOTALASSETS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: January_2_2022, Object: id_348_million, Relationship: AMORTIZATIONEXPENSE, Timestamp: 2022-01-02T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Tax_Matters_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Tax_Matters_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Tax_Matters_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Tax_Matters_Agreement, Relationship: GOVERNS, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Kenvue_2023_Plan, Relationship: HASPLAN, Timestamp: 2023-08-23T00:00:00\n",+ "Subject: Company, Object: Kenvue_2023_Plan, Relationship: APPROVED, Timestamp: 2023-03-01T00:00:00\n",+ "Subject: J_J, Object: Kenvue_2023_Plan, Relationship: APPROVED, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: January_1_2023, Object: Kenvue_2023_Plan, Relationship: STARTDATE, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: December_31_2023, Object: Kenvue_2023_Plan, Relationship: ENDDATE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: Stock_based_compensation_expense, Relationship: RECOGNIZEDEXPENSE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: J_J, Object: Stock_based_compensation_expense, Relationship: REVERSEDEXPENSE, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: PSUs, Relationship: RECOGNIZEDCOMPENSATIONCOSTS, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: PSUs, Relationship: GRANTEDTO, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Board, Object: Compensation_Human_Capital_Committee, Relationship: EVALUATES, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Kenvue, Object: Stock_Options, Relationship: GRANTEDTO, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Stock_Options, Relationship: GRANTED, Timestamp: 2022-02-14T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Stock_Options, Relationship: RECEIVED, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Paul_Ruh, Object: Stock_Options, Relationship: RECEIVED, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Stock_Options, Relationship: RECEIVED, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Stock_Options, Relationship: RECEIVES, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Stock_Options, Relationship: RECEIVES, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Stock_Options, Relationship: RECEIVES, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Stock_Options, Relationship: HAS, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: id_2022, Relationship: APPROVEDENGAGEMENTAWARDS, Timestamp: 2022-01-01T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Employee_Matters_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Employee_Matters_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Employee_Matters_Agreement, Relationship: ADDRESSES, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Intellectual_Property_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Intellectual_Property_Agreement, Relationship: GOVERNS, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: J_J, Object: Transition_Services_Agreement, Relationship: PROVIDESSERVICES, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Transition_Services_Agreement, Relationship: ENTERSINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Company, Object: Kenvue_IPO, Relationship: COMPLETED, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Company, Object: Kenvue_IPO, Relationship: CLAIMEDBENEFITSUNTIL, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: The_Company, Object: Kenvue_IPO, Relationship: SEPARATIONFROM, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Foreign_Tax_Credits, Relationship: UTILIZES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: May_8_2023, Relationship: IPOCOMPLETEDON, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Company, Object: Trade_Receivables, Relationship: INCLUDES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: Cash_Flow_Hedge_Portfolio, Relationship: RECORDSCHANGEIN, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Company, Object: id_30_year_Bonds, Relationship: ISSUED, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: Cough_Cold_and_Allergy, Relationship: INCLUDES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Fiscal_Year_2023, Object: Women_s_Health, Relationship: INCLUDES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue_Inc, Object: SEC, Relationship: FILEDWITH, Timestamp: 2023-03-30T00:00:00\n",+ "Subject: Kenvue, Object: SEC, Relationship: FILEDWITH, Timestamp: 2024-03-01T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Deutsche_Bank_Trust_Company_Americas, Relationship: TRUSTEEOF, Timestamp: 2023-03-22T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Executive_Severance_Pay_Plan, Relationship: FILEDAS, Timestamp: 2023-11-03T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Exhibit_10_7, Relationship: FILEDAS, Timestamp: 2023-11-03T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Exhibit_10_7, Relationship: FILEDASEXHIBIT, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Exhibit_10_8, Relationship: FILEDAS, Timestamp: 2023-11-03T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Exhibit_10_8, Relationship: FILEDASEXHIBIT, Timestamp: 2023-05-08T00:00:00\n",+ "Subject: Kenvue_Inc, Object: Exhibit_10_18, Relationship: FILEDAS, Timestamp: 2023-11-03T00:00:00\n",+ "Subject: Johnson_Johnson, Object: Separation_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Kenvue, Object: Separation_Agreement, Relationship: CONTAINSPROVISIONS, Timestamp: 2023-05-03T00:00:00\n",+ "Subject: Employment_Agreement, Object: Carlton_Lawson, Relationship: BETWEEN, Timestamp: 2022-06-22T00:00:00\n",+ "Subject: Shareholder_Engagement, Object: Board, Relationship: OVERSIGHT, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Board, Object: Nominating_Governance_Sustainability_Committee, Relationship: CONDUCTS, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Board, Object: Board_Culture_Charter, Relationship: ADOPTS, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Board, Object: Audit_Committee, Relationship: EVALUATES, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Board, Object: Executive_Committee, Relationship: EVALUATES, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Shareholder_Engagement, Object: Institutional_Holders, Relationship: OUTREACHTO, Timestamp: 2023-08-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: NEOs, Relationship: EVALUATEDCOMPENSATION, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: J_J, Object: NEOs, Relationship: SETCOMPENSATION, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: NEOs, Relationship: ESTABLISHEDBASESALARIES, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Kenvue, Object: NEOs, Relationship: COMPENSATES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: February_2023, Relationship: GRANTEDLONGTERMINCENTIVEAWARDS, Timestamp: 2023-02-01T00:00:00\n",+ "Subject: Kenvue_CHCC, Object: December_2023, Relationship: APPROVEDLONGTERMINCENTIVEGRANT, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: Kenvue, Object: P_Ruh, Relationship: RECEIVEDGRANT, Timestamp: 2023-12-01T00:00:00\n",+ "Subject: P_Ruh, Object: Engagement_Awards, Relationship: RECEIVED, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: M_Stevens, Object: Engagement_Awards, Relationship: RECEIVED, Timestamp: 2023-09-01T00:00:00\n",+ "Subject: PSUs, Object: Organic_Net_Sales, Relationship: PERFORMANCEMEASURE, Timestamp: 2026-12-31T00:00:00\n",+ "Subject: Mr_Lawson, Object: Switzerland, Relationship: RELOCATEDTO, Timestamp: 2023-01-01T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Annual_Incentive, Relationship: RECEIVED, Timestamp: 2023-02-13T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Founder_PSUs, Relationship: GRANTED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Founder_PSUs, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Paul_Ruh, Object: Founder_PSUs, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Founder_PSUs, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Founder_PSUs, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Founder_PSUs, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Founder_PSUs, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Founder_Stock_Options, Relationship: GRANTED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Founder_Stock_Options, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Paul_Ruh, Object: Founder_Stock_Options, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Founder_Stock_Options, Relationship: RECEIVED, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Founder_Stock_Options, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Founder_Stock_Options, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Founder_Stock_Options, Relationship: RECEIVES, Timestamp: 2023-10-02T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Dec_2023_PSUs, Relationship: GRANTED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Dec_2023_PSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Paul_Ruh, Object: Dec_2023_PSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Dec_2023_PSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Dec_2023_PSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Dec_2023_PSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Dec_2023_PSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Dec_2023_RSUs, Relationship: GRANTED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Dec_2023_RSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Paul_Ruh, Object: Dec_2023_RSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Dec_2023_RSUs, Relationship: RECEIVED, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Carlton_Lawson, Object: Dec_2023_RSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Meredith_Stevens, Object: Dec_2023_RSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Ellie_Bing_Xie, Object: Dec_2023_RSUs, Relationship: RECEIVES, Timestamp: 2023-12-07T00:00:00\n",+ "Subject: Thibaut_Mongon, Object: Healthcare_Coverage, Relationship: RECEIVES, Timestamp: 2023-12-31T00:00:00\n",+ "Subject: Kenvue, Object: IPO, Relationship: INVOLVEDIN, Timestamp: 2023-05-01T00:00:00\n",+ "Subject: Kenvue, Object: Reverse_Transition_Manufacturing_Agreement, Relationship: ENTEREDINTO, Timestamp: 2023-07-03T00:00:00\n",+ "Subject: Kenvue, Object: Annual_Meeting, Relationship: HOSTS, Timestamp: 2024-03-25T00:00:00\n",+ "Subject: Annual_Meeting, Object: May_23_2024, Relationship: SCHEDULEDON, Timestamp: 2024-05-23T09:00:00\n",+ "Subject: Kenvue_Inc, Object: id_2023_10_26, Relationship: REPORTEDEARNINGS, Timestamp: 2023-10-26T00:00:00\n",+ "Subject: Kenvue, Object: id_1_5, Relationship: IMPACTSRETURN, Timestamp: 2023-07-31T00:00:00\n"+ ]+ }+ ],+ "source": [+ "# Query all triplets\n",+ "all_triplets = neo4j_graph.get_triplet()\n",+ "if all_triplets:\n",+ " for triplet in all_triplets:\n",+ " print(\n",+ " f\"Subject: {triplet['subj']}, Object: {triplet['obj']}, \"\n",+ " f\"Relationship: {triplet['rel']}, \"\n",+ " f\"Timestamp: {triplet['timestamp']}\"\n",+ " )\n",+ "else:\n",+ " print(\"No triplets found in the database.\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "oNRyv0JotB8R"+ },+ "source": [+ "## Parameters Investigation.\n",+ "\n",+ "- `max_characters`: The maximum number of characters in a chunk.\n",+ "- `model`: The model to use for the knowledge graph agent. (TogetherAI or Samba Verse)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "kVUI_gwGtB8S",+ "outputId": "d08a6345-8125-4464-fd0f-a82a74d3aced"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[33mThe number of elements is: \u001b[39m108\n",+ "\u001b[34m[max_characters: 512] \u001b[33mThe number of chunk elements is: 26\u001b[39m\n",+ "\u001b[34m[max_characters: 1024] \u001b[33mThe number of chunk elements is: 13\u001b[39m\n",+ "\u001b[34m[max_characters: 2048] \u001b[33mThe number of chunk elements is: 7\u001b[39m\n"+ ]+ }+ ],+ "source": [+ "elements = uio.parse_file_or_url(str(example_pdf_files[0]))\n",+ "print(\n",+ " colorama.Fore.YELLOW\n",+ " + \"The number of elements is: \"\n",+ " + colorama.Fore.RESET\n",+ " + str(len(elements))\n",+ ")\n",+ "\n",+ "# Investigation of the chunk_elements function.\n",+ "for max_characters in [512, 1024, 2048]:\n",+ " chunk_elements = uio.chunk_elements(\n",+ " elements,\n",+ " chunk_type=\"chunk_by_title\",\n",+ " max_characters=max_characters,\n",+ " )\n",+ " print(\n",+ " colorama.Fore.BLUE\n",+ " + f\"[max_characters: {max_characters:>4}] \"\n",+ " + colorama.Fore.YELLOW\n",+ " + f\"The number of chunk elements is: {len(chunk_elements)}\"\n",+ " + colorama.Fore.RESET\n",+ " )"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Lp5xIoTptB8S",+ "outputId": "d9d6e791-f36b-4873-d29b-54cabd16d283"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "13\n",+ "Kenvue Inc. (KVUE)\n",+ "\n",+ "Updated November 8th, 2024 by Nathan Parsh Key Metrics\n",+ "\n",+ "Current Price: $23.48 5 Year CAGR Estimate: -0.3% Market Cap: $45 B Fair Value Price: $16.10 5 Year Growth Estimate: 3.0% Ex-Dividend Date: 11/13/24 % Fair Value: 146% 5 Year Valuation Multiple Estimate: -7.3% Dividend Payment Date: 11/27/24 Dividend Yield: 3.5% 5 Year Price Target $19 Years Of Dividend Growth: 62 Dividend Risk Score: A Retirement Suitability Score: A Rating: Sell\n"+ ]+ }+ ],+ "source": [+ "limited_chunk_elements = uio.chunk_elements(\n",+ " elements, chunk_type=\"chunk_by_title\", max_characters=1000\n",+ ")\n",+ "print(len(limited_chunk_elements))\n",+ "print(limited_chunk_elements[0].text)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "1nBmgXRttB8S",+ "outputId": "609b5d7e-4168-4763-a3e3-b4fe2b68e923"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "459\n",+ "Kenvue Inc. (KVUE)\n",+ "\n",+ "Updated November 8th, 2024 by Nathan Parsh Key Metrics\n",+ "\n",+ "Current Price: $23.48 5 Year CAGR Estimate: -0.3% Market Cap: $45 B Fair Value Price: $16.10 5 Year Growth Estimate: 3.0% Ex-Dividend Date: 11/13/24 % Fair Value: 146% 5 Year Valuation Multiple Estimate: -7.3% Dividend Payment Date: 11/27/24 Dividend Yield: 3.5% 5 Year Price Target $19 Years Of Dividend Growth: 62 Dividend Risk Score: A Retirement Suitability Score: A Rating: Sell\n"+ ]+ }+ ],+ "source": [+ "print(len(limited_chunk_elements[0].text))\n",+ "print(limited_chunk_elements[0].text)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Fsv07793WCNN"+ },+ "outputs": [],+ "source": [+ "llama_kg_result = llama_405b_kg_agent.run(\n",+ " limited_chunk_elements[0], parse_graph_elements=True\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "IjPPgmWftB8T",+ "outputId": "006153bb-02a2-4585-ec17-f728559b18b3"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "17\n",+ "[Node(id='Kenvue Inc.', type=\"Organization', ticker='KVUE\", properties={'source': 'agent_created'}), Node(id='Nathan Parsh', type='Person', properties={'source': 'agent_created'}), Node(id='$19.15', type=\"Price', description='Current Price\", properties={'source': 'agent_created'}), Node(id='5.5%', type=\"Growth Rate', description='5 Year CAGR Estimate\", properties={'source': 'agent_created'}), Node(id='$37 B', type='Market Capitalization', properties={'source': 'agent_created'}), Node(id='$17.78', type=\"Price', description='Fair Value Price\", properties={'source': 'agent_created'}), Node(id='3.0%', type=\"Growth Rate', description='5 Year Growth Estimate\", properties={'source': 'agent_created'}), Node(id='11/07/23', type=\"Date', description='Ex-Dividend Date\", properties={'source': 'agent_created'}), Node(id='108%', type=\"Valuation', description='% Fair Value\", properties={'source': 'agent_created'}), Node(id='-1.5%', type=\"Valuation Multiple', description='5 Year Valuation Multiple Estimate\", properties={'source': 'agent_created'}), Node(id='11/22/23', type=\"Date', description='Dividend Payment Date\", properties={'source': 'agent_created'}), Node(id='4.2%', type='Dividend Yield', properties={'source': 'agent_created'}), Node(id='$21', type=\"Price', description='5 Year Price Target\", properties={'source': 'agent_created'}), Node(id='61', type='Years Of Dividend Growth', properties={'source': 'agent_created'}), Node(id='C', type='Dividend Risk Score', properties={'source': 'agent_created'}), Node(id='B', type='Retirement Suitability Score', properties={'source': 'agent_created'}), Node(id='Hold', type='Rating', properties={'source': 'agent_created'})]\n"+ ]+ }+ ],+ "source": [+ "print(len(llama_kg_result.nodes))\n",+ "print(llama_kg_result.nodes)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "lLB-CQP1WCNT"+ },+ "outputs": [],+ "source": [+ "together_kg_result = together_kg_agent.run(\n",+ " limited_chunk_elements[0], parse_graph_elements=True\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "iJxfuO-OWCNU",+ "outputId": "0fc47b41-93d6-4e14-fd08-32fa553cc8d9"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "18\n",+ "[Node(id='Kenvue Inc.', type='Organization', properties={'source': 'agent_created'}), Node(id='Nathan Parsh', type='Person', properties={'source': 'agent_created'}), Node(id='$19.15', type='Price', properties={'source': 'agent_created'}), Node(id='5.5%', type='CAGR', properties={'source': 'agent_created'}), Node(id='$37 B', type='MarketCap', properties={'source': 'agent_created'}), Node(id='$17.78', type='FairValuePrice', properties={'source': 'agent_created'}), Node(id='3.0%', type='GrowthEstimate', properties={'source': 'agent_created'}), Node(id='11/07/23', type='ExDividendDate', properties={'source': 'agent_created'}), Node(id='108%', type='FairValue', properties={'source': 'agent_created'}), Node(id='-1.5%', type='ValuationMultipleEstimate', properties={'source': 'agent_created'}), Node(id='11/22/23', type='DividendPaymentDate', properties={'source': 'agent_created'}), Node(id='4.2%', type='DividendYield', properties={'source': 'agent_created'}), Node(id='$21', type='PriceTarget', properties={'source': 'agent_created'}), Node(id='61', type='YearsOfDividendGrowth', properties={'source': 'agent_created'}), Node(id='C', type='DividendRiskScore', properties={'source': 'agent_created'}), Node(id='B', type='RetirementSuitabilityScore', properties={'source': 'agent_created'}), Node(id='Hold', type='Rating', properties={'source': 'agent_created'}), Node(id='{self.id}', type='{self.type}', properties={'source': 'agent_created'})]\n"+ ]+ }+ ],+ "source": [+ "print(len(together_kg_result.nodes))\n",+ "print(together_kg_result.nodes)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "5LS3u3aoQvru"+ },+ "source": [+ "## 🌟 Highlights"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "xerDlirc1nx2"+ },+ "source": [+ "This notebook has guided you through setting up and running a dynamic knowledge graph construction workflow using CAMEL's Knowledge Graph Agent and Neo4j. You can adapt and expand this example for various other scenarios requiring dynamic graph generation and querying.\n",+ "\n",+ "Key tools utilized in this notebook include:\n",+ "\n",+ "- **CAMEL**: A powerful multi-agent framework that enables the construction of knowledge graphs from unstructured data.\n",+ "- **Neo4j**: A graph database used to store and query the knowledge graph.\n",+ "- **Together and SambaVerse Models**: Large language models used to generate the knowledge graph from parsed documents.\n",+ "- **Deduplication**: Techniques to ensure the uniqueness of nodes and relationships in the graph.\n",+ "\n",+ "This comprehensive setup allows you to adapt and expand the example for various scenarios requiring dynamic graph generation and querying."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "s6Det-fcMb9A"+ },+ "source": [+ "<div class=\"align-center\">\n",+ " <a href=\"https://www.camel-ai.org/\"><img src=\"https://i.postimg.cc/KzQ5rfBC/button.png\"width=\"150\"></a>\n",+ " <a href=\"https://discord.camel-ai.org\"><img src=\"https://i.postimg.cc/L4wPdG9N/join-2.png\" width=\"150\"></a></a>\n",+ " \n",+ "⭐ <i>Star us on [*Github*](https://github.com/camel-ai/camel), join our [*Discord*](https://discord.camel-ai.org) or follow our [*X*](https://x.com/camelaiorg)\n",+ "</div>"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "dkg",+ "language": "python",+ "name": "python3"+ },+ "language_info": {+ "codemirror_mode": {+ "name": "ipython",+ "version": 3+ },+ "file_extension": ".py",+ "mimetype": "text/x-python",+ "name": "python",+ "nbconvert_exporter": "python",+ "pygments_lexer": "ipython3",+ "version": "3.10.14"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}\ No newline at end of file