From 2fdf3f3a6a84fd2d31d219c17f8178d6f0ac8610 Mon Sep 17 00:00:00 2001 From: Vini Brasil Date: Mon, 18 Aug 2025 11:00:50 -0700 Subject: [PATCH] Move Chroma lockfile to `db/` (#3342) This commit fixes an issue where using Chroma would spam lockfiles over the root path of the crew. --- src/crewai/utilities/chromadb.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/crewai/utilities/chromadb.py b/src/crewai/utilities/chromadb.py index 7d2051ebf..60da9988d 100644 --- a/src/crewai/utilities/chromadb.py +++ b/src/crewai/utilities/chromadb.py @@ -1,9 +1,10 @@ +import os import re import portalocker from chromadb import PersistentClient from hashlib import md5 from typing import Optional - +from crewai.utilities.paths import db_storage_path MIN_COLLECTION_LENGTH = 3 MAX_COLLECTION_LENGTH = 63 @@ -27,7 +28,9 @@ def is_ipv4_pattern(name: str) -> bool: return bool(IPV4_PATTERN.match(name)) -def sanitize_collection_name(name: Optional[str], max_collection_length: int = MAX_COLLECTION_LENGTH) -> str: +def sanitize_collection_name( + name: Optional[str], max_collection_length: int = MAX_COLLECTION_LENGTH +) -> str: """ Sanitize a collection name to meet ChromaDB requirements: 1. 3-63 characters long @@ -72,7 +75,8 @@ def create_persistent_client(path: str, **kwargs): concurrent creations. Works for both multi-threads and multi-processes environments. """ - lockfile = f"chromadb-{md5(path.encode(), usedforsecurity=False).hexdigest()}.lock" + lock_id = md5(path.encode(), usedforsecurity=False).hexdigest() + lockfile = os.path.join(db_storage_path(), f"chromadb-{lock_id}.lock") with portalocker.Lock(lockfile): client = PersistentClient(path=path, **kwargs)