Skip to content

Commit

Permalink
limit community building concurrency (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalef committed Sep 22, 2024
1 parent c6ead2e commit 5d2121e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions graphiti_core/utils/maintenance/community_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from graphiti_core.prompts import prompt_library
from graphiti_core.utils.maintenance.edge_operations import build_community_edges

MAX_COMMUNITY_BUILD_CONCURRENCY = 10


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -132,10 +135,14 @@ async def build_communities(
projection = await build_community_projection(driver)
community_clusters = await get_community_clusters(driver, projection)

semaphore = asyncio.Semaphore(MAX_COMMUNITY_BUILD_CONCURRENCY)

async def limited_build_community(cluster):
async with semaphore:
return await build_community(llm_client, cluster)

communities: list[tuple[CommunityNode, list[CommunityEdge]]] = list(
await asyncio.gather(
*[build_community(llm_client, cluster) for cluster in community_clusters]
)
await asyncio.gather(*[limited_build_community(cluster) for cluster in community_clusters])
)

community_nodes: list[CommunityNode] = []
Expand Down Expand Up @@ -236,4 +243,4 @@ async def update_community(

await community.generate_name_embedding(embedder)

await community.save(driver)
await community.save(driver)

0 comments on commit 5d2121e

Please sign in to comment.