@@ -12,7 +12,7 @@ func TestSingleSentenceEmbedding(t *testing.T) {
1212 if err != nil {
1313 t .Fatalf ("Failed to create model: %v" , err )
1414 }
15- defer model . Close ( )
15+ defer closeAndDestroy ( model )
1616
1717 sentence := "Hello, world! This is a test sentence."
1818 embedding , err := model .Compute (sentence , false )
@@ -54,7 +54,7 @@ func TestBatchEmbedding(t *testing.T) {
5454 if err != nil {
5555 t .Fatalf ("Failed to create model: %v" , err )
5656 }
57- defer model . Close ( )
57+ defer closeAndDestroy ( model )
5858
5959 sentences := []string {
6060 "Hello, world! This is a test sentence." ,
@@ -117,7 +117,7 @@ func TestConsistentEmbeddingForSameSentence(t *testing.T) {
117117 if err != nil {
118118 t .Fatalf ("Failed to create model: %v" , err )
119119 }
120- defer model . Close ( )
120+ defer closeAndDestroy ( model )
121121
122122 // Test with same sentence appearing twice in batch, plus a different sentence
123123 sentences := []string {
@@ -172,7 +172,7 @@ func TestSingleVsBatchConsistency(t *testing.T) {
172172 if err != nil {
173173 t .Fatalf ("Failed to create model: %v" , err )
174174 }
175- defer model . Close ( )
175+ defer closeAndDestroy ( model )
176176
177177 sentence := "Testing consistency between single and batch computation."
178178
@@ -203,7 +203,7 @@ func TestEmptyBatch(t *testing.T) {
203203 if err != nil {
204204 t .Fatalf ("Failed to create model: %v" , err )
205205 }
206- defer model . Close ( )
206+ defer closeAndDestroy ( model )
207207
208208 // Test empty batch
209209 embeddings , err := model .ComputeBatch ([]string {}, false )
@@ -230,3 +230,9 @@ func vectorsEqual(a, b []float32) bool {
230230 }
231231 return true
232232}
233+
234+ // Helper function to close the model and destroy its env
235+ func closeAndDestroy (m * all_minilm_l6_v2.Model ) {
236+ m .Close ()
237+ all_minilm_l6_v2 .DestroyOrtEnv ()
238+ }
0 commit comments