Skip to Content

Graph

The GraphResource provides graph-level operations: community detection, duplicate entity finding, and entity merging.

Access

graph = client.graph

Methods

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}")
ParameterTypeDefaultDescription
limitint20Maximum 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"}
ParameterTypeDefaultDescription
resolutionfloat1.0Resolution 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}")
ParameterTypeDefaultDescription
thresholdfloat0.90Similarity threshold (0.0–1.0, higher = more strict)
limitint50Maximum duplicate groups to return

Returns: DuplicatesResponse with fields:

  • groups — List of DuplicateGroup (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}")
ParameterTypeDescription
keep_entity_idstrID of the entity to keep
merge_entity_idstrID of the entity to merge (will be soft-deleted)

Returns: MergeResponse with fields merged_into, merged_count, relationships_redirected, status

Last updated on