Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt

Use this file to discover all available pages before exploring further.

The Cognee Python SDK connects to Cognee Cloud via cognee.serve(). Once connected, all operations (remember, recall, forget, improve) route to your cloud tenant.
The same cognee package is used for both local and cloud workflows. The only difference is calling cognee.serve() to connect to a remote instance.

Install

pip install cognee

Complete example

import asyncio
import cognee

async def main():
    # Connect to Cognee Cloud (opens browser for login)
    await cognee.serve()

    # Store content in memory — ingests, builds knowledge graph, enriches
    await cognee.remember(
        "Cognee Cloud automates knowledge graph creation in the cloud.",
        dataset_name="demo_dataset",
    )

    # Retrieve from memory
    results = await cognee.recall(
        query_text="What does Cognee Cloud automate?"
    )
    for result in results:
        print(result)

    # Disconnect when done
    await cognee.disconnect()

asyncio.run(main())

What just happened

Connecting to cloud

There are two ways to connect to Cognee Cloud: OAuth / device-auth (default) — Opens a browser window for login. Best for interactive development.
await cognee.serve()
After authentication, the SDK discovers your cloud tenant and connects to it. Credentials are cached at ~/.cognee/cloud_credentials.json — subsequent calls reconnect without re-authenticating until the token expires. Direct mode — Pass the tenant URL and API key explicitly. Best for CI, scripts, or self-hosted/staging environments.
await cognee.serve(
    url="https://your-tenant.aws.cognee.ai",
    api_key="your-api-key"
)
You can also set these as environment variables (COGNEE_SERVICE_URL and COGNEE_API_KEY) instead of passing them inline. Create an API key from the API Keys page in the Cognee Cloud console.

Storing data

await cognee.remember(
    "Cognee Cloud automates knowledge graph creation in the cloud.",
    dataset_name="demo_dataset",
)
remember ingests data and builds the knowledge graph in a single call. Data is organized by dataset for isolation and permissions. For more control, use the lower-level add and cognify operations separately.

Retrieving data

results = await cognee.recall(
    query_text="What does Cognee Cloud automate?"
)
recall auto-routes the query to the best retrieval strategy. For direct control over search types, see Search Basics.

Disconnecting

await cognee.disconnect()
Closes the connection to the cloud tenant. Credentials remain cached for the next session.

Next steps

Cloud functionality

Explore the full API surface available in Cognee Cloud.

Connect an agent

Give any agent framework persistent memory through Cognee.