@@ -201,13 +201,27 @@ def test_additional_entity_examples(entity_extraction_model, entity_example, doc
201201 assert len (new_entities ) >= 2
202202
203203
204+ def test_chat_response (graph_store , query_connection ):
205+ """Displays querying an existing Knowledge Graph Database"""
206+ answer = graph_store .chat_response (query_connection )
207+ assert isinstance (answer , AIMessage )
208+ assert "acme corporation" in answer .content .lower ()
209+
210+
211+ def test_similarity_search (graph_store , query_connection ):
212+ docs = graph_store .similarity_search (query_connection )
213+ assert len (docs ) >= 4
214+ assert all ({"_id" , "type" , "relationships" }.issubset (set (d .keys ())) for d in docs )
215+ assert any ("depth" in d .keys () for d in docs )
216+ assert any ("attributes" in d .keys () for d in docs )
217+
218+
204219def test_validator (documents , entity_extraction_model ):
205220 # Case 1. No existing collection.
221+ client = MongoClient (CONNECTION_STRING )
206222 clxn_name = f"{ COLLECTION_NAME } _validation"
207-
208- with MongoClient (CONNECTION_STRING ) as client :
209- client [DB_NAME ][clxn_name ].drop ()
210-
223+ client [DB_NAME ][clxn_name ].drop ()
224+ client .close ()
211225 # now we call with validation that can be added without db admin privileges
212226 store = MongoDBGraphStore (
213227 connection_string = CONNECTION_STRING ,
@@ -229,15 +243,16 @@ def test_validator(documents, entity_extraction_model):
229243 collection = client [DB_NAME ][clxn_name ]
230244 collection .delete_many ({})
231245
232- store = MongoDBGraphStore (
233- collection = collection ,
234- entity_extraction_model = entity_extraction_model ,
235- validate = True ,
236- validation_action = "error" ,
237- )
238- bulkwrite_results = store .add_documents (documents )
239- assert len (bulkwrite_results ) == len (documents )
240- collection .delete_many ({})
246+ store = MongoDBGraphStore (
247+ collection = collection ,
248+ entity_extraction_model = entity_extraction_model ,
249+ validate = True ,
250+ validation_action = "error" ,
251+ )
252+ bulkwrite_results = store .add_documents (documents )
253+ assert len (bulkwrite_results ) == len (documents )
254+ collection .drop ()
255+ store .close ()
241256
242257 # Case 3: Existing collection without a validator
243258 with MongoClient (CONNECTION_STRING ) as client :
0 commit comments