Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

128 lines
4.9 KiB
Python

import argparse
import asyncio
from cognee.cli.reference import SupportsCliCommand
from cognee.cli import DEFAULT_DOCS_URL
import cognee.cli.echo as fmt
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
# Tiny constants-only import; the cognee package is already loaded by the CLI.
from cognee.modules.migration.sources.base import IMPORT_MODES
class PushCommand(SupportsCliCommand):
command_string = "push"
help_string = "Upload a local dataset's knowledge graph to Cognee Cloud"
docs_url = DEFAULT_DOCS_URL
description = """
Upload a local dataset's knowledge graph to a Cognee Cloud instance.
The dataset's graph is exported as a COGX archive and imported on the remote
instance, preserving locally extracted entities and relationships instead of
re-deriving them from raw files.
Authentication reuses the serve credentials: run `cognee serve` once to log
in, then push any time. Alternatively pass --url/--api-key or set
COGNEE_SERVICE_URL and COGNEE_API_KEY.
Import modes:
preserve (default) map exported entities/facts directly — zero LLM calls
hybrid preserve the graph and also cognify the raw content
re-derive ignore the exported graph, rebuild from raw content remotely
Examples:
cognee push # push main_dataset
cognee push my_dataset
cognee push my_dataset --target-dataset prod_dataset
cognee push my_dataset --mode hybrid
cognee push --url https://my.cognee.ai --api-key ck_...
"""
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"dataset",
nargs="?",
default="main_dataset",
help="Local dataset name to push (default: main_dataset)",
)
parser.add_argument(
"--target-dataset",
help="Dataset name on the remote instance (default: same as local)",
)
parser.add_argument(
"--mode",
choices=list(IMPORT_MODES),
default="preserve",
help="Remote import mode (default: preserve)",
)
parser.add_argument(
"--url",
help=(
"Remote instance URL (default: active serve connection, "
"COGNEE_SERVICE_URL, or saved serve credentials)"
),
)
parser.add_argument(
"--api-key",
help="API key for the remote instance",
)
parser.add_argument(
"--background",
"-b",
action="store_true",
help=(
"Schedule the remote import in the background and return after the "
"upload (recommended for large graphs); prints the pipeline run id"
),
)
def execute(self, args: argparse.Namespace) -> None:
try:
import cognee
fmt.echo(f"Pushing dataset '{args.dataset}' to Cognee Cloud...")
async def run_push():
try:
from cognee.api.v1.push.push import _resolve_client
from cognee.cli.user_resolution import resolve_cli_user
# Resolve once up front so the target host is visible
# before the upload starts.
client, created = _resolve_client(args.url, args.api_key)
fmt.echo(f"Remote instance: {client.service_url}")
if created:
await client.close()
user = await resolve_cli_user(getattr(args, "user_id", None))
return await cognee.push(
args.dataset,
target_dataset=args.target_dataset,
mode=args.mode,
run_in_background=args.background,
url=args.url,
api_key=args.api_key,
user=user,
)
except Exception as e:
raise CliCommandInnerException(f"Failed to push: {str(e)}") from e
result = asyncio.run(run_push())
if args.background and result.status == "started":
fmt.success(
f"Uploaded {result.num_nodes} nodes and {result.num_edges} edges; "
f"remote import of dataset '{result.target_dataset}' is running in "
f"the background (pipeline run id: {result.pipeline_run_id or 'n/a'})."
)
else:
fmt.success(
f"Pushed {result.num_nodes} nodes and {result.num_edges} edges "
f"to remote dataset '{result.target_dataset}'."
)
except Exception as e:
if isinstance(e, CliCommandInnerException):
raise CliCommandException(str(e), error_code=1) from e
raise CliCommandException(f"Error during push: {str(e)}", error_code=1) from e