3131SEARCH_INDEX_NAME = "text_index"
3232
3333
34- def setup_test () -> tuple [ Collection , MongoDBAtlasVectorSearch ] :
34+ def get_collection () -> Collection :
3535 client = MongoClient (CONNECTION_STRING )
36- coll = client [DB_NAME ][COLLECTION_NAME ]
36+ return client [DB_NAME ][COLLECTION_NAME ]
3737
38+
39+ def setup_test (coll : Collection ) -> MongoDBAtlasVectorSearch :
3840 # Set up the vector search index and add the documents if needed.
3941 vs = PatchedMongoDBAtlasVectorSearch (
4042 coll ,
@@ -72,7 +74,7 @@ class TestMongoDBAtlasFullTextSearchRetriever(RetrieversIntegrationTests):
7274
7375 @classmethod
7476 def setup_class (cls ):
75- cls ._coll , _ = setup_test ()
77+ cls ._coll = get_collection ()
7678
7779 @classmethod
7880 def teardown_class (cls ):
@@ -85,6 +87,7 @@ def retriever_constructor(self) -> Type[MongoDBAtlasFullTextSearchRetriever]:
8587
8688 @property
8789 def retriever_constructor_params (self ) -> dict :
90+ setup_test (self ._coll )
8891 return {
8992 "collection" : self ._coll ,
9093 "search_index_name" : SEARCH_INDEX_NAME ,
@@ -101,11 +104,10 @@ def retriever_query_example(self) -> str:
101104
102105class TestMongoDBAtlasHybridSearchRetriever (RetrieversIntegrationTests ):
103106 _coll : Collection
104- _vs : MongoDBAtlasVectorSearch
105107
106108 @classmethod
107109 def setup_class (cls ):
108- cls ._coll , cls . _vs = setup_test ()
110+ cls ._coll = get_collection ()
109111
110112 @classmethod
111113 def teardown_class (cls ):
@@ -118,8 +120,9 @@ def retriever_constructor(self) -> Type[MongoDBAtlasHybridSearchRetriever]:
118120
119121 @property
120122 def retriever_constructor_params (self ) -> dict :
123+ vs = setup_test (self ._coll )
121124 return {
122- "vectorstore" : self . _vs ,
125+ "vectorstore" : vs ,
123126 "collection" : self ._coll ,
124127 "search_index_name" : SEARCH_INDEX_NAME ,
125128 "search_field" : PAGE_CONTENT_FIELD ,
0 commit comments