Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt

Use this file to discover all available pages before exploring further.

What are NodeSets?

A NodeSet lets you group parts of your AI memory at the dataset level. You create them as a simple list of tags when adding data to Cognee:
await cognee.remember(..., node_set=["projectA", "finance"])
These tags travel with your data into the knowledge graph, where they become first-class nodes connected with belongs_to_set edges — and you can later filter retrieval to only those subsets.

How they flow through Cognee

  • Remember:
    • NodeSets are attached as simple tags to datasets or documents
    • This happens when you first ingest data
    • The underlying graph-building step carries them into Documents and Chunks
    • They are materialized as real NodeSet nodes in the graph and connected with belongs_to_set edges
  • Recall:
    • NodeSets help define meaningful retrieval subsets
    • Use recall() with node_name and node_name_filter_operator to scope retrieval to specific node-set subsets
  • Improve:
    • The default improvement path runs memify-style enrichment
    • Related enrichment flows can create node sets such as coding_agent_rules or user_sessions_from_cache

Why they matter

  • Provide a lightweight way to organize and tag your data
  • Enable graph-based filtering, traversal, and reporting
  • Ideal for creating project-, domain-, or user-defined subsets of your knowledge graph

Example: tagging data with NodeSets

import asyncio
import cognee

async def main():
    # reset Cognee’s memory and metadata for a clean run
    await cognee.prune.prune_data()
    await cognee.prune.prune_system(metadata=True)

    # remember a document linked only to the "AI_Memory" node set
    await cognee.remember(
        "Cognee builds AI memory from raw documents.",
        node_set=["AI_Memory"]
    )

    # remember a document linked to both "AI_Memory" and "Graph_RAG" node sets
    await cognee.remember(
        "Cognee combines vector search with graph reasoning.",
        node_set=["AI_Memory", "Graph_RAG"]
    )

if __name__ == "__main__":
    asyncio.run(main())

What just happened?

  • You reset Cognee’s memory so you’re working with a clean graph.
  • You remembered two documents, each tagged with one or more NodeSet labels.
    • The first document is only linked to AI_Memory.
    • The second document is linked to both AI_Memory and Graph_RAG.
  • During remember(), Cognee:
    • Created NodeSet nodes (AI_Memory, Graph_RAG) in the graph.
    • Attached each document to the corresponding NodeSets.
    • Extracted entities and relationships from the documents, then linked those entities back to the same NodeSets.
This means the tags you add flow down into the extracted entities:
  • “Cognee” appears in both documents → connects to both NodeSets.
  • “AI memory” appears only in the first → connects only to AI_Memory.
  • “Vector search” appears only in the second → connects to both since that document belongs to AI_Memory and Graph_RAG.
Your NodeSets now unlock powerful search and navigation capabilities:

Filtering searches by NodeSet

When filtering with multiple NodeSet names, you can control matching behavior by choosing whether results must be connected to all selected names or to any selected name; by default, Cognee uses the any selected name behavior (OR-style matching). This behaviour is controlled by passing the wanted value (AND or OR) via the node_name_filter_operator parameter in recall().
from cognee import SearchType
from cognee.modules.engine.models.node_set import NodeSet

# OR (default) — results from any of the listed node sets
results = await cognee.recall(
    "What are the key topics?",
    query_type=SearchType.GRAPH_COMPLETION,
    node_type=NodeSet,
    node_name=["AI_Memory", "Graph_RAG"],
    node_name_filter_operator="OR",
)

# AND — results must belong to all listed node sets simultaneously
results = await cognee.recall(
    "What concepts appear in both?",
    query_type=SearchType.GRAPH_COMPLETION,
    node_type=NodeSet,
    node_name=["AI_Memory", "Graph_RAG"],
    node_name_filter_operator="AND",
)
Node-set filtering works with graph-completion search types (GRAPH_COMPLETION, GRAPH_COMPLETION_COT, GRAPH_COMPLETION_CONTEXT_EXTENSION, GRAPH_SUMMARY_COMPLETION, TEMPORAL). It is not applied for CHUNKS, SUMMARIES, RAG_COMPLETION, CYPHER, or NATURAL_LANGUAGE.
Use the same NodeSet names you assigned during remember() to limit retrieval to a focused subset of your graph. This is useful when one dataset contains multiple topics, teams, or workflows but you only want answers grounded in one slice of that memory.In practice, NodeSets let you keep a shared dataset while still asking targeted questions like “show only finance concepts” or “search just the Graph_RAG material” without splitting everything into separate datasets.
from cognee import SearchType
from cognee.modules.engine.models.node_set import NodeSet

# Recall only within the finance-related subset
results = await cognee.recall(
    "What risks are mentioned in the quarterly report?",
    query_type=SearchType.GRAPH_COMPLETION,
    node_type=NodeSet,
    node_name=["finance"],
)

# Recall only within the Graph_RAG subset
results = await cognee.recall(
    "How does Cognee combine graph reasoning with retrieval?",
    query_type=SearchType.GRAPH_COMPLETION,
    node_type=NodeSet,
    node_name=["Graph_RAG"],
)

Remember

Where NodeSets are first attached

Improve

How enrichment flows add more NodeSet-based structure

Search

Use NodeSets as anchors in queries