@@ -244,7 +244,6 @@ public static VectorStoreCollection<TKey, TRecord> GetVectorCollection<TKey, TRe
244244 where TRecord : class
245245 {
246246 IDatabase database ;
247- VectorStore vectorStore ;
248247 VectorStoreCollection < TKey , TRecord > collection = null ;
249248
250249 //TODO: If the logic becomes overly complex in the future, different combinations can be considered to be separated into different libraries
@@ -253,8 +252,10 @@ public static VectorStoreCollection<TKey, TRecord> GetVectorCollection<TKey, TRe
253252 {
254253 case VectorDBType . Memory :
255254 {
256- vectorStore = new InMemoryVectorStore ( ) ;
257- collection = vectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
255+ using ( var inMemoryVectorStore = new InMemoryVectorStore ( ) )
256+ {
257+ collection = inMemoryVectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
258+ }
258259 break ;
259260 }
260261 case VectorDBType . HardDisk :
@@ -293,13 +294,17 @@ public static VectorStoreCollection<TKey, TRecord> GetVectorCollection<TKey, TRe
293294 }
294295 case VectorDBType . Qdrant :
295296 {
296- vectorStore = new QdrantVectorStore ( new QdrantClient ( vectorDb . ConnectionString ) , ownsClient : true ) ;
297- collection = vectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
297+ using ( var qdrantVectorStore = new QdrantVectorStore ( new QdrantClient ( vectorDb . ConnectionString ) , ownsClient : true ) )
298+ {
299+ collection = qdrantVectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
300+ }
298301 break ;
299302 }
300303 default :
301- vectorStore = new InMemoryVectorStore ( ) ;
302- collection = vectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
304+ using ( var inMemoryVectorStore = new InMemoryVectorStore ( ) )
305+ {
306+ collection = inMemoryVectorStore . GetCollection < TKey , TRecord > ( name , vectorStoreRecordDefinition ) ;
307+ }
303308 break ;
304309 }
305310
0 commit comments