Graph
The GraphResource provides graph-level operations: community detection, duplicate entity finding, and entity merging.
Access
graph = client.graphMethods
communities(limit)
List detected communities in the knowledge graph. Communities are clusters of related entities found via graph algorithms.
communities = graph.communities(limit=10)
for c in communities:
print(f"{c.label}: {c.entity_count} entities")
if c.summary:
print(f" {c.summary}")| Parameter | Type | Default | Description |
|---|---|---|---|
limit | int | 20 | Maximum number to return |
Returns: List of GraphCommunity objects with fields id, label, summary, entity_count, entity_ids
detect_communities(resolution)
Run community detection on the knowledge graph using the Louvain algorithm. This is a background operation that groups related entities.
result = graph.detect_communities(resolution=1.0)
print(result) # {"message": "Community detection started"}| Parameter | Type | Default | Description |
|---|---|---|---|
resolution | float | 1.0 | Resolution parameter (higher = more, smaller communities) |
Returns: Status dict with message
find_duplicates(threshold, limit)
Find potential duplicate entities based on semantic similarity.
dupes = graph.find_duplicates(threshold=0.95)
for group in dupes.groups:
print(f"Duplicates (similarity: {group.similarity_score}):")
print(f" Entity IDs: {group.entity_ids}")
print(f" Suggested keep: {group.suggested_merge_target}")| Parameter | Type | Default | Description |
|---|---|---|---|
threshold | float | 0.90 | Similarity threshold (0.0–1.0, higher = more strict) |
limit | int | 50 | Maximum duplicate groups to return |
Returns: DuplicatesResponse with fields:
groups— List ofDuplicateGroup(entity_ids, similarity_score, suggested_merge_target)total_groups— Total number of duplicate groups found
merge(keep_entity_id, merge_entity_id)
Merge two duplicate entities. Keeps one entity and soft-deletes the other, redirecting all relationships.
result = graph.merge(
keep_entity_id="uuid-to-keep",
merge_entity_id="uuid-to-merge",
)
print(f"Merged into: {result.merged_into}")
print(f"Relationships redirected: {result.relationships_redirected}")| Parameter | Type | Description |
|---|---|---|
keep_entity_id | str | ID of the entity to keep |
merge_entity_id | str | ID of the entity to merge (will be soft-deleted) |
Returns: MergeResponse with fields merged_into, merged_count, relationships_redirected, status