What is the cognify operation
cognify turns data stored by add into a knowledge graph plus vector indexes. remember runs it for you.
What happens under the hood
Turns stored data into a knowledge graph in four stages: classify documents → chunk text → extract entities/relationships (LLM) and summarize (conditional), then add data points (six vector collections, plusDltRow_text for DLT rows, and provenance to the relational DB) — one
streaming stage that saves each document as soon as all its extraction and
summary results are in: every chunk’s calls go through one bounded stream (no
batch barrier), each finished document’s graph is built on the CPU pool and
saved by a single writer in input order, and at most
cognify.max_unsaved_documents
documents are in progress at once → extract DLT FK edges, after the run. A DLT row (a document whose external_metadata has
source: "dlt") is one DltRow chunk indexed into DltRow_text, not
DocumentChunk_text; the last step adds its SchemaTable, SchemaRelationship
and DltColumn nodes (vector collections SchemaTable_name,
SchemaTable_description, SchemaRelationship_name,
SchemaRelationship_description and DltColumn_properties) and the row edges.
Datasets cognified before this layout need a re-cognify after deleting their
old graph and vector rows. Configurable via CognifyConfig
(chunk strategy, custom prompts/schemas). Pipeline:
cognee-cognify (cognify() / cognify_datasets()).
Every write of a run goes through one persistence layer, in a fixed order:
ownership-ledger rows first, then every graph node, then every graph edge,
then the vectors, then the edge evidence. Under the default failed_items
rollback scope, the writer marks each document complete right after saving it, and a
failed run keeps what it completed (see
When a cognify run fails). When a later document of the run changes an entity an earlier one
saved (a new type, a new node set, or a real extraction replacing an ontology
placeholder), the entity’s graph node, vector point and ownership rows are
rewritten so the result matches a run saved at once; its description,
importance weight and metadata stay those of the first document. Under
FailFast, a failed extraction also stops the summary calls and vice versa,
and a failed save stops both. Under the default failed_items rollback scope a
failed save fails only that document (FailureStage::Persistence), which is
removed while the run goes on and errors at the end; under whole_run and
nothing it fails the run at once.
The ownership ledger names the documents: every entity, entity type, is_a,
contains, is_part_of and made_from edge, every entity first seen through
an ontology lookup, and every ontology edge a document’s lookup brought in
(when the document owns both endpoints) gets an ownership row per producing
document, so deleting a document
removes the types and edges only it produced. An ontology edge the graph
already holds is not written again, but each such document still claims it
with a row of its own.
Shared SQLite with Python. Python cognee’s alembic revision f2b4c6d8e0a1
moves every external_metadata.source of "dlt" / "dlt_source" into
system_metadata, Rust-written rows included. A per-row DLT record whose stamp
was moved (system_metadata.source == "dlt") is then refused as a legacy
record (CognifyRouteError::LegacyDltRecord), even when an earlier run
completed it. A moved "dlt_source" manifest is refused too
(UnsupportedRoute): Rust has no DLT-source route. Delete such rows and
re-add the data.
Code items
Each item first takes its route (cognee_cognify::routing), read from its
system_metadata. Code items run the deterministic code graph instead of the
stages above: an enola --generate run whose snapshot is mapped to code nodes
and typed edges
(cognee-code-graph),
recorded in the ownership ledger, with no LLM and no embedding call. Every other
item runs the stages above. Both kinds share one pipeline run and its
completion markers, and a run whose items are all code-routed resolves no
graph extractor, so a deployment without an LLM key builds a code project’s
graph. enola must be installed: see
Configuration: code graph.
- A code project’s repo item (
code_repo, from adding a code-project directory) runs enola over the original directory and tags the code nodes with the item’s node set. The load is incremental: an unchanged snapshot of an untagged repository is skipped, and a changed one writes only changed facts, sweeps the nodes and edges that left it and strips node-set tags the call no longer passes. The sweep reads every code node and node set by type, so a stale code node that lost itspart_ofedge is swept too. A load retried after a failed edge write restores the missing structural edges (part_of,belongs_to_set) of the whole snapshot, so the retry ends with every edge. A timed-out enola run is killed before the timeout error returns. Forgetting the item removes its code graph and leaves other repositories’ alone. - Several repositories in one dataset are one enola cluster: the run’s
first repo item runs enola once over all of them (into each one’s
.enola-<dataset_id>) and loads every repository from that snapshot, each under its own item, with the edges between them (a frontend call to the backend route that serves it); the run’s other repo items have nothing left to do. - A per-file code item (
source: "code", a lone source file added throughcode_loader) loads the code graph of that one file: its stored text is staged in a temporary directory under its original name (plus atsconfig.jsonfor plain JavaScript) and enola runs on it, as a repository named<file name>_<data id>, untagged. Such an item used to fail the whole run withCognifyRouteError::UnsupportedRoute.
CodeGraph); one that loaded counts as a survivor. A DLT source stamped in
system_metadata (dlt_source) is not supported yet, and a row whose
system_metadata says source: "dlt" (a pre-manifest DLT record) is refused;
each fails the whole run before any work. The DLT rows above, stamped in
external_metadata, are not affected. The bindings still validate a
graphBackend or non-blank extractor the caller passes; the CLI’s
cognify --extractor is not checked for an all-code run.
The cognify routes are always graph-only: only
remember(content_type="code", index_vectors=true)
embeds code nodes. The
CODE search type
reads the code graph itself, so it needs no vectors.
Writing vectors
The add data points stage embeds and writes each vector collection in windows of about 16 MiB of vector data (cognee_vector::write_window_points,
around 2,700 points at 1536 dimensions), so memory on the write path does not
grow with the corpus. By default the generated vectors are not kept in the
result: CognifyResult.embeddings is empty unless
CognifyConfig::with_retained_embeddings(true) (field retain_embeddings,
default false) is set. The vectors are in the vector store either way, and
CognifyResult.embedding_count reports how many chunk, entity and summary
embeddings the run generated. Code that read embeddings.len() should read
embedding_count instead.
Dates and Timestamp nodes
Dates come out of the default extraction, with no separate temporal pipeline (the event-graph temporal cognify was removed; see Temporal Cognify): a node the LLM typesTimestamp whose name is an absolute time
(1867, 1969-07, 23 March 1947, from 1803 to 1815) becomes a shared
Timestamp graph node — one per normalized time string, carrying
time_at/time_until (ms since the epoch, UTC, half-open) and its
precision — that *_at edges point at and every chunk naming it contains.
Timestamps are not embedded. A name that does not parse stays an ordinary
entity. Year-less dates in the text (“27 April”, “four weeks later”) are
resolved against the last stated year earlier in the document and handed to the
default prompt as normalization hints; a custom prompt receives none.
Entity ids
An extracted entity’s id derives from its name (Entity.id_for(name)), so
the same name from two chunks or documents is one node; several nodes
sharing a name inside one chunk’s graph get deterministic ordinal ids instead.
This is a breaking change: earlier Rust releases keyed entities on the LLM’s
node id, so re-cognifying a dataset built before it adds the name-based entities
beside the old ones. Rebuild such a dataset from scratch to avoid the duplicates.
An extracted node with an empty type gets no EntityType and no is_a edge.
The graph is built per data item (or per block of chunks_per_batch chunks of
one), each with fresh maps, and the blocks are then merged. Within a block the
first type given to an entity wins; across data items an entity keeps every
type, in first-seen order, so it can have several is_a edges, each
EntityType written and indexed. The is_a edges are the entity’s stored type
set: Entity.extra_types (the types after is_a) is in memory only and is no
longer serialised into graph nodes, ledger rows, vector payloads or COGX
exports (a payload that holds it still deserialises). The first data item in input order decides an entity’s description,
importance weight and metadata; NodeSet membership is combined. An extracted
edge’s endpoint never matches a node of another data item;
cognify.cross_chunk_endpoints
decides whether it may match a node an earlier chunk of the same block
declared. Existing graphs are not migrated: an entity gains further types only
when its data is cognified again (with incremental_loading off, or re-added).
Deleting a document removes the is_a edges and EntityTypes only it
contributed; data cognified by earlier releases keeps nil-data_id ledger
rows for them, which still claim them until their dataset is deleted.
Relationship labels are normalised before they are stored (lowercase, spaces
to underscores, apostrophes dropped), so Born In and born_in are one
born_in edge, and Is A or Contains become is_a and contains. Before
writing, cognify asks the graph which of the edges it built already exist, on
their final ids and labels; those are claimed (an ownership row, no graph
write). An ontology edge the graph already holds is not written again, but the
document still gets an ownership row for it when it owns both endpoints. Graphs built before this are not migrated:
cognifying the same data again adds a normalised copy of every edge whose label
was not already normalised (works at gains works_at), and the raw copy stays
until the data that produced it is deleted.
COGNEE_COGNIFY_EXTRACTION_STRATEGY=cascade swaps the single extraction call
for a multi-round cascade (see
configuration).
When a cognify run fails
A chunk or a file the pipeline cannot process is not a bare error: the chunking, graph-extraction and summarization stages collect their failures, and the run result carries a report naming which file, which chunk, which stage and what went wrong.CognifyResult.failures carries it on success;
CognifyError::RunFailed carries the same report when the run failed.
What happens to what the run already wrote is decided at the end, from two
independent settings — when to stop (FailFast, the default, or RunToEnd)
and what to sweep (WholeRun, FailedItems, or Nothing; unset, it is
FailedItems with incremental_loading — the default — and WholeRun
without). The
full matrix is in
Cognify failure handling; the end
states are:
WholeRun(the default withincremental_loadingoff). UnderFailFastthe run stops dispatching at the first failure — not at a file boundary, see below — everything it created is removed, the run is recordedERROREDand the call returnsErr. The store converges to its pre-run state — what earlier runs completed is untouched, because the sweep selects only rows naming this run.FailedItems(the default withincremental_loading). A run in which any file failed is recordedERROREDand returnsErrwith the failed-file list in its report — but keeps the files it completed, indexed and marked. Each file is saved and marked complete as soon as it is done, so only what the run did not complete is removed, and the next run redoes exactly the failed files. The chunk failure ratio no longer decides anything.Nothingremoves nothing. The escape hatch (code only — not selectable from the environment): the files saved before a stop stay, unmarked, and nothing more is saved after it.
FailFast a run partitions its files three ways at the abort point:
complete (every call back — persisted and marked), failed (at least one
chunk failed, or its save failed) and unreached (never attempted). Only
complete files are kept, which is what keeps a data item all-or-nothing;
failed and unreached files are indistinguishable to the next run and are
simply redone. A DLT row is complete only once the post-run step has written
its foreign-key edges; a code item once its graph is loaded.
The abort point is not a file boundary, and how much work FailFast actually
saves depends on how many calls are in flight. Graph extraction and
summarization each run every chunk of the run through one stream, with no
barrier between chunks_per_batch blocks: both stop dispatching as soon as a
failure comes back from either one, but the calls already in flight (up to
max_parallel_extractions) are neither cancelled nor discarded, unless a save
fails and stops the run, which aborts them. A file with a
chunk that was never dispatched is unreached, even if its other chunks
succeeded. A graph backend is the exception: it is handed chunks_per_batch
chunks per call and stops after the call that failed.
FailFast is an upper bound on wasted spend, not a promise of none.
A sweep deliberately keeps anything still claimed from outside its scope: an
entity a surviving file also produced, an artifact another run or another
dataset also names, or a row written before ownership tracking existed. The
worst case is a surplus artifact that keeps an owner, never an artifact with no
owner at all.
That claim is recorded even when the artifact is not written. Graph extraction
filters out edges the graph already holds, so a file cognified in a later run
adds no second copy of an edge an earlier file created — but it still records
ownership of it. Without that row the earlier file would be the edge’s only
owner, and deleting it would take the edge’s vectors away from a file that still
references it. Ownership is per (dataset, data item): an edge shared across two
datasets is still governed by each dataset’s own exclusivity check, the same
limitation entity ownership has.
One caveat. Cancellation is swept — though there is no
caller-facing cancel handle on cognify() today, and simply dropping the future
runs no sweep at all.
For a run that was killed (not failed in-process), see
Serialization and recovery of pipeline runs
and cognee-cli edge-reindex in the CLI Reference.
Re-cognifying is incremental
incremental_loading is on by default and now does what it says. A run marks
each data item it finished, in Python’s own pipeline_status format — under
FailedItems the moment the item is saved, under WholeRun once the run
succeeded — and the next run skips the marked items before it builds a pipeline — no
classification, no chunking, no LLM calls.
A failed run keeps the marks of the files it completed (none under WholeRun),
and a sweep clears the markers of whatever it rolled back, so the next run redoes exactly the work that was lost.
The markers live under Python’s one cognify_pipeline key. See
Completion markers and incremental loading.
What became of each item
CognifyResult::items says, per data item handed to cognify() and in that
order, what the run did with it, as an ItemOutcome { data_id, status }. The
ItemStatus is one of:
A run that errors with
CognifyError::RunFailed carries the same list on its
report (FailureReport::item_outcomes(), or CognifyError::item_outcomes()),
read after the run’s rollback, so Completed names only kept documents. The
list holds ids and statuses only; a host reads an item’s source fields from its
Data row. Completed does not promise a completion marker: none is written
without incremental_loading, and a failed marker write only warns.
ItemStatus and ItemOutcome are #[non_exhaustive] (ItemOutcome::new
builds one), and a CognifyResult struct literal now needs items: vec![].
Related
Add
The step before cognify
Search
Query the graph
Cognify configuration
Chunking, extraction and failure settings