Why use it
Use the global context index when answers often depend on document-wide or dataset-wide context:- long documents where important details are spread across chapters or sections
- evolving conversations where the final state depends on earlier updates
- project memory where the answer needs the overall plan, risks, and current status
- policy or research corpora where local facts need broader framing
- local evidence from the graph
- global orientation from compact dataset summaries
How it works
During ingestion, Cognee createsDocumentChunk nodes and extracts the entities each chunk mentions. The global context index reads those chunks and entities and adds the GlobalContextSummary layer shown inside the dashed lines:
- Bucket: the document’s name, then one
Type: name, nameline per entity type, then the relations between the bucket’s own entities. Entities are ranked by tf-idf over the dataset’s chunks, so a bucket leads with what sets its document apart (at most 20 entities and 40 relations). - Root: a
Topics:line (entity types, by how many entities carry them), anEntities:line (the names that appear in the most documents), and aDocuments:line (document names, by chunk count, with a(+N more)suffix past 40 documents).
What retrieval adds
Three search types read the index:GRAPH_COMPLETION, HYBRID_COMPLETION and HYBRID_COMPLETION_DECOMPOSITION. Other search types ignore include_global_context_index, including the graph completion variants such as GRAPH_COMPLETION_COT and GRAPH_COMPLETION_DECOMPOSITION.
When enabled, Cognee prepends a global context prelude before the usual retrieved context:
GlobalContextSummary. The Relevant areas are the top matching non-root GlobalContextSummary bucket texts for the query.
This gives the model a compact map before it reads the local graph facts. HYBRID_COMPLETION places the same prelude under a ## Global context heading at the top of its context block.
Build the index
improve() builds the index by default, so a plain improve() after memory has been created is enough. build_global_context_index=False skips it for one call, and IMPROVE_GLOBAL_CONTEXT_INDEX=false turns it off by default. Passing True builds it even when that setting is false:
improve() builds the global context index as its last stage. It needs no LLM key, so it also runs on a keyless setup; only the earlier cognify step extracts the entities, with the LLM or, on a keyless setup, the local GLiNER extractor.
Every build computes the whole index for the dataset, writes only the buckets and root whose text changed, and deletes the dataset’s index nodes it did not compute. That one rule covers new data and edited data. Deleting a document does not wait for a build: the deletion removes the document’s bucket and the dataset’s root right away, because the root names every document. For an index built by the default method, the root is then written again at once from the documents that remain. This takes one graph read and one embedding of a short text, with no LLM call. The other buckets keep their text until the next build. An index built with method="llm" gets no root until its next build, because its root summarizes bucket summaries that still describe the deleted document. Neither does a dataset whose last document was deleted. If the rebuild fails, for example because the embedding provider cannot be reached, the deletion still succeeds: a warning is logged and the root stays absent until the next improve(). Deletion only touches the dataset’s own index nodes, even when datasets share one graph.
When nothing but reads (search, recall, or an improve() that ran no stage) has touched the dataset since the last build, the stage reports already_completed with the reason no_writes_since_last_improve and rewrites nothing. Any other run on the dataset counts as a change, including a failed run and a forget(). With ENABLE_BACKEND_ACCESS_CONTROL=false, datasets share one graph, so a run on any dataset counts.
If the build itself fails,
improve() logs a warning and still returns successfully — the index is simply absent, and search falls back to normal graph context.LLM-written summaries (opt-in)
improve() always uses the entity-counting method above. The older method, which groups TextSummary nodes into hierarchical buckets and writes each bucket and the root with one structured-output call to LLM_MODEL, is still available through the lower-level pipeline with method="llm":
bucketing_strategy, max_bucket_size, placement_distance_threshold, min_overlap, and rebuild apply only to method="llm". Pass rebuild=True when switching an index built by the default method over to method="llm": the LLM method extends the buckets it finds, and per-document buckets are not its shape. Switching the other way needs nothing, because the default method deletes every index node it did not compute. A later improve(build_global_context_index=True) run replaces an LLM-written index with the entity-counting one.
Use it during search
Enable it throughretriever_specific_config on graph completion search:
only_context=True — for a completion search type the result’s text is the full user prompt, with the World summary: and Relevant areas: prelude inside it:
Scope to a dataset
Each index belongs to exactly one dataset.improve(dataset=...) builds it for that dataset only, and every GlobalContextSummary node it writes stores that dataset’s dataset_id.
To choose which dataset’s summary retrieval uses, pass that dataset in datasets=[...] on recall(). Each listed dataset is searched in its own database context, so the World summary and Relevant areas come from that dataset’s root and buckets. This scoping relies on backend access control, which gives each dataset its own graph and vector stores. It is on by default when your databases support it. When ENABLE_BACKEND_ACCESS_CONTROL=false, all datasets share one graph and one GlobalContextSummary_text collection, and retrieval does not filter by dataset.
To read one dataset’s root summary directly, enter that dataset’s database context and filter its graph nodes:
recall(), this dataset_id filter still returns the right root when access control is off and datasets share one graph.
Dataset routing
The index also decides which datasets an unscoped search covers. Whenrecall() or search() is called without datasets or dataset_ids, every readable dataset is scored against the query by its root and buckets, and only the best matches are searched. See Dataset routing. Each build mirrors the dataset’s root and bucket vectors into a routing collection in the deployment’s default vector store (the one VECTOR_DB_URL configures), so one query can score every dataset in one place. The routing rows are copies of the index rows, vectors included, so nothing is embedded twice. When a document is deleted, the rebuilt root is copied into the routing collection too, so broad unscoped queries keep routing to the dataset.
A dataset without an index is not searched next to a routed dataset: an unscoped search covers it only when no dataset is routed, or when the routed datasets retrieve nothing. Turning the index off (IMPROVE_GLOBAL_CONTEXT_INDEX=false, improve(build_global_context_index=False), or IMPROVE_STAGES_DISABLED=global_context_index) leaves routing nothing to score that dataset with; routing still runs for the datasets that do have an index. Routing is inactive with ENABLE_BACKEND_ACCESS_CONTROL=false.
Configuration
Benefits and tradeoffs
The main benefit is better long-range coherence. The model can see a compact summary of the dataset before it reasons over the retrieved graph context. This can reduce failures where local retrieval finds a relevant fragment but misses the broader story. The tradeoff is that the index is lossy. A bucket summary is an orientation aid, not a replacement for source chunks or graph facts. The most reliable answers still come from combining global context with precise retrieved evidence. Building the index is cheap. It makes no LLM call: it reads the dataset’s chunks and entities once, and embeds only theGlobalContextSummary texts that changed into their own vector collection. A run with no writes since the last build is skipped outright. Because the texts are lists of names and relations rather than prose, they orient the model but do not explain.
At search time the cost is small and fixed: one lookup for the root summary and one vector search for the top global_context_index_top_k buckets, plus the extra prompt tokens the prelude adds.
When not to use it
You may not need the global context index when:- your dataset is small enough that normal retrieval already has enough context
- queries are mostly simple fact lookups
- you need the fastest possible
improve()run - you want retrieval context to contain only direct local graph evidence
Building the Global Context Index
A runnable guide: build the index, inspect its root/bucket structure, and see it update incrementally as new data arrives.
Reading the Global Context Index
A runnable guide: see exactly what include_global_context_index adds to GRAPH_COMPLETION retrieval, and what stays the same.