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

Full Working Example

import asyncio
import cognee
from cognee 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)

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.

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.