3.7 KiB
3.7 KiB
NodeSets
Tagging and grouping data in Cognee
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.add(..., 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 searches to only those subsets.
How they flow through Cognee
- Add:
- NodeSets are attached as simple tags to datasets or documents
- This happens when you first ingest data
- Cognify:
- carried into Documents and Chunks
- materialized as real
NodeSetnodes in the graph - connected with
belongs_to_setedges
- Search:
- NodeSets act as entry points into the graph
- Queries can be scoped to only nodes linked to specific NodeSets
- This lets you search within a tagged subset of your data
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
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)
# add a document linked only to the "AI_Memory" node set
await cognee.add(
"Cognee builds AI memory from raw documents.",
node_set=["AI_Memory"]
)
# add a document linked to both "AI_Memory" and "Graph_RAG" node sets
await cognee.add(
"Cognee combines vector search with graph reasoning.",
node_set=["AI_Memory", "Graph_RAG"]
)
# build the knowledge graph by extracting entities and relationships
await cognee.cognify()
if __name__ == "__main__":
asyncio.run(main())
What just happened?
- You reset Cognee’s memory so you’re working with a clean graph.
- You added two documents, each tagged with one or more
NodeSetlabels.- The first document is only linked to
AI_Memory. - The second document is linked to both
AI_MemoryandGraph_RAG.
- The first document is only linked to
- When you ran
cognify(), Cognee:- Created
NodeSetnodes (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.
- Created
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:
- You can filter searches by NodeSet.
- You can scope queries to specific NodeSets.
- You can navigate data by project or domain using NodeSets.
To find navigation and other pages in this documentation, fetch the llms.txt file at: https://docs.cognee.ai/llms.txt