async def build_communities(
            collection_id: UUID = Path(
                ..., description="The unique identifier of the collection"
            ),
            graph_enrichment_settings: Optional[dict] = Body(
                default=None,
                description="Settings for the graph enrichment process.",
            ),
            run_with_orchestration: Optional[bool] = Body(True),
            auth_user=Depends(self.providers.auth.auth_wrapper()),
        ) -> WrappedGenericMessageResponse:
            """Creates communities in the graph by analyzing entity
            relationships and similarities.

            Communities are created through the following process:
            1. Analyzes entity relationships and metadata to build a similarity graph
            2. Applies advanced community detection algorithms (e.g. Leiden) to identify densely connected groups
            3. Creates hierarchical community structure with multiple granularity levels
            4. Generates natural language summaries and statistical insights for each community

            The resulting communities can be used to:
            - Understand high-level graph structure and organization
            - Identify key entity groupings and their relationships
            - Navigate and explore the graph at different levels of detail
            - Generate insights about entity clusters and their characteristics

            The community detection process is configurable through settings like:
                - Community detection algorithm parameters
                - Summary generation prompt
            """
            collections_overview_response = (
                await self.services.management.collections_overview(
                    user_ids=[auth_user.id],
                    collection_ids=[collection_id],
                    offset=0,
                    limit=1,
                )
            )["results"]
            if len(collections_overview_response) == 0:  # type: ignore
                raise R2RException("Collection not found.", 404)

            # Check user permissions for graph
            if (
                not auth_user.is_superuser
                and collections_overview_response[0].owner_id != auth_user.id  # type: ignore
            ):
                raise R2RException(
                    "Only superusers can `build communities` for a graph they do not own.",
                    403,
                )

            # If no collection ID is provided, use the default user collection
            # id = generate_default_user_collection_id(auth_user.id)

            # Apply runtime settings overrides
            server_graph_enrichment_settings = (
                self.providers.database.config.graph_enrichment_settings
            )
            if graph_enrichment_settings:
                server_graph_enrichment_settings = update_settings_from_dict(
                    server_graph_enrichment_settings, graph_enrichment_settings
                )

            workflow_input = {
                "collection_id": str(collection_id),
                "graph_enrichment_settings": server_graph_enrichment_settings.model_dump_json(),
                "user": auth_user.json(),
            }

            if run_with_orchestration:
                try:
                    return await self.providers.orchestration.run_workflow(  # type: ignore
                        "graph-clustering", {"request": workflow_input}, {}
                    )
                    return GenericMessageResponse(
                        message="Graph communities created successfully."
                    )  # type: ignore

                except Exception as e:  # TODO: Need to find specific error (gRPC most likely?)
                    logger.error(
                        f"Error running orchestrated community building: {e} \n\nAttempting to run without orchestration."
                    )
            from core.main.orchestration import (
                simple_graph_search_results_factory,
            )

            logger.info("Running build-communities without orchestration.")
            simple_graph_search_results = simple_graph_search_results_factory(
                self.services.graph
            )
            await simple_graph_search_results["graph-clustering"](
                workflow_input
            )
            return {  # type: ignore
                "message": "Graph communities created successfully.",
                "task_id": None,
            }
Creates communities in the graph by analyzing entity
            relationships and similarities.

            Communities are created through the following process:
            1. Analyzes entity relationships and metadata to build a similarity graph
            2. Applies advanced community detection algorithms (e.g. Leiden) to identify densely connected groups
            3. Creates hierarchical community structure with multiple granularity levels
            4. Generates natural language summaries and statistical insights for each community

            The resulting communities can be used to:
            - Understand high-level graph structure and organization
            - Identify key entity groupings and their relationships
            - Navigate and explore the graph at different levels of detail
            - Generate insights about entity clusters and their characteristics

            The community detection process is configurable through settings like:
                - Community detection algorithm parameters
                - Summary generation prompt
            
py/core/main/api/v3/graph_router.py