@ -23,12 +23,17 @@ class ChromaDBVectorStore(VectorStore):
max_retries = 30
for i in range ( max_retries ) :
try :
response = requests . get ( f " http:// { host } : { port } /api/v1/heartbeat " )
if response . status_code == 200 :
# Try v2 API first, then fallback to basic connection test
try :
response = requests . get ( f " http:// { host } : { port } /api/v1/version " )
except :
response = requests . get ( f " http:// { host } : { port } " )
if response . status_code in [ 200 , 404 ] : # 404 is OK, means server is responding
vector_store_logger . info ( " ChromaDB is ready! " )
break
except Exception as e :
vector_store_logger . debug ( f " ChromaDB heartbeat check failed (attempt { i + 1 } ) " , error = e )
vector_store_logger . debug ( f " ChromaDB connection check failed (attempt { i + 1 } ) " , error = e )
pass
if i == max_retries - 1 :
vector_store_logger . warning ( " ChromaDB not responding, attempting to connect anyway... " )
@ -41,7 +46,10 @@ class ChromaDBVectorStore(VectorStore):
try :
vector_store_logger . debug ( " Trying direct ChromaDB connection... " )
self . client = chromadb . HttpClient ( host = host , port = port )
self . collection = self . client . get_or_create_collection ( name = " face_embeddings " )
self . collection = self . client . get_or_create_collection (
name = " face_embeddings " ,
metadata = { " hnsw:space " : " cosine " }
)
vector_store_logger . info ( " Direct ChromaDB connection successful! " )
connection_successful = True
except Exception as e :
@ -53,7 +61,10 @@ class ChromaDBVectorStore(VectorStore):
vector_store_logger . debug ( " Trying ChromaDB connection with settings... " )
settings = chromadb . config . Settings ( allow_reset = True )
self . client = chromadb . HttpClient ( host = host , port = port , settings = settings )
self . collection = self . client . get_or_create_collection ( name = " face_embeddings " )
self . collection = self . client . get_or_create_collection (
name = " face_embeddings " ,
metadata = { " hnsw:space " : " cosine " }
)
vector_store_logger . info ( " ChromaDB connection with settings successful! " )
connection_successful = True
except Exception as e :
@ -65,7 +76,10 @@ class ChromaDBVectorStore(VectorStore):
vector_store_logger . debug ( " Trying persistent client fallback... " )
import tempfile
self . client = chromadb . PersistentClient ( path = tempfile . mkdtemp ( ) )
self . collection = self . client . get_or_create_collection ( name = " face_embeddings " )
self . collection = self . client . get_or_create_collection (
name = " face_embeddings " ,
metadata = { " hnsw:space " : " cosine " }
)
vector_store_logger . warning ( " Using persistent client fallback! " )
connection_successful = True
except Exception as e :
@ -146,6 +160,8 @@ class ChromaDBVectorStore(VectorStore):
face_id = results [ ' ids ' ] [ 0 ] [ i ]
distance = results [ ' distances ' ] [ 0 ] [ i ]
metadata = results [ ' metadatas ' ] [ 0 ] [ i ]
# For cosine distance, similarity = 1 - distance
# Cosine distance ranges from 0 (identical) to 2 (opposite)
similarity = 1 - distance
similar_faces . append ( ( face_id , similarity , metadata ) )