Skip to main content

When to use this

After cognify, entity descriptions may be fragmented or repetitive because each description is derived from a single chunk. This pipeline rewrites each entity’s description using the LLM and the entity’s full neighborhood context (edges and neighbors), producing more coherent and complete descriptions. Before you start:
  • Complete Quickstart to understand basic operations
  • Ensure you have LLM Providers configured
  • Have an existing knowledge graph with Entity nodes (add → cognify completed)

Code in Action

import asyncio
import cognee
from cognee.memify_pipelines.consolidate_entity_descriptions import (
    consolidate_entity_descriptions_pipeline,
)

async def main():
    await cognee.prune.prune_data()
    await cognee.prune.prune_system(metadata=True)
    await cognee.add(
        [
            "Alice moved to Paris in 2010, while Bob has always lived in New York.",
            "Andreas was born in Venice, but later settled in Lisbon.",
            "Diana and Tom were born and raised in Helsinki. Diana currently resides in Berlin, while Tom never moved.",
        ]
    )
    await cognee.cognify()

    await consolidate_entity_descriptions_pipeline()

asyncio.run(main())

What Just Happened

  1. Prune — clears existing data and metadata so the example starts fresh.
  2. Add + Cognify — builds a knowledge graph with Entity nodes for each person and location.
  3. consolidate_entity_descriptions_pipeline() — loads each entity along with its graph neighbors and edges, sends the context to the LLM, and writes back a refined description.

What Changed in Your Graph

  • Existing Entity node description fields are rewritten using LLM analysis of each entity’s neighbors and edges.
  • No new nodes are created. The pipeline updates descriptions in place.
  • Descriptions become more coherent because the LLM sees each entity in the context of its graph neighborhood, not just the original chunk text.
Three tasks run in sequence:
  1. get_entities_with_neighborhood — loads all Entity nodes and fetches their edges and neighbor nodes.
  2. generate_consolidated_entities — sends each entity + neighborhood to the LLM, which returns a refined description.
  3. add_data_points — writes the updated Entity objects back to the graph and vector DB.
  • No entities found — the graph must contain Entity nodes. Run cognee.add() and cognee.cognify() first.
  • LLM errors — verify that your LLM provider is configured. See LLM Providers.
  • Permission errors — the user must have write access to the target dataset. See Permissions.