1717from chromadb .api .models .AsyncCollection import AsyncCollection
1818from chromadb .api .types import EmbeddingFunction , IncludeEnum , QueryResult
1919from chromadb .config import APIVersion , Settings
20+ from chromadb .errors import InvalidCollectionException
2021from tree_sitter import Point
2122
2223import vectorcode .subcommands .query .types as vectorcode_query_types
2324from vectorcode .chunking import Chunk , TreeSitterChunker
2425from vectorcode .cli_utils import Config , LockManager , expand_path
2526from vectorcode .common import get_embedding_function
2627from vectorcode .database .base import DatabaseConnectorBase
28+ from vectorcode .database .errors import CollectionNotFoundError
2729from vectorcode .database .types import (
2830 CollectionContent ,
2931 CollectionInfo ,
@@ -170,7 +172,7 @@ async def get_client(self, configs: Config, need_lock: bool = True):
170172 process = None
171173 if not await _try_server (url ):
172174 logger .info (f"Starting a new server at { url } " )
173- process = await _start_server (url )
175+ process = await _start_server (configs )
174176 is_bundled = True
175177
176178 self .__clients [project_root ] = _Chroma0ClientModel (
@@ -223,7 +225,7 @@ def clear(self):
223225 self .__clients .clear ()
224226
225227
226- __default_settings : dict [str , Any ] = {
228+ _default_settings : dict [str , Any ] = {
227229 "db_url" : "http://127.0.0.1" ,
228230 "db_path" : os .path .expanduser ("~/.local/share/vectorcode/chromadb/" ),
229231 "db_log_path" : os .path .expanduser ("~/.local/share/vectorcode/" ),
@@ -246,7 +248,7 @@ class ChromaDB0Connector(DatabaseConnectorBase):
246248
247249 def __init__ (self , configs : Config ):
248250 super ().__init__ (configs )
249- params = copy .deepcopy (__default_settings )
251+ params = copy .deepcopy (_default_settings )
250252 params .update (self ._configs .db_params )
251253 self ._configs .db_params = params
252254
@@ -294,12 +296,18 @@ async def _create_or_get_collection(
294296 meta_field_name : str = key
295297 if not meta_field_name .startswith ("hnsw:" ):
296298 meta_field_name = f"hnsw:{ meta_field_name } "
297- collection_meta [meta_field_name ] = db_params [key ]
299+ if db_params .get (key ) is not None :
300+ collection_meta [meta_field_name ] = db_params [key ]
298301
299302 async with Chroma0ClientManager ().get_client (self ._configs , True ) as client :
300303 collection_id = get_collection_id (collection_path )
301304 if not allow_create :
302- return await client .get_collection (collection_id )
305+ try :
306+ return await client .get_collection (collection_id )
307+ except (InvalidCollectionException , ValueError ) as e :
308+ raise CollectionNotFoundError (
309+ f"There's no existing collection for { collection_path } in ChromaDB0 { self ._configs .db_params .get ('db_url' )} "
310+ ) from e
303311 col = await client .get_or_create_collection (
304312 collection_id , metadata = collection_meta
305313 )
@@ -448,4 +456,5 @@ async def delete(self, collection_path: str, file_path: str | Sequence[str]):
448456
449457 async def drop (self , collection_path : str ):
450458 async with Chroma0ClientManager ().get_client (self ._configs ) as client :
459+ await self ._create_or_get_collection (collection_path , False )
451460 await client .delete_collection (get_collection_id (collection_path ))
0 commit comments