Skip to content

Commit ccee700

Browse files
GraphRAG CI Fixes
1 parent 8392af7 commit ccee700

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

libs/langchain-mongodb/langchain_mongodb/graphrag/graph.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pymongo import MongoClient, UpdateOne
1515
from pymongo.collection import Collection
1616
from pymongo.driver_info import DriverInfo
17+
from pymongo.errors import OperationFailure
1718
from pymongo.results import BulkWriteResult
1819

1920
from 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

libs/langchain-mongodb/langchain_mongodb/graphrag/prompts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
INPUT: You will be provided a text document.
2222
OUTPUT:
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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
COLLECTION_NAME = "langchain_test_graphrag"
1818

1919

20-
@pytest.fixture(scope="function")
20+
@pytest.fixture(scope="module")
2121
def collection() -> Collection:
2222
client = MongoClient(MONGODB_URI)
2323
db = client[DB_NAME]
@@ -36,7 +36,7 @@ def collection() -> Collection:
3636
def 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")
118118
def graph_store(collection, entity_extraction_model, documents) -> MongoDBGraphStore:
119119
store = MongoDBGraphStore(
120120
collection, entity_extraction_model, entity_prompt, query_prompt

0 commit comments

Comments
 (0)