diff --git a/README.md b/README.md index 1c7c446ec..8c1994b99 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,14 @@ Build dynamic Agent memory using scalable, modular ECL (Extract, Cognify, Load) More on [use-cases](https://docs.cognee.ai/use-cases) and [evals](https://github.com/topoteretes/cognee/tree/main/evals) +

+ 🌐 Available Languages + : + 🇵🇹 Português + · + 🇨🇳 [中文] +

+
Why cognee?
@@ -116,17 +124,15 @@ Example output: Natural Language Processing (NLP) is a cross-disciplinary and interdisciplinary field that involves computer science and information retrieval. It focuses on the interaction between computers and human language, enabling machines to understand and process natural language. ``` -### cognee UI + +### cognee UI You can also cognify your files and query using cognee UI. - Cognee UI 2 - Try cognee UI out locally [here](https://docs.cognee.ai/how-to-guides/cognee-ui). - ## Understand our architecture
diff --git a/cognee/modules/pipelines/operations/run_tasks.py b/cognee/modules/pipelines/operations/run_tasks.py index 71f22ac48..5f34be011 100644 --- a/cognee/modules/pipelines/operations/run_tasks.py +++ b/cognee/modules/pipelines/operations/run_tasks.py @@ -20,7 +20,9 @@ from ..tasks.task import Task logger = get_logger("run_tasks(tasks: [Task], data)") -async def run_tasks_with_telemetry(tasks: list[Task], data, user: User, pipeline_name: str): +async def run_tasks_with_telemetry( + tasks: list[Task], data, user: User, pipeline_name: str, context: dict = None +): config = get_current_settings() logger.debug("\nRunning pipeline with configuration:\n%s\n", json.dumps(config, indent=1)) @@ -36,7 +38,7 @@ async def run_tasks_with_telemetry(tasks: list[Task], data, user: User, pipeline | config, ) - async for result in run_tasks_base(tasks, data, user): + async for result in run_tasks_base(tasks, data, user, context): yield result logger.info("Pipeline run completed: `%s`", pipeline_name) @@ -72,6 +74,7 @@ async def run_tasks( data: Any = None, user: User = None, pipeline_name: str = "unknown_pipeline", + context: dict = None, ): pipeline_id = uuid5(NAMESPACE_OID, pipeline_name) @@ -82,7 +85,11 @@ async def run_tasks( try: async for _ in run_tasks_with_telemetry( - tasks=tasks, data=data, user=user, pipeline_name=pipeline_id + tasks=tasks, + data=data, + user=user, + pipeline_name=pipeline_id, + context=context, ): pass diff --git a/cognee/modules/pipelines/operations/run_tasks_base.py b/cognee/modules/pipelines/operations/run_tasks_base.py index 9c5cdfdb8..e5f577848 100644 --- a/cognee/modules/pipelines/operations/run_tasks_base.py +++ b/cognee/modules/pipelines/operations/run_tasks_base.py @@ -14,6 +14,7 @@ async def handle_task( leftover_tasks: list[Task], next_task_batch_size: int, user: User, + context: dict = None, ): """Handle common task workflow with logging, telemetry, and error handling around the core execution logic.""" task_type = running_task.task_type @@ -27,9 +28,16 @@ async def handle_task( }, ) + has_context = any( + [key == "context" for key in inspect.signature(running_task.executable).parameters.keys()] + ) + + if has_context: + args.append(context) + try: async for result_data in running_task.execute(args, next_task_batch_size): - async for result in run_tasks_base(leftover_tasks, result_data, user): + async for result in run_tasks_base(leftover_tasks, result_data, user, context): yield result logger.info(f"{task_type} task completed: `{running_task.executable.__name__}`") @@ -55,7 +63,7 @@ async def handle_task( raise error -async def run_tasks_base(tasks: list[Task], data=None, user: User = None): +async def run_tasks_base(tasks: list[Task], data=None, user: User = None, context: dict = None): """Base function to execute tasks in a pipeline, handling task type detection and execution.""" if len(tasks) == 0: yield data @@ -68,5 +76,7 @@ async def run_tasks_base(tasks: list[Task], data=None, user: User = None): next_task = leftover_tasks[0] if len(leftover_tasks) > 0 else None next_task_batch_size = next_task.task_config["batch_size"] if next_task else 1 - async for result in handle_task(running_task, args, leftover_tasks, next_task_batch_size, user): + async for result in handle_task( + running_task, args, leftover_tasks, next_task_batch_size, user, context + ): yield result diff --git a/cognee/shared/logging_utils.py b/cognee/shared/logging_utils.py index 4d2ee7f52..bfd4828f8 100644 --- a/cognee/shared/logging_utils.py +++ b/cognee/shared/logging_utils.py @@ -312,7 +312,7 @@ def setup_logging(log_level=None, name=None): root_logger.addHandler(file_handler) root_logger.setLevel(log_level) - if log_level > logging.WARNING: + if log_level > logging.DEBUG: import warnings from sqlalchemy.exc import SAWarning diff --git a/cognee/tests/integration/run_toy_tasks/conftest.py b/cognee/tests/integration/run_toy_tasks/conftest.py deleted file mode 100644 index 09e98328c..000000000 --- a/cognee/tests/integration/run_toy_tasks/conftest.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -import pytest - - -@pytest.fixture(autouse=True, scope="session") -def copy_cognee_db_to_target_location(): - os.makedirs("cognee/.cognee_system/databases/", exist_ok=True) - os.system( - "cp cognee/tests/integration/run_toy_tasks/data/cognee_db cognee/.cognee_system/databases/cognee_db" - ) diff --git a/cognee/tests/integration/run_toy_tasks/data/cognee_db b/cognee/tests/integration/run_toy_tasks/data/cognee_db deleted file mode 100644 index 912adf295..000000000 Binary files a/cognee/tests/integration/run_toy_tasks/data/cognee_db and /dev/null differ diff --git a/cognee/tests/integration/run_toy_tasks/run_task_from_queue_test.py b/cognee/tests/unit/modules/pipelines/run_task_from_queue_test.py similarity index 100% rename from cognee/tests/integration/run_toy_tasks/run_task_from_queue_test.py rename to cognee/tests/unit/modules/pipelines/run_task_from_queue_test.py diff --git a/cognee/tests/integration/run_toy_tasks/run_tasks_test.py b/cognee/tests/unit/modules/pipelines/run_tasks_test.py similarity index 96% rename from cognee/tests/integration/run_toy_tasks/run_tasks_test.py rename to cognee/tests/unit/modules/pipelines/run_tasks_test.py index 7fbc905ee..72dd5440e 100644 --- a/cognee/tests/integration/run_toy_tasks/run_tasks_test.py +++ b/cognee/tests/unit/modules/pipelines/run_tasks_test.py @@ -48,3 +48,7 @@ async def run_and_check_tasks(): def test_run_tasks(): asyncio.run(run_and_check_tasks()) + + +if __name__ == "__main__": + test_run_tasks() diff --git a/cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py b/cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py new file mode 100644 index 000000000..32c9f32a7 --- /dev/null +++ b/cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py @@ -0,0 +1,47 @@ +import asyncio + +import cognee +from cognee.modules.pipelines.tasks.task import Task +from cognee.modules.users.methods import get_default_user +from cognee.modules.pipelines.operations.run_tasks import run_tasks_base +from cognee.infrastructure.databases.relational import create_db_and_tables + + +async def run_and_check_tasks(): + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + + def task_1(num, context): + return num + context + + def task_2(num): + return num * 2 + + def task_3(num, context): + return num**context + + await create_db_and_tables() + user = await get_default_user() + + pipeline = run_tasks_base( + [ + Task(task_1), + Task(task_2), + Task(task_3), + ], + data=5, + user=user, + context=7, + ) + + final_result = 4586471424 + async for result in pipeline: + assert result == final_result + + +def test_run_tasks(): + asyncio.run(run_and_check_tasks()) + + +if __name__ == "__main__": + test_run_tasks() diff --git a/community/README.zh.md b/community/README.zh.md new file mode 100644 index 000000000..573a77b31 --- /dev/null +++ b/community/README.zh.md @@ -0,0 +1,162 @@ +
+ + Cognee Logo + + +
+ + cognee - AI应用和智能体的记忆层 + +

+ 演示 + . + 了解更多 + · + 加入Discord +

+ + + [![GitHub forks](https://img.shields.io/github/forks/topoteretes/cognee.svg?style=social&label=Fork&maxAge=2592000)](https://GitHub.com/topoteretes/cognee/network/) + [![GitHub stars](https://img.shields.io/github/stars/topoteretes/cognee.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/topoteretes/cognee/stargazers/) + [![GitHub commits](https://badgen.net/github/commits/topoteretes/cognee)](https://GitHub.com/topoteretes/cognee/commit/) + [![Github tag](https://badgen.net/github/tag/topoteretes/cognee)](https://github.com/topoteretes/cognee/tags/) + [![Downloads](https://static.pepy.tech/badge/cognee)](https://pepy.tech/project/cognee) + [![License](https://img.shields.io/github/license/topoteretes/cognee?colorA=00C586&colorB=000000)](https://github.com/topoteretes/cognee/blob/main/LICENSE) + [![Contributors](https://img.shields.io/github/contributors/topoteretes/cognee?colorA=00C586&colorB=000000)](https://github.com/topoteretes/cognee/graphs/contributors) + + 可靠的AI智能体响应。 + + + +使用可扩展、模块化的ECL(提取、认知、加载)管道构建动态智能体记忆。 + +更多[使用场景](https://docs.cognee.ai/use_cases)。 + +
+ 为什么选择cognee? +
+ +
+ + + + +## 功能特性 + +- 互联并检索您的历史对话、文档、图像和音频转录 +- 减少幻觉、开发人员工作量和成本 +- 仅使用Pydantic将数据加载到图形和向量数据库 +- 从30多个数据源摄取数据时进行数据操作 + +## 开始使用 + +通过Google Colab 笔记本入门项目快速上手 + +## 贡献 +您的贡献是使这成为真正开源项目的核心。我们**非常感谢**任何贡献。更多信息请参阅[`CONTRIBUTING.md`](CONTRIBUTING.md)。 + + + + + +## 📦 安装 + +您可以使用**pip**、**poetry**、**uv**或任何其他Python包管理器安装Cognee。 + +### 使用pip + +```bash +pip install cognee +``` + +## 💻 基本用法 + +### 设置 + +``` +import os +os.environ["LLM_API_KEY"] = "YOUR OPENAI_API_KEY" + +``` + +您也可以通过创建.env文件设置变量,使用我们的模板。 +要使用不同的LLM提供商,请查看我们的文档获取更多信息。 + + +### 简单示例 + +此脚本将运行默认管道: + +```python +import cognee +import asyncio + + +async def main(): + # Add text to cognee + await cognee.add("自然语言处理(NLP)是计算机科学和信息检索的跨学科领域。") + + # Generate the knowledge graph + await cognee.cognify() + + # Query the knowledge graph + results = await cognee.search("告诉我关于NLP") + + # Display the results + for result in results: + print(result) + + +if __name__ == '__main__': + asyncio.run(main()) + +``` +示例输出: +``` + 自然语言处理(NLP)是计算机科学和信息检索的跨学科领域。它关注计算机和人类语言之间的交互,使机器能够理解和处理自然语言。 + +``` +图形可视化: +图形可视化 +在[浏览器](https://rawcdn.githack.com/topoteretes/cognee/refs/heads/main/assets/graph_visualization.html)中打开。 + +有关更高级的用法,请查看我们的文档。 + + +## 了解我们的架构 + +
+ cognee概念图 +
+ + + +## 演示 + +1. 什么是AI记忆: + +[了解cognee](https://github.com/user-attachments/assets/8b2a0050-5ec4-424c-b417-8269971503f0) + +2. 简单GraphRAG演示 + +[简单GraphRAG演示](https://github.com/user-attachments/assets/f57fd9ea-1dc0-4904-86eb-de78519fdc32) + +3. cognee与Ollama + +[cognee与本地模型](https://github.com/user-attachments/assets/834baf9a-c371-4ecf-92dd-e144bd0eb3f6) + + +## 行为准则 + +我们致力于为我们的社区提供愉快和尊重的开源体验。有关更多信息,请参阅CODE_OF_CONDUCT。 + +## 💫 贡献者 + + + contributors + + + +## Star历史 + +[![Star History Chart](https://api.star-history.com/svg?repos=topoteretes/cognee&type=Date)](https://star-history.com/#topoteretes/cognee&Date) diff --git a/community/cognee_benefits_zh.JPG b/community/cognee_benefits_zh.JPG new file mode 100644 index 000000000..30474b8d9 Binary files /dev/null and b/community/cognee_benefits_zh.JPG differ diff --git a/community/cognee_diagram_zh.JPG b/community/cognee_diagram_zh.JPG new file mode 100644 index 000000000..df78ec6c0 Binary files /dev/null and b/community/cognee_diagram_zh.JPG differ