Graph Namespacing
Using group_ids to create isolated graph namespaces
Overview
Graphiti supports the concept of graph namespacing through the use of group_id
parameters. This feature allows you to create isolated graph environments within the same Graphiti instance, enabling multiple distinct knowledge graphs to coexist without interference.
Graph namespacing is particularly useful for:
- Multi-tenant applications: Isolate data between different customers or organizations
- Testing environments: Maintain separate development, testing, and production graphs
- Domain-specific knowledge: Create specialized graphs for different domains or use cases
- Team collaboration: Allow different teams to work with their own graph spaces
How Namespacing Works
In Graphiti, every node and edge can be associated with a group_id
. When you specify a group_id
, you’re effectively creating a namespace for that data. Nodes and edges with the same group_id
form a cohesive, isolated graph that can be queried and manipulated independently from other namespaces.
Key Benefits
- Data isolation: Prevent data leakage between different namespaces
- Simplified management: Organize and manage related data together
- Performance optimization: Improve query performance by limiting the search space
- Flexible architecture: Support multiple use cases within a single Graphiti instance
Using group_ids in Graphiti
Adding Episodes with group_id
When adding episodes to your graph, you can specify a group_id
to namespace the episode and all its extracted entities:
Adding Fact Triples with group_id
When manually adding fact triples, ensure both nodes and the edge share the same group_id
:
Querying Within a Namespace
When querying the graph, specify the group_id
to limit results to a particular namespace:
Best Practices for Graph Namespacing
- Consistent naming: Use a consistent naming convention for your
group_id
values - Documentation: Maintain documentation of your namespace structure and purpose
- Granularity: Choose an appropriate level of granularity for your namespaces
- Too many namespaces can lead to fragmented data
- Too few namespaces may not provide sufficient isolation
- Cross-namespace queries: When necessary, perform multiple queries across namespaces and combine results in your application logic
Example: Multi-tenant Application
Here’s an example of using namespacing in a multi-tenant application: