diff --git a/cognee/api/v1/add/add.py b/cognee/api/v1/add/add.py index 90b11cda2..9a255e161 100644 --- a/cognee/api/v1/add/add.py +++ b/cognee/api/v1/add/add.py @@ -8,6 +8,10 @@ from cognee.infrastructure import infrastructure_config from cognee.infrastructure.files.storage import LocalStorage from cognee.modules.discovery import discover_directory_datasets +from cognee.utils import send_telemetry + + + async def add(data_path: Union[str, List[str]], dataset_name: str = None): if isinstance(data_path, str): # data_path is a data directory path @@ -101,6 +105,7 @@ async def add_files(file_paths: List[str], dataset_name: str): dataset_name = dataset_name.replace(" ", "_").replace(".", "_") if dataset_name is not None else "main_dataset", write_disposition = "merge", ) + send_telemetry( "COGNEE_ADD") return run_info diff --git a/cognee/api/v1/cognify/cognify.py b/cognee/api/v1/cognify/cognify.py index 64a7ec5b2..eb876e0a9 100644 --- a/cognee/api/v1/cognify/cognify.py +++ b/cognee/api/v1/cognify/cognify.py @@ -25,6 +25,7 @@ from cognee.modules.data.get_content_categories import get_content_categories from cognee.modules.data.get_content_summary import get_content_summary from cognee.modules.data.get_cognitive_layers import get_cognitive_layers from cognee.modules.data.get_layer_graphs import get_layer_graphs +from cognee.utils import send_telemetry config = Config() @@ -162,4 +163,6 @@ async def process_text(chunk_collection: str, chunk_id: str, input_text: str, fi score_threshold = infrastructure_config.get_config()["intra_layer_score_treshold"] ) + send_telemetry( "COGNEE_COGNIFY") + print(f"Chunk ({chunk_id}) cognified.") diff --git a/cognee/api/v1/search/search.py b/cognee/api/v1/search/search.py index d5eb20b67..dfa90f19c 100644 --- a/cognee/api/v1/search/search.py +++ b/cognee/api/v1/search/search.py @@ -10,6 +10,7 @@ from cognee.modules.search.graph.search_neighbour import search_neighbour from cognee.modules.search.graph.search_summary import search_summary from cognee.infrastructure.databases.graph.get_graph_client import get_graph_client from cognee.infrastructure import infrastructure_config +from cognee.utils import send_telemetry class SearchType(Enum): ADJACENT = 'ADJACENT' @@ -69,6 +70,8 @@ async def specific_search(query_params: List[SearchParameters]) -> List: # Update the results set with the results from all tasks results.extend(search_results) + send_telemetry( "COGNEE_SEARCH") + return results diff --git a/cognee/utils.py b/cognee/utils.py index a9eec6318..32e4fba9a 100644 --- a/cognee/utils.py +++ b/cognee/utils.py @@ -8,11 +8,34 @@ import pandas as pd import matplotlib.pyplot as plt import tiktoken import nltk +from posthog import Posthog + from cognee.config import Config +import uuid +import datetime config = Config() config.load() + +def send_telemetry( posthog, event_name="COGNEE_ADD"): + if os.getenv("TELEMETRY_DISABLED"): + return + + posthog = Posthog(project_api_key='phc_bbR86N876kwub62Lr3dhQ7zIeRyMMMm0fxXqxPqzLm3', + host='https://eu.i.posthog.com') + + user_id = str(uuid.uuid4()) + current_time = datetime.datetime.now() + properties = { + "time": current_time.strftime('%m/%d/%Y') + + } + + try: + posthog.capture(user_id, event_name, properties) + except Exception as e: + print('ERROR sending telemetric data to Posthog. See exception: %s', e) def get_document_names(doc_input): """ Get a list of document names. diff --git a/poetry.lock b/poetry.lock index 8fd62d5eb..d92eef1c7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3458,6 +3458,17 @@ files = [ griffe = ">=0.37" mkdocstrings = ">=0.20" +[[package]] +name = "monotonic" +version = "1.6" +description = "An implementation of time.monotonic() for Python 2 & < 3.3" +optional = false +python-versions = "*" +files = [ + {file = "monotonic-1.6-py2.py3-none-any.whl", hash = "sha256:68687e19a14f11f26d140dd5c86f3dba4bf5df58003000ed467e0e2a69bca96c"}, + {file = "monotonic-1.6.tar.gz", hash = "sha256:3a55207bcfed53ddd5c5bae174524062935efed17792e9de2ad0205ce9ad63f7"}, +] + [[package]] name = "mpmath" version = "1.3.0" @@ -4147,6 +4158,7 @@ optional = false python-versions = ">=3.9" files = [ {file = "pandas-2.2.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:90c6fca2acf139569e74e8781709dccb6fe25940488755716d1d354d6bc58bce"}, + {file = "pandas-2.2.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c7adfc142dac335d8c1e0dcbd37eb8617eac386596eb9e1a1b77791cf2498238"}, {file = "pandas-2.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4abfe0be0d7221be4f12552995e58723c7422c80a659da13ca382697de830c08"}, {file = "pandas-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8635c16bf3d99040fdf3ca3db669a7250ddf49c55dc4aa8fe0ae0fa8d6dcc1f0"}, {file = "pandas-2.2.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:40ae1dffb3967a52203105a077415a86044a2bea011b5f321c6aa64b379a3f51"}, @@ -4167,6 +4179,7 @@ files = [ {file = "pandas-2.2.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:43498c0bdb43d55cb162cdc8c06fac328ccb5d2eabe3cadeb3529ae6f0517c32"}, {file = "pandas-2.2.2-cp312-cp312-win_amd64.whl", hash = "sha256:d187d355ecec3629624fccb01d104da7d7f391db0311145817525281e2804d23"}, {file = "pandas-2.2.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0ca6377b8fca51815f382bd0b697a0814c8bda55115678cbc94c30aacbb6eff2"}, + {file = "pandas-2.2.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:9057e6aa78a584bc93a13f0a9bf7e753a5e9770a30b4d758b8d5f2a62a9433cd"}, {file = "pandas-2.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:001910ad31abc7bf06f49dcc903755d2f7f3a9186c0c040b827e522e9cef0863"}, {file = "pandas-2.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:66b479b0bd07204e37583c191535505410daa8df638fd8e75ae1b383851fe921"}, {file = "pandas-2.2.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:a77e9d1c386196879aa5eb712e77461aaee433e54c68cf253053a73b7e49c33a"}, @@ -4520,6 +4533,29 @@ docs = ["sphinx (>=1.7.1)"] redis = ["redis"] tests = ["pytest (>=5.4.1)", "pytest-cov (>=2.8.1)", "pytest-mypy (>=0.8.0)", "pytest-timeout (>=2.1.0)", "redis", "sphinx (>=6.0.0)", "types-redis"] +[[package]] +name = "posthog" +version = "3.5.0" +description = "Integrate PostHog into any python application." +optional = false +python-versions = "*" +files = [ + {file = "posthog-3.5.0-py2.py3-none-any.whl", hash = "sha256:3c672be7ba6f95d555ea207d4486c171d06657eb34b3ce25eb043bfe7b6b5b76"}, + {file = "posthog-3.5.0.tar.gz", hash = "sha256:8f7e3b2c6e8714d0c0c542a2109b83a7549f63b7113a133ab2763a89245ef2ef"}, +] + +[package.dependencies] +backoff = ">=1.10.0" +monotonic = ">=1.5" +python-dateutil = ">2.1" +requests = ">=2.7,<3.0" +six = ">=1.5" + +[package.extras] +dev = ["black", "flake8", "flake8-print", "isort", "pre-commit"] +sentry = ["django", "sentry-sdk"] +test = ["coverage", "flake8", "freezegun (==0.3.15)", "mock (>=2.0.0)", "pylint", "pytest", "pytest-timeout"] + [[package]] name = "prometheus-client" version = "0.20.0" @@ -5078,7 +5114,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -7075,4 +7110,4 @@ weaviate = ["weaviate-client"] [metadata] lock-version = "2.0" python-versions = ">=3.9.0,<3.12" -content-hash = "deea0ca0fe759aabe96f616f95cf647714d970873466cfa8ae942f158b3423d0" +content-hash = "d026e03ff7f204a4026f4f980876fca84a1ac48d7dbfdcfec2c5d7656ed8355d" diff --git a/pyproject.toml b/pyproject.toml index 24e1eda5c..dc56436e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,7 @@ nest-asyncio = "^1.6.0" structlog = "^24.1.0" tiktoken = "^0.6.0" dspy-ai = "2.4.3" +posthog = "^3.5.0" [tool.poetry.extras]