File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
langchain_mongodb/graphrag Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1414from pymongo import MongoClient , UpdateOne
1515from pymongo .collection import Collection
1616from pymongo .driver_info import DriverInfo
17+ from pymongo .errors import OperationFailure
1718from pymongo .results import BulkWriteResult
1819
1920from langchain_mongodb .graphrag import example_templates , prompts
@@ -145,12 +146,18 @@ def __init__(
145146 else :
146147 self .allowed_relationship_types = []
147148 if validate :
148- collection .database .command (
149- "collMod" ,
150- collection .name ,
151- validator = {"$jsonSchema" : self ._schema },
152- validationAction = validation_action ,
153- )
149+ try :
150+ collection .database .command (
151+ "collMod" ,
152+ collection .name ,
153+ validator = {"$jsonSchema" : self ._schema },
154+ validationAction = validation_action ,
155+ )
156+ except OperationFailure :
157+ logger .warning (
158+ "Validation will NOT be performed. User must be DB Admin to add validation **after** a Collection is created. \n "
159+ "Please add validator when you create collection: db.create_collection.(coll_name, validator={'$jsonSchema': self._schema})"
160+ )
154161 self .collection = collection
155162
156163 # Include examples
Original file line number Diff line number Diff line change 2121INPUT: You will be provided a text document.
2222OUTPUT:
2323- You will produce valid json according the "Output Schema" section below.
24+ - Your response **must be** a **valid JSON document** with NO extra text, explanations, or markdown formatting.
2425- The extracted entities and relationships **MUST STRICTLY CONFORM** to the constraints outlined below.
2526- Any entities or relationships not matching the allowed types must be **EXCLUDED**.
2627
Original file line number Diff line number Diff line change 1717COLLECTION_NAME = "langchain_test_graphrag"
1818
1919
20- @pytest .fixture (scope = "function " )
20+ @pytest .fixture (scope = "module " )
2121def collection () -> Collection :
2222 client = MongoClient (MONGODB_URI )
2323 db = client [DB_NAME ]
@@ -36,7 +36,7 @@ def collection() -> Collection:
3636def entity_extraction_model () -> BaseChatModel :
3737 """LLM for converting documents into Graph of Entities and Relationships"""
3838 try :
39- return ChatOpenAI (model = "gpt-4o" , temperature = 0.0 )
39+ return ChatOpenAI (model = "gpt-4o" , temperature = 0.0 , cache = False )
4040 except Exception :
4141 pass
4242
@@ -114,7 +114,7 @@ def entity_example():
114114"""
115115
116116
117- @pytest .fixture (scope = "function " )
117+ @pytest .fixture (scope = "module " )
118118def graph_store (collection , entity_extraction_model , documents ) -> MongoDBGraphStore :
119119 store = MongoDBGraphStore (
120120 collection , entity_extraction_model , entity_prompt , query_prompt
You can’t perform that action at this time.
0 commit comments