-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add data visualization for Anthropic #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
daf2d54
b132ff4
7b0bfe9
cf4737b
55e9d64
047948a
3ba98b2
ad07bae
a0e3686
61118dd
e71f852
933d21a
aef7822
be0b486
662faeb
4a87df9
4ae8eb9
1af24dc
b2355de
5b31638
f19b58a
5aaf420
72b503f
7a4a0f4
0783625
bbd51e8
cb7b2d3
fe47253
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,51 +1,48 @@ | ||||||||||||
| name: build | Build and Push Docker Image to DockerHub | ||||||||||||
| name: build | Build and Push Docker Image to dockerhub | ||||||||||||
|
|
||||||||||||
| on: | ||||||||||||
| push: | ||||||||||||
| branches: | ||||||||||||
| - dev | ||||||||||||
| - main | ||||||||||||
|
|
||||||||||||
| jobs: | ||||||||||||
| docker-build-and-push: | ||||||||||||
| runs-on: ubuntu-latest | ||||||||||||
|
|
||||||||||||
| steps: | ||||||||||||
| - name: Checkout repository | ||||||||||||
| uses: actions/checkout@v4 | ||||||||||||
|
|
||||||||||||
| - name: Set up Docker Buildx | ||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||
|
|
||||||||||||
| - name: Log in to Docker Hub | ||||||||||||
| uses: docker/login-action@v3 | ||||||||||||
| with: | ||||||||||||
| username: ${{ secrets.DOCKER_USERNAME }} | ||||||||||||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||||||||||||
|
|
||||||||||||
| - name: Extract Git information | ||||||||||||
| id: git-info | ||||||||||||
| run: | | ||||||||||||
| echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> "$GITHUB_ENV" | ||||||||||||
| echo "COMMIT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_ENV" | ||||||||||||
|
|
||||||||||||
| - name: Build and Push Docker Image | ||||||||||||
| run: | | ||||||||||||
| IMAGE_NAME=cognee/cognee | ||||||||||||
| TAG_VERSION="${BRANCH_NAME}-${COMMIT_SHA}" | ||||||||||||
|
|
||||||||||||
| echo "Building image: ${IMAGE_NAME}:${TAG_VERSION}" | ||||||||||||
| docker buildx build \ | ||||||||||||
| --platform linux/amd64,linux/arm64 \ | ||||||||||||
| --push \ | ||||||||||||
| --tag "${IMAGE_NAME}:${TAG_VERSION}" \ | ||||||||||||
| --tag "${IMAGE_NAME}:latest" \ | ||||||||||||
| . | ||||||||||||
|
|
||||||||||||
| - name: Verify pushed Docker images | ||||||||||||
| run: | | ||||||||||||
| # Verify both platform variants | ||||||||||||
| for PLATFORM in "linux/amd64" "linux/arm64"; do | ||||||||||||
| echo "Verifying image for $PLATFORM..." | ||||||||||||
| docker buildx imagetools inspect "${IMAGE_NAME}:${TAG_VERSION}" --format "{{.Manifest.$PLATFORM.Digest}}" | ||||||||||||
| done | ||||||||||||
| echo "Successfully verified images in Docker Hub" | ||||||||||||
| - name: Checkout repository | ||||||||||||
| uses: actions/checkout@v4 | ||||||||||||
|
|
||||||||||||
| - name: Set up Docker Buildx | ||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||
|
|
||||||||||||
| - name: Log in to Docker Hub | ||||||||||||
| uses: docker/login-action@v3 | ||||||||||||
| with: | ||||||||||||
| username: ${{ secrets.DOCKER_USERNAME }} | ||||||||||||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||||||||||||
|
|
||||||||||||
| - name: Extract metadata | ||||||||||||
| id: meta | ||||||||||||
| uses: docker/metadata-action@v5 | ||||||||||||
| with: | ||||||||||||
| images: cognee/cognee | ||||||||||||
| tags: | | ||||||||||||
| type=ref,event=branch | ||||||||||||
| type=sha,prefix={{branch}}- | ||||||||||||
| type=raw,value=latest,enable={{is_default_branch}} | ||||||||||||
|
|
||||||||||||
| - name: Build and push | ||||||||||||
| uses: docker/build-push-action@v5 | ||||||||||||
| with: | ||||||||||||
| context: . | ||||||||||||
| platforms: linux/amd64,linux/arm64 | ||||||||||||
| push: true | ||||||||||||
| tags: ${{ steps.meta.outputs.tags }} | ||||||||||||
| labels: ${{ steps.meta.outputs.labels }} | ||||||||||||
| cache-from: type=registry,ref=cognee/cognee:buildcache | ||||||||||||
| cache-to: type=registry,ref=cognee/cognee:buildcache,mode=max | ||||||||||||
|
|
||||||||||||
| - name: Image digest | ||||||||||||
| run: echo ${{ steps.build.outputs.digest }} | ||||||||||||
|
Comment on lines
+47
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the image digest step. There are two issues to address:
Apply this diff to fix both issues: - name: Image digest
- run: echo ${{ steps.build.outputs.digest }}
+ run: echo ${{ steps.meta.outputs.json }}
+📝 Committable suggestion
Suggested change
🧰 Tools🪛 actionlint (1.7.4)48-48: property "build" is not defined in object type {meta: {conclusion: string; outcome: string; outputs: {annotations: string; bake-file: string; bake-file-annotations: string; bake-file-labels: string; bake-file-tags: string; json: string; labels: string; tags: string; version: string}}} (expression) 🪛 yamllint (1.35.1)[error] 48-48: no new line character at the end of file (new-line-at-end-of-file) |
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,15 @@ source .venv/bin/activate | |
| 4. Add the new server to your Claude config: | ||
|
|
||
| The file should be located here: ~/Library/Application\ Support/Claude/ | ||
| ``` | ||
| cd ~/Library/Application\ Support/Claude/ | ||
| ``` | ||
| You need to create claude_desktop_config.json in this folder if it doesn't exist | ||
| Make sure to add your paths and LLM API key to the file bellow | ||
| Use your editor of choice, for example Nano: | ||
| ``` | ||
| nano claude_desktop_config.json | ||
| ``` | ||
|
|
||
| ``` | ||
|
|
||
|
|
@@ -83,3 +91,17 @@ npx -y @smithery/cli install cognee --client claude | |
|
|
||
| Define cognify tool in server.py | ||
| Restart your Claude desktop. | ||
|
|
||
|
|
||
| To use debugger, run: | ||
| ```bash | ||
| npx @modelcontextprotocol/inspector uv --directory /Users/name/folder run cognee | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace hardcoded paths with placeholders. The instructions contain specific user paths that won't work for other users. Apply these changes: -npx @modelcontextprotocol/inspector uv --directory /Users/name/folder run cognee
+npx @modelcontextprotocol/inspector uv --directory /Users/{username}/path/to/folder run cognee
-npx @modelcontextprotocol/inspector uv --directory /Users/vasilije/cognee/cognee-mcp run cognee
+npx @modelcontextprotocol/inspector uv --directory /Users/{username}/cognee/cognee-mcp run cogneeAlso applies to: 105-105 |
||
| ``` | ||
|
|
||
| To apply new changes while development you do: | ||
|
|
||
| 1. Poetry lock in cognee folder | ||
| 2. uv sync --dev --all-extras --reinstall | ||
| 3. npx @modelcontextprotocol/inspector uv --directory /Users/vasilije/cognee/cognee-mcp run cognee | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,13 +3,17 @@ | |||||||||||||||||||||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||||||||||||||||||||||
| from contextlib import redirect_stderr, redirect_stdout | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from sqlalchemy.testing.plugin.plugin_base import logging | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use the standard Python logging module instead. Importing logging from sqlalchemy's testing plugin is not recommended. Use Python's built-in logging module instead. -from sqlalchemy.testing.plugin.plugin_base import logging
+import logging📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| import cognee | ||||||||||||||||||||||||||||||||||||||||||||
| import mcp.server.stdio | ||||||||||||||||||||||||||||||||||||||||||||
| import mcp.types as types | ||||||||||||||||||||||||||||||||||||||||||||
| from cognee.api.v1.search import SearchType | ||||||||||||||||||||||||||||||||||||||||||||
| from cognee.shared.data_models import KnowledgeGraph | ||||||||||||||||||||||||||||||||||||||||||||
| from mcp.server import NotificationOptions, Server | ||||||||||||||||||||||||||||||||||||||||||||
| from mcp.server.models import InitializationOptions | ||||||||||||||||||||||||||||||||||||||||||||
| from PIL import Image | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| server = Server("cognee-mcp") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -87,9 +91,45 @@ async def handle_list_tools() -> list[types.Tool]: | |||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
| types.Tool( | ||||||||||||||||||||||||||||||||||||||||||||
| name="visualize", | ||||||||||||||||||||||||||||||||||||||||||||
| description="Visualize the knowledge graph.", | ||||||||||||||||||||||||||||||||||||||||||||
| inputSchema={ | ||||||||||||||||||||||||||||||||||||||||||||
| "type": "object", | ||||||||||||||||||||||||||||||||||||||||||||
| "properties": { | ||||||||||||||||||||||||||||||||||||||||||||
| "query": {"type": "string"}, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+94
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Clarify query parameter requirement in visualization tool schema The tool's schema defines a "query" property but doesn't mark it as required. Either:
types.Tool(
name="visualize",
description="Visualize the knowledge graph.",
inputSchema={
"type": "object",
"properties": {
"query": {"type": "string"},
},
+ "required": ["query"], # Add this if query is required
},
),📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: ruff format[warning] File requires formatting. Code does not conform to Ruff's formatting standards.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good suggestion from coderabbit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @borisarzentar Thank you for confirming! I'm glad the suggestion was helpful. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ |
||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def get_freshest_png(directory: str) -> Image.Image: | ||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.exists(directory): | ||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"Directory {directory} does not exist") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # List all files in 'directory' that end with .png | ||||||||||||||||||||||||||||||||||||||||||||
| files = [f for f in os.listdir(directory) if f.endswith(".png")] | ||||||||||||||||||||||||||||||||||||||||||||
| if not files: | ||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError("No PNG files found in the given directory.") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Sort by integer value of the filename (minus the '.png') | ||||||||||||||||||||||||||||||||||||||||||||
| # Example filename: 1673185134.png -> integer 1673185134 | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| files_sorted = sorted(files, key=lambda x: int(x.replace(".png", ""))) | ||||||||||||||||||||||||||||||||||||||||||||
| except ValueError as e: | ||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("Invalid PNG filename format. Expected timestamp format.") from e | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # The "freshest" file has the largest timestamp | ||||||||||||||||||||||||||||||||||||||||||||
| freshest_filename = files_sorted[-1] | ||||||||||||||||||||||||||||||||||||||||||||
| freshest_path = os.path.join(directory, freshest_filename) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Open the image with PIL and return the PIL Image object | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| return Image.open(freshest_path) | ||||||||||||||||||||||||||||||||||||||||||||
| except (IOError, OSError) as e: | ||||||||||||||||||||||||||||||||||||||||||||
| raise IOError(f"Failed to open PNG file {freshest_path}") from e | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @server.call_tool() | ||||||||||||||||||||||||||||||||||||||||||||
| async def handle_call_tool( | ||||||||||||||||||||||||||||||||||||||||||||
| name: str, arguments: dict | None | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -154,6 +194,22 @@ async def handle_call_tool( | |||||||||||||||||||||||||||||||||||||||||||
| text="Pruned", | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| elif name == "visualize": | ||||||||||||||||||||||||||||||||||||||||||||
| with open(os.devnull, "w") as fnull: | ||||||||||||||||||||||||||||||||||||||||||||
| with redirect_stdout(fnull), redirect_stderr(fnull): | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| result = await cognee.visualize_graph() | ||||||||||||||||||||||||||||||||||||||||||||
| results = retrieved_edges_to_string(result) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||
| types.TextContent( | ||||||||||||||||||||||||||||||||||||||||||||
| type="text", | ||||||||||||||||||||||||||||||||||||||||||||
| text=results, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| except (FileNotFoundError, IOError, ValueError) as e: | ||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Failed to create visualization: {str(e)}") | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return visualization output instead of text content. The visualization tool returns text content ( return [
- types.TextContent(
- type="text",
- text=results,
- )
+ types.ImageContent(
+ type="image",
+ data=await cognee.visualize_graph(),
+ format="png"
+ )
]
|
||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Unknown tool: {name}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add explicit permissions configuration.
Consider adding explicit permissions to follow the principle of least privilege:
docker-build-and-push: runs-on: ubuntu-latest + permissions: + contents: read + packages: write📝 Committable suggestion