Skip to content

Commit 8392af7

Browse files
INTPYTHON-515 Release GraphRAG langchain-mongodb 0.5.0 (#80)
1 parent 2df734f commit 8392af7

File tree

6 files changed

+641
-378
lines changed

6 files changed

+641
-378
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ It contains the following packages.
2929
- [MongoDBRecordManager](https://langchain-mongodb.readthedocs.io/en/latest/langchain_mongodb/indexes/langchain_mongodb.indexes.MongoDBRecordManager.html#langchain_mongodb.indexes.MongoDBRecordManager)
3030
- Loading
3131
- [MongoDBLoader](https://langchain-mongodb.readthedocs.io/en/latest/langchain_mongodb/loaders/langchain_mongodb.loaders.MongoDBLoader.html#langchain_mongodb.loaders.MongoDBLoader)
32+
- GraphRAG
33+
- [MongoDBGraphStore](https://langchain-mongodb.readthedocs.io/en/latest/langchain_mongodb/graphrag/langchain_mongodb.graphrag.graph.MongoDBGraphStore.html)
3234

3335
### LangGraph
3436

libs/langchain-mongodb/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
---
44

5-
## Changes in version 0.5 (YYYY/MM/DD)
5+
## Changes in version 0.5 (2025/02/11)
66

7-
- TBD
7+
- Added GraphRAG support via `MongoDBGraphStore`
88

99
## Changes in version 0.4 (2025/01/09)
1010

libs/langchain-mongodb/README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from libs.community.tests.unit_tests.chains.test_pebblo_retrieval import retriever
2+
13
# langchain-mongodb
24

35
# Installation
@@ -6,34 +8,31 @@ pip install -U langchain-mongodb
68
```
79

810
# Usage
9-
- See [Getting Started with the LangChain Integration](https://www.mongodb.com/docs/atlas/atlas-vector-search/ai-integrations/langchain/#get-started-with-the-langchain-integration) for a walkthrough on using your first LangChain implementation with MongoDB Atlas.
11+
- [Integrate Atlas Vector Search with LangChain](https://www.mongodb.com/docs/atlas/atlas-vector-search/ai-integrations/langchain/#get-started-with-the-langchain-integration) for a walkthrough on using your first LangChain implementation with MongoDB Atlas.
1012

1113
## Using MongoDBAtlasVectorSearch
1214
```python
15+
import os
1316
from langchain_mongodb import MongoDBAtlasVectorSearch
17+
from langchain_openai import OpenAIEmbeddings
1418

1519
# Pull MongoDB Atlas URI from environment variables
16-
MONGODB_ATLAS_CLUSTER_URI = os.environ.get("MONGODB_ATLAS_CLUSTER_URI")
17-
20+
MONGODB_ATLAS_CONNECTION_STRING = os.environ["MONGODB_CONNECTION_STRING"]
1821
DB_NAME = "langchain_db"
1922
COLLECTION_NAME = "test"
20-
ATLAS_VECTOR_SEARCH_INDEX_NAME = "index_name"
21-
MONGODB_COLLECTION = client[DB_NAME][COLLECTION_NAME]
22-
23-
# Create the vector search via `from_connection_string`
24-
vector_search = MongoDBAtlasVectorSearch.from_connection_string(
25-
MONGODB_ATLAS_CLUSTER_URI,
26-
DB_NAME + "." + COLLECTION_NAME,
27-
OpenAIEmbeddings(disallowed_special=()),
28-
index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
29-
)
23+
VECTOR_SEARCH_INDEX_NAME = "index_name"
3024

31-
# Initialize MongoDB python client
32-
client = MongoClient(MONGODB_ATLAS_CLUSTER_URI)
33-
# Create the vector search via instantiation
34-
vector_search_2 = MongoDBAtlasVectorSearch(
35-
collection=MONGODB_COLLECTION,
36-
embeddings=OpenAIEmbeddings(disallowed_special=()),
37-
index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
25+
MODEL_NAME = "text-embedding-3-large"
26+
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
27+
28+
29+
vectorstore = MongoDBAtlasVectorSearch.from_connection_string(
30+
connection_string=MONGODB_ATLAS_CONNECTION_STRING,
31+
namespace=DB_NAME + "." + COLLECTION_NAME,
32+
embedding=OpenAIEmbeddings(model=MODEL_NAME),
33+
index_name=VECTOR_SEARCH_INDEX_NAME,
3834
)
35+
36+
retrieved_docs = vectorstore.similarity_search(
37+
"How do I deploy MongoDBAtlasVectorSearch in our production environment?")
3938
```

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def __init__(
9393
self,
9494
collection: Collection,
9595
entity_extraction_model: BaseChatModel,
96-
entity_prompt: ChatPromptTemplate = prompts.entity_prompt,
97-
query_prompt: ChatPromptTemplate = prompts.query_prompt,
96+
entity_prompt: ChatPromptTemplate = None,
97+
query_prompt: ChatPromptTemplate = None,
9898
max_depth: int = 2,
9999
allowed_entity_types: List[str] = None,
100100
allowed_relationship_types: List[str] = None,
@@ -108,7 +108,9 @@ def __init__(
108108
collection: Collection representing an Entity Graph.
109109
entity_extraction_model: LLM for converting documents into Graph of Entities and Relationships.
110110
entity_prompt: Prompt to fill graph store with entities following schema.
111+
Defaults to .prompts.ENTITY_EXTRACTION_INSTRUCTIONS
111112
query_prompt: Prompt extracts entities and relationships as search starting points.
113+
Defaults to .prompts.NAME_EXTRACTION_INSTRUCTIONS
112114
max_depth: Maximum recursion depth in graph traversal.
113115
allowed_entity_types: If provided, constrains search to these types.
114116
allowed_relationship_types: If provided, constrains search to these types.
@@ -120,8 +122,12 @@ def __init__(
120122
- If "error", an exception will be raised if any document does not match the schema.
121123
"""
122124
self.entity_extraction_model = entity_extraction_model
123-
self.entity_prompt = entity_prompt
124-
self.query_prompt = query_prompt
125+
self.entity_prompt = (
126+
prompts.entity_prompt if entity_prompt is None else entity_prompt
127+
)
128+
self.query_prompt = (
129+
prompts.query_prompt if query_prompt is None else query_prompt
130+
)
125131
self.max_depth = max_depth
126132
self._schema = deepcopy(entity_schema)
127133
if allowed_entity_types:
@@ -138,7 +144,6 @@ def __init__(
138144
] = allowed_relationship_types
139145
else:
140146
self.allowed_relationship_types = []
141-
142147
if validate:
143148
collection.database.command(
144149
"collMod",
@@ -155,7 +160,6 @@ def __init__(
155160
1,
156161
SystemMessagePromptTemplate.from_template(entity_examples),
157162
)
158-
159163
if entity_name_examples:
160164
self.query_prompt.messages.insert(
161165
1,

libs/langchain-mongodb/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55

66
[project]
77
name = "langchain-mongodb"
8-
version = "0.4.0"
8+
version = "0.5.0"
99
description = "An integration package connecting MongoDB and LangChain"
1010
readme = "README.md"
1111
requires-python = ">=3.9"

0 commit comments

Comments
 (0)