Skip to main content

Data Models

Key Pydantic models and types used in the cognee Python API.

SearchResult

Returned by cognee.search().

PipelineRunInfo

Returned by cognee.add(), cognee.cognify(), and pipeline functions.
Status values: PipelineRunStarted, PipelineRunYield, PipelineRunCompleted, PipelineRunAlreadyCompleted, PipelineRunErrored

data_ids

data_ids is computed from data_ingestion_info: the ids of the Data rows the run processed, in result order, without duplicates. Items that errored are left out. Items that already existed with the same content (PipelineRunAlreadyCompleted) are included, because the existing row holds that content. For add(), use these ids for later update() or datasets.delete_data() calls instead of working them out from the content yourself. data_ids is None, and the key is left out of serialized output, when the run info has no data_ingestion_info. This covers PipelineRunStarted, progress updates, the run infos nested inside data_ingestion_info entries, and add(run_in_background=True), which returns before the items are stored. The field is serialized with the model, so POST /api/v1/add responses include it too.

data_ingestion_info entries

Each entry describes one data item the run handled: data_name, data_location and data_label are set on the incremental path, which runs when incremental_loading or data_cache is True (both are by default). They are filled for failed items too, so you can tell which files in a folder failed, but only with RAISE_INCREMENTAL_LOADING_ERRORS=false: by default a failing item aborts the run and the error is raised instead of returned. Use them to match ids to inputs: data_ids does not line up one-to-one with what you passed in. A PipelineRunErrored run info additionally carries error_class: str | None and error_message: str | None (PII-scrubbed) naming the root cause of the failure. See Failed runs for how to read them.

Task

Wraps a callable for use in pipelines.
Callable
required
The function to execute. Can be an async generator, generator, coroutine, or regular function.
dict
default:"{\"batch_size\": 1}"
Task configuration, primarily batch size.

DataPoint

The public base class for all user-defined graph entities. Extend DataPoint to create custom node types that Cognee can index, search, and connect in the knowledge graph.
Key methods: to_json(), from_json(), to_dict(), from_dict(), update_version() See DataPoints and Custom Data Models for usage details.

KnowledgeGraph

Default graph model used by cognify() and remember() as an internal extraction format. With no graph_model argument, it is filled once per chunk by the LLM, or, when no LLM key is configured, by the GLiNER demo extractor. It is a plain Pydantic model, not a DataPoint, and is never stored as it is. It is not exported from the top-level cognee package and is not intended for user extension.
When LLM_PROVIDER=gemini, a Gemini variant is selected at import. It also requires summary: str and description: str on KnowledgeGraph and label: str on Node, to work around a Gemini structured-output restriction. Graph construction reads only nodes and edges in both variants.
Node and the Edge type nested inside KnowledgeGraph are used as internal pipeline types during extraction, rather than as user-facing extension points. For custom entities and application models, use DataPoint subclasses instead.

Node (internal)

Edge (internal)

How a filled KnowledgeGraph is stored

Cognee turns each chunk’s KnowledgeGraph into Entity, EntityType and Timestamp nodes, contains edges from the chunk, and the extracted relationships:
  • Node.id is local to one chunk’s graph: edges use it to name their endpoints, but it is not the stored id. The stored Entity id comes from name, so the same name in different chunks or documents becomes one node. Two nodes with the same name in one chunk graph stay separate. If two nodes in one chunk graph share an id, only the first is kept.
  • Node.type becomes an EntityType node the entity points to with is_a. A blank type creates none. A node of type Timestamp whose name is a normalized time (YYYY, YYYY-MM, YYYY-MM-DD, …) becomes a Timestamp node, which SearchType.TEMPORAL uses to find facts by date.
  • An edge whose endpoint is not among the chunk’s nodes is skipped. Relationships already in the graph are not written again. Edge.description becomes the stored edge’s text and, with the default SUMMARY_METHOD=from_extraction, a line of the chunk’s summary.

Exceptions

All cognee exceptions inherit from CogneeApiError: