{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "# Turn expert developer Python knowhow into an AI Memory that will make your own code better. \n", "\n", "\n", "### Learning from Guido van Rossum, the creator of Python" ], "id": "6f22c8fe6d92cfcc" }, { "metadata": {}, "cell_type": "markdown", "source": [ "## What You'll Learn\n", "\n", "In this comprehensive tutorial, you'll discover how to transform scattered development data into an intelligent knowledge system that enhances your coding workflow. By the end, you'll have:\n", "\n", "- **Connected disparate data sources** (Guido's CPython contributions, mypy development, PEP discussions, your Python projects) into a unified AI memory graph\n", "- **Built an memory layer** that understands Python design philosophy and coding patterns\n", "- **Learn how to use intelligent search capabilities** that surface Pythonic solutions when you need them most\n", "- **Integrated everything with your coding environment** through MCP (Model Context Protocol)\n", "\n", "This tutorial demonstrates the power of **knowledge graphs** and **retrieval-augmented generation (RAG)** for software development, showing you how to build systems that learn from Python's creator and improve your own Python development." ], "id": "fe69acbf9ab1a22b" }, { "metadata": {}, "cell_type": "markdown", "source": [ "## Understanding the Cognee Ecosystem\n", "\n", "Before we dive in, let's understand the key components we'll be working with:\n", "\n", "### Core Cognee Functions\n", "\n", "- **`cognee.add()`** - Ingests raw data (files, text, APIs) into the system\n", "- **`cognee.cognify()`** - Processes and structures data into a knowledge graph using AI\n", "- **`cognee.search()`** - Queries the knowledge graph with natural language or Cypher\n", "- **`cognee.visualize()`** - Creates interactive graph visualizations\n", "- **`cognee.memify()`** - Cognee's \"secret sauce\" that infers implicit connections and rules from your data" ], "id": "b03b59c064213dd4" }, { "metadata": {}, "cell_type": "markdown", "source": [ "### Why This Approach Works\n", "\n", "Traditional coding assistants lack context about your specific projects, rules, and past decisions. By building a knowledge graph of development history from Python's creator, we create an AI that understands:\n", "\n", "- Guido's coding patterns and Python design philosophy\n", "- How language features evolved and why\n", "- Best practices derived from decades of Python development\n", "- Connections between different aspects of Python programming" ], "id": "6a7669fbb6a3e6c7" }, { "metadata": {}, "cell_type": "markdown", "source": [ "### Exploring Guido's Python Contributions\n", "\n", "We'll begin with a pre-loaded dataset containing Guido van Rossum's contributions to the Python ecosystem. This demonstrates how cognee structures and connects development activity from Python's creator.\n", "\n", "Take a moment to explore the repositories this user contributed to with the Graph Visualizaiton" ], "id": "93c9783037715026" }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T09:57:30.827241Z", "start_time": "2025-09-07T09:57:27.209811Z" } }, "cell_type": "code", "source": [ "import cognee\n", "import os\n", "from pathlib import Path\n", "\n", "print('🔍 Quick Cognee Import Check')\n", "print('=' * 30)\n", "print(f'📍 Cognee location: {cognee.__file__}')\n", "print(f'📁 Package directory: {os.path.dirname(cognee.__file__)}')\n", "\n", "# Check if it's local or installed\n", "current_dir = Path.cwd()\n", "cognee_path = Path(cognee.__file__)\n", "if current_dir in cognee_path.parents:\n", " print('🏠 Status: LOCAL DEVELOPMENT VERSION')\n", "else:\n", " print('📦 Status: INSTALLED PACKAGE')" ], "id": "9386ecb596860399", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\u001B[2m2025-09-07T09:57:28.419783\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mDeleted old log file: /Users/lazar/PycharmProjects/cognee/logs/2025-09-04_09-37-20.log\u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m\n", "/Users/lazar/PycharmProjects/cognee/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", "\n", "\u001B[2m2025-09-07T09:57:29.163761\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mLogging initialized \u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m \u001B[36mcognee_version\u001B[0m=\u001B[35m0.2.4-local\u001B[0m \u001B[36mdatabase_path\u001B[0m=\u001B[35m/Users/lazar/PycharmProjects/cognee/cognee/.cognee_system/databases\u001B[0m \u001B[36mgraph_database_name\u001B[0m=\u001B[35m\u001B[0m \u001B[36mos_info\u001B[0m=\u001B[35m'Darwin 24.5.0 (Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030)'\u001B[0m \u001B[36mpython_version\u001B[0m=\u001B[35m3.12.8\u001B[0m \u001B[36mrelational_config\u001B[0m=\u001B[35mcognee_db\u001B[0m \u001B[36mstructlog_version\u001B[0m=\u001B[35m25.4.0\u001B[0m \u001B[36mvector_config\u001B[0m=\u001B[35mlancedb\u001B[0m\n", "\n", "\u001B[2m2025-09-07T09:57:29.164208\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mDatabase storage: /Users/lazar/PycharmProjects/cognee/cognee/.cognee_system/databases\u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "🔍 Quick Cognee Import Check\n", "==============================\n", "📍 Cognee location: /Users/lazar/PycharmProjects/cognee/cognee/__init__.py\n", "📁 Package directory: /Users/lazar/PycharmProjects/cognee/cognee\n", "📦 Status: INSTALLED PACKAGE\n" ] } ], "execution_count": 1 }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T09:59:43.525416Z", "start_time": "2025-09-07T09:59:43.522480Z" } }, "cell_type": "code", "source": [ "import sys\n", "from pathlib import Path\n", "notebook_dir = Path.cwd()\n", "if notebook_dir.name == 'notebooks':\n", " project_root = notebook_dir.parent\n", "else:\n", " project_root = Path.cwd()\n", "\n", "# Add project root to the beginning of sys.path\n", "project_root_str = str(project_root.absolute())\n", "if project_root_str not in sys.path:\n", " sys.path.insert(0, project_root_str)\n", "\n", "print(f\"📁 Project root: {project_root_str}\")" ], "id": "19e74e6b691020db", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "📁 Project root: /Users/lazar/PycharmProjects/cognee\n" ] } ], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T10:00:14.685409Z", "start_time": "2025-09-07T10:00:12.419145Z" } }, "cell_type": "code", "source": [ "import cognee\n", "\n", "\n", "\n", "result = await cognee.add(\"file://data/guido_contributions.json\", node_set=[\"guido\"])\n", "await cognee.cognify()\n", "results = await cognee.search(\"Show me commits\")" ], "id": "b8743ed520b4de37", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\u001B[2m2025-09-07T10:00:12.505721\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mOntology file 'None' not found. No owl ontology will be attached to the graph.\u001B[0m [\u001B[0m\u001B[1m\u001B[34mOntologyAdapter\u001B[0m]\u001B[0m\n", "\n", "\u001B[2m2025-09-07T10:00:12.578388\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mRetrieved 85 nodes and 182 edges in 0.02 seconds\u001B[0m [\u001B[0m\u001B[1m\u001B[34mNeo4jAdapter\u001B[0m]\u001B[0m\n", "\n", "\u001B[2m2025-09-07T10:00:12.580139\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mGraph projection completed: 85 nodes, 182 edges in 0.03s\u001B[0m [\u001B[0m\u001B[1m\u001B[34mCogneeGraph\u001B[0m]\u001B[0m\n", "\n", "\u001B[2m2025-09-07T10:00:12.958731\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mVector collection retrieval completed: Retrieved distances from 6 collections in 0.03s\u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m\n" ] } ], "execution_count": 6 }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T10:00:16.283950Z", "start_time": "2025-09-07T10:00:16.280509Z" } }, "cell_type": "code", "source": "results[0]", "id": "f08b362cbf12b398", "outputs": [ { "data": { "text/plain": [ "'Here are the commits from the provided context:'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 7 }, { "metadata": {}, "cell_type": "markdown", "source": "What's happening here? The search() function uses natural language to query a knowledge graph containing Guido's development history. Unlike traditional databases, this understands the relationships between commits, language features, design decisions, and evolution over time.", "id": "10d582d02ead905e" }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T10:04:42.969912Z", "start_time": "2025-09-07T10:04:42.898473Z" } }, "cell_type": "code", "source": [ "from cognee import visualize_graph\n", "\n", "await visualize_graph('./guido_contributions.html')" ], "id": "1fb068f422bda6cf", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\u001B[2m2025-09-07T10:04:42.959421\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mRetrieved 85 nodes and 182 edges in 0.03 seconds\u001B[0m [\u001B[0m\u001B[1m\u001B[34mNeo4jAdapter\u001B[0m]\u001B[0m\n", "\n", "\u001B[2m2025-09-07T10:04:42.963711\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mGraph visualization saved as ./guido_contributions.html\u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m\n", "\n", "\u001B[2m2025-09-07T10:04:42.964638\u001B[0m [\u001B[32m\u001B[1minfo \u001B[0m] \u001B[1mThe HTML file has been stored at path: ./guido_contributions.html\u001B[0m [\u001B[0m\u001B[1m\u001B[34mcognee.shared.logging_utils\u001B[0m]\u001B[0m\n" ] }, { "data": { "text/plain": [ "'\\n \\n \\n
\\n \\n \\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n '" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 12 }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-07T10:04:24.449814Z", "start_time": "2025-09-07T10:04:24.443869Z" } }, "cell_type": "code", "source": [ "from IPython.display import IFrame, HTML, display\n", "display(IFrame(\"./guido_contributions.html\", width=\"100%\", height=\"500\"))" ], "id": "f24341c97d6eaccb", "outputs": [ { "data": { "text/plain": [ "