Description
When CreateCollection is called with CreateIfNotExists=true (i.e. via GetOrCreateCollection) and the collection already exists (isNewCreation=false), PrepareAndValidateCollectionRequest() unconditionally creates a default ORT EmbeddingFunction that holds native ONNX Runtime resources (session handles, environment state).
The isNewCreation=false path then sets overrideEF = nil and overrideContentEF = nil, discarding the reference to the default ORT EF without ever closing it. The EF is never stored in collection state or passed to a collection constructor, so its Close() is never called.
Impact
Every call to GetOrCreateCollection on the embedded client for an already-existing collection leaks one ORT EmbeddingFunction's native ONNX resources. Over many calls this accumulates leaked session handles and environment state.
Affected code
pkg/api/v2/client_local_embedded.go: CreateCollection lines 347, 408-411
pkg/api/v2/client.go: PrepareAndValidateCollectionRequest lines 274-284 (where default ORT EF is created)
Notes
Description
When
CreateCollectionis called withCreateIfNotExists=true(i.e. viaGetOrCreateCollection) and the collection already exists (isNewCreation=false),PrepareAndValidateCollectionRequest()unconditionally creates a default ORTEmbeddingFunctionthat holds native ONNX Runtime resources (session handles, environment state).The
isNewCreation=falsepath then setsoverrideEF = nilandoverrideContentEF = nil, discarding the reference to the default ORT EF without ever closing it. The EF is never stored in collection state or passed to a collection constructor, so itsClose()is never called.Impact
Every call to
GetOrCreateCollectionon the embedded client for an already-existing collection leaks one ORT EmbeddingFunction's native ONNX resources. Over many calls this accumulates leaked session handles and environment state.Affected code
pkg/api/v2/client_local_embedded.go:CreateCollectionlines 347, 408-411pkg/api/v2/client.go:PrepareAndValidateCollectionRequestlines 274-284 (where default ORT EF is created)Notes
isNewCreation=falsebefore discarding it: