Skip to content

Commit dcd836d

Browse files
committed
INTPYTHON-787 Added check for AZURE_OPENAI_ENDPOINT test_graphrag.py and cleaned up closing clients (#232)
[Issue Key](https://jira.mongodb.org/browse/{ISSUE_KEY}) <!-- What is this PR introducing? If context is already provided from the JIRA ticket, still place it in the Pull Request as you should not make the reviewer do digging for a basic summary. --> <!-- What changes did you make to the code? What new APIs (public or private) were added, removed, or edited to generate the desired outcome explained in the above summary? --> This is a small bugfix. When we switched from including OPENAI_API_KEY in CI secrets to using AZURE_OPENAI_ENDPOINTS, we missed this one. <!-- How did you test the code? If you added unit tests, you can say that. If you didn’t introduce unit tests, explain why. All code should be tested in some way – so please list what your validation strategy was. --> - Tests are run in github and evergreen. A passing patch build will be included. <!-- Do not delete the items provided on this checklist --> - [ na] Did you update the changelog (if necessary)? - [X] Is the intention of the code captured in relevant tests? - [na] If there are new TODOs, has a related JIRA ticket been created? - [X] Has a MongoDB Employee run [the patch build of this PR](https://github.com/mongodb-labs/ai-ml-pipeline-testing?tab=readme-ov-file#running-a-patch-build-of-a-given-pr)? - [x] Does the title of the PR reference a JIRA Ticket? - [x] Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?) - [x] Have you checked for spelling & grammar errors? - [x] Is all relevant documentation (README or docstring) updated? <!-- List any complex portion of code you believe needs particular scrutiny and explain why. --> The author had thought of updating MongoDBGraphStore to be a context manager. All this would do is close the client. We decided to leave it with a close method only.
1 parent 350348a commit dcd836d

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

libs/langchain-mongodb/tests/integration_tests/test_graphrag.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,13 @@ 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-
219204
def test_validator(documents, entity_extraction_model):
220205
# Case 1. No existing collection.
221-
client = MongoClient(CONNECTION_STRING)
222206
clxn_name = f"{COLLECTION_NAME}_validation"
223-
client[DB_NAME][clxn_name].drop()
224-
client.close()
207+
208+
with MongoClient(CONNECTION_STRING) as client:
209+
client[DB_NAME][clxn_name].drop()
210+
225211
# now we call with validation that can be added without db admin privileges
226212
store = MongoDBGraphStore(
227213
connection_string=CONNECTION_STRING,
@@ -243,16 +229,15 @@ def test_validator(documents, entity_extraction_model):
243229
collection = client[DB_NAME][clxn_name]
244230
collection.delete_many({})
245231

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()
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({})
256241

257242
# Case 3: Existing collection without a validator
258243
with MongoClient(CONNECTION_STRING) as client:

0 commit comments

Comments
 (0)