Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphRAG CI Fixes #82

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions libs/langchain-mongodb/langchain_mongodb/graphrag/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pymongo import MongoClient, UpdateOne
from pymongo.collection import Collection
from pymongo.driver_info import DriverInfo
from pymongo.errors import OperationFailure
from pymongo.results import BulkWriteResult

from langchain_mongodb.graphrag import example_templates, prompts
Expand Down Expand Up @@ -140,12 +141,18 @@ def __init__(
self.allowed_relationship_types = []

if validate:
collection.database.command(
"collMod",
collection.name,
validator={"$jsonSchema": self._schema},
validationAction=validation_action,
)
try:
collection.database.command(
"collMod",
collection.name,
validator={"$jsonSchema": self._schema},
validationAction=validation_action,
)
except OperationFailure:
logger.warning(
"Validation will NOT be performed. User must be DB Admin to add validation **after** a Collection is created. \n"
"Please add validator when you create collection: db.create_collection.(coll_name, validator={'$jsonSchema': self._schema})"
)
self.collection = collection

# Include examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
INPUT: You will be provided a text document.
OUTPUT:
- You will produce valid json according the "Output Schema" section below.
- Your response **must be** a **valid JSON document** with NO extra text, explanations, or markdown formatting.
- The extracted entities and relationships **MUST STRICTLY CONFORM** to the constraints outlined below.
- Any entities or relationships not matching the allowed types must be **EXCLUDED**.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
COLLECTION_NAME = "langchain_test_graphrag"


@pytest.fixture(scope="function")
@pytest.fixture(scope="module")
def collection() -> Collection:
client = MongoClient(MONGODB_URI)
db = client[DB_NAME]
Expand All @@ -36,7 +36,7 @@ def collection() -> Collection:
def entity_extraction_model() -> BaseChatModel:
"""LLM for converting documents into Graph of Entities and Relationships"""
try:
return ChatOpenAI(model="gpt-4o", temperature=0.0)
return ChatOpenAI(model="gpt-4o", temperature=0.0, cache=False)
except Exception:
pass

Expand Down Expand Up @@ -114,7 +114,7 @@ def entity_example():
"""


@pytest.fixture(scope="function")
@pytest.fixture(scope="module")
def graph_store(collection, entity_extraction_model, documents) -> MongoDBGraphStore:
store = MongoDBGraphStore(
collection, entity_extraction_model, entity_prompt, query_prompt
Expand Down
Loading