add() and cognify() hides all of it behind two function calls.
What You’ll Build
A short paragraph of text about natural language processing goes in, and a queryable knowledge graph comes out — except neitheradd() nor cognify() is ever called. The add stage is reassembled by hand from the two Task objects it wraps, and the cognify stage is run from the task list cognify() itself would have used, both handed to run_custom_pipeline(). A final GRAPH_COMPLETION search over the result proves the hand-driven graph is an ordinary cognee graph.
The complete runnable script is
examples/demos/custom_pipelines/custom_cognify_pipeline_example.py —
this page walks through its key moments rather than reproducing it.
Features in Play
- Custom Tasks and Pipelines —
run_custom_pipeline()executes both stages from task lists the script controls - Tasks —
Task(...)wrapsresolve_data_directoriesandingest_datatogether with the arguments they need - Add — the ingestion stage this demo reconstructs from its two underlying tasks
- Cognify —
get_default_tasks()hands over the real graph-building task list instead of running it - Inspecting Graph Completion Context —
SearchType.GRAPH_COMPLETIONqueries the graph the custom pipelines built
Before You Start
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured — the cognify task list makes live LLM calls to extract entities and relationships. The script’s own header asks you to copy
.env.templateto.envand setLLM_API_KEY - Run it from a checkout of the cognee repo: it imports internals such as
cognee.modules.pipelines.Taskandcognee.api.v1.cognify.cognify.get_default_tasks, and the command below uses the repo-relative path - The script begins with
prune_data()andprune_system(metadata=True), which wipe data and system state including users and pipeline runs — point it at a scratch instance rather than memory you want to keep
How It Works
Stage 1: Reset and Initialize the Databases
metadata=True drops the relational database, so the tables the pipelines write to have to be recreated before anything runs. setup() is the call the high-level operations make for you; driving pipelines directly means making it yourself.
Stage 2: Rebuild the Add Stage from Tasks
add() does underneath: resolve whatever was passed into concrete data items, then ingest them into a dataset. A Task carries its own arguments — the dataset name and user are bound into ingest_data here — while the pipeline supplies the data flowing through. Naming the run add_pipeline keeps it identifiable in the pipeline-run history.
Stage 3: Borrow the Default Cognify Task List
data argument is needed: the tasks pick up the data items the add pipeline already wrote to main_dataset.
Stage 4: Query the Hand-Built Graph
search() closes the loop. Nothing about the query is aware that the graph was built task by task — which is the point of the demo: the custom pipeline path produces the same graph the built-in operations do.
Run It
Text added successfully. once the add pipeline finishes. The cognify pipeline announces that it is recreating the existing cognify pipeline, takes the longest as it makes its LLM calls, and ends with Cognify process complete. The script then reports the query it is running and prints Search results: followed by the generated answer about natural language processing.
Where to Change It
Both stages are plain Python lists ofTask objects, so this is the shape to start from when the built-in flow is close to what you want but not exact. get_default_tasks() returns the cognify list, and you can reorder it, drop a task, or splice your own in before passing it to run_custom_pipeline() — see Custom Tasks and Pipelines for writing that task. It also takes the knobs cognify takes, including graph_model and chunker, if adjusting the arguments is enough.
Custom Tasks and Pipelines
Write your own task and run it in a pipeline of your own.
Tasks
What a
Task wraps, and how its arguments and batching work.run_custom_pipeline()
Every parameter of the entry point both stages are run through.
Cognify
The operation whose default task list this demo runs by hand.