Skip to main content
A minimal guide to running a small enrichment pass over your existing knowledge graph to add useful derived facts (e.g., coding rules) without re-ingesting data. Before you start:
  • Complete Quickstart to understand basic operations
  • Ensure you have LLM Providers configured
  • Have an existing knowledge graph (add → cognify completed)

What Memify Does

  • Pulls a subgraph (or whole graph) into a mini-pipeline
  • Applies enrichment tasks to create new nodes/edges from existing context
  • Defaults: extracts relevant chunks and adds coding rule associations

Code in Action

import asyncio
import cognee
from cognee.modules.search.types import SearchType

async def main():
    # 1) Add two short chats and build a graph
    await cognee.add([
        "We follow PEP8. Add type hints and docstrings.",
        "Releases should not be on Friday. Susan must review PRs.",
    ], dataset_name="rules_demo")
    await cognee.cognify(datasets=["rules_demo"])  # builds graph

    # 2) Enrich the graph (uses default memify tasks)
    await cognee.memify(dataset="rules_demo")

    # 3) Query the new coding rules
    rules = await cognee.search(
        query_type=SearchType.CODING_RULES,
        query_text="List coding rules",
        node_name=["coding_agent_rules"],
    )
    print("Rules:", rules)

if __name__ == "__main__":
    asyncio.run(main())
This simple example uses basic text data for demonstration. In practice, you can enrich large knowledge graphs with complex derived facts and associations.

What Just Happened

Step 1: Build Your Knowledge Graph

await cognee.add([
    "We follow PEP8. Add type hints and docstrings.",
    "Releases should not be on Friday. Susan must review PRs.",
], dataset_name="rules_demo")
await cognee.cognify(datasets=["rules_demo"])
First, create your knowledge graph using the standard add → cognify workflow. Memify works on existing graphs, so you need this foundation first.

Step 2: Enrich with Memify

await cognee.memify(dataset="rules_demo")
This runs the default memify tasks on your existing graph. No data parameter means it processes the existing graph, optionally filtering with node_name and node_type.

Step 3: Query Enriched Data

rules = await cognee.search(
    query_type=SearchType.CODING_RULES,
    query_text="List coding rules",
    node_name=["coding_agent_rules"],
)
Search for the newly created derived facts using specialized search types like SearchType.CODING_RULES.

What Changed in Your Graph

After memify completes, the graph contains:
  • Rule nodes — each rule extracted by the LLM from your document chunks (e.g., “Follow PEP8”, “Susan must review PRs”).
  • rule_associated_from edges — connecting each Rule node back to the DocumentChunk it was derived from.
  • coding_agent_rules node set — all rules are grouped under this node set, which is what SearchType.CODING_RULES queries against.
You can verify this by visualizing the graph before and after running memify.
  • dataset (str, default: "main_dataset") — the dataset to process. Must match the dataset you used in cognee.add() and cognee.cognify().
  • node_name (List[str], default: None) — filter the graph to nodes with these names. Useful when you want to process only a subset of your graph.
  • node_type (Type, default: NodeSet) — filter the graph to nodes of this type. Combined with node_name for targeted enrichment.
  • run_in_background (bool, default: False) — if True, memify returns immediately and processes in the background.

Customizing Tasks (Optional)

from cognee.modules.pipelines.tasks.task import Task
from cognee.tasks.memify.extract_subgraph_chunks import extract_subgraph_chunks
from cognee.tasks.codingagents.coding_rule_associations import add_rule_associations

await cognee.memify(
    extraction_tasks=[Task(extract_subgraph_chunks)],
    enrichment_tasks=[Task(add_rule_associations, rules_nodeset_name="coding_agent_rules")],
    dataset="rules_demo",
)
You can customize the memify pipeline by specifying your own extraction and enrichment tasks.

What Happens Under the Hood

The default memify tasks are equivalent to:
  • Extraction: Task(extract_subgraph_chunks) - pulls relevant chunks from your graph
  • Enrichment: Task(add_rule_associations, rules_nodeset_name="coding_agent_rules") - creates new associations and rules
This creates derived knowledge without re-processing your original data.

Additional examples

Additional examples about Memify are available on our github.
  • Empty rules / no results from CODING_RULES search — the input text may be too short or unrelated to coding practices. Memify’s default pipeline extracts coding rules; it works best with text that contains development guidelines, conventions, or process descriptions.
  • Error: no graph data found — run cognee.add() and cognee.cognify() before calling cognee.memify(). Memify operates on an existing knowledge graph.
  • LLM errors — verify that your LLM provider is configured correctly. See LLM Providers.
  • Permission errors — the user must have write access to the target dataset. See Permissions.

Custom Data Models

Learn about custom data models

Custom Tasks

Learn about custom tasks and pipelines

Core Concepts

Understand knowledge graph fundamentals