Skip to content

Commit 2df734f

Browse files
INTPYTHON-330 GraphRAG (#66)
Co-authored-by: Steven Silvester <[email protected]>
1 parent 1dbfee3 commit 2df734f

File tree

9 files changed

+1164
-3
lines changed

9 files changed

+1164
-3
lines changed

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

Whitespace-only changes.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
"""These prompts serve as defaults, and templates when you wish to override them.
2+
3+
LLM performance can be greatly increased by adding domain-specific examples.
4+
"""
5+
6+
entity_extraction = """
7+
## Examples
8+
Use the following examples to guide your work.
9+
10+
### Example 1: Constrained entity and relationship types: Person, Friend
11+
#### Input
12+
Alice Palace has been the CEO of MongoDB since January 1, 2018.
13+
She maintains close friendships with Jarnail Singh, whom she has known since May 1, 2019,
14+
and Jasbinder Kaur, who she has been seeing weekly since May 1, 2015.
15+
16+
#### Output
17+
(If `allowed_entity_types` is ["Person"] and `allowed_relationship_types` is ["Friend"])
18+
{{
19+
"entities": [
20+
{{
21+
"_id": "Alice Palace",
22+
"type": "Person",
23+
"attributes": {{
24+
"job": ["CEO of MongoDB"],
25+
"startDate": ["2018-01-01"]
26+
}},
27+
"relationships": {{
28+
"targets": ["Jasbinder Kaur", "Jarnail Singh"],
29+
"types": ["Friend", "Friend"],
30+
"attributes": [
31+
{{ "since": ["2019-05-01"] }},
32+
{{ "since": ["2015-05-01"], "frequency": ["weekly"] }}
33+
]
34+
}}
35+
}},
36+
{{
37+
"_id": "Jarnail Singh",
38+
"type": "Person",
39+
"relationships": {{
40+
"targets": ["Alice Palace"],
41+
"types": ["Friend"],
42+
"attributes": [{{ "since": ["2019-05-01"] }}]
43+
}}
44+
}},
45+
{{
46+
"_id": "Jasbinder Kaur",
47+
"type": "Person",
48+
"relationships": {{
49+
"targets": ["Alice Palace"],
50+
"types": ["Friend"],
51+
"attributes": [{{ "since": ["2015-05-01"], "frequency": ["weekly"] }}]
52+
}}
53+
}}
54+
]
55+
}}
56+
57+
### Example 2: Event Extraction
58+
#### Input
59+
The 2022 OpenAI Developer Conference took place on October 10, 2022, in San Francisco.
60+
Elon Musk and Sam Altman were keynote speakers at the event.
61+
62+
#### Output
63+
(If `allowed_entity_types` is ["Event", "Person"] and `allowed_relationship_types` is ["Speaker"])
64+
{{
65+
"entities": [
66+
{{
67+
"_id": "2022 OpenAI Developer Conference",
68+
"type": "Event",
69+
"attributes": {{
70+
"date": ["2022-10-10"],
71+
"location": ["San Francisco"]
72+
}},
73+
"relationships": {{
74+
"targets": ["Elon Musk", "Sam Altman"],
75+
"types": ["Speaker", "Speaker"]
76+
}}
77+
}},
78+
{{ "_id": "Elon Musk", "type": "Person" }},
79+
{{ "_id": "Sam Altman", "type": "Person" }}
80+
]
81+
}}
82+
83+
### Example 3: Concept Relationship
84+
#### Input
85+
Quantum computing is a field of study that focuses on developing computers based on the principles of quantum mechanics.
86+
87+
#### Output
88+
(If `allowed_entity_types` is ["Concept"] and `allowed_relationship_types` is ["Based On"])
89+
{{
90+
"entities": [
91+
{{
92+
"_id": "Quantum Computing",
93+
"type": "Concept",
94+
"relationships": {{
95+
"targets": ["Quantum Mechanics"],
96+
"types": ["Based On"]
97+
}}
98+
}},
99+
{{ "_id": "Quantum Mechanics", "type": "Concept" }}
100+
]
101+
}}
102+
103+
### Example 4: News Article
104+
#### Input
105+
On March 1, 2023, NASA successfully launched the Artemis II mission, sending astronauts to orbit the Moon.
106+
NASA Administrator Bill Nelson praised the historic achievement.
107+
108+
#### Output
109+
(If `allowed_entity_types` is ["Organization", "Event", "Person"] and `allowed_relationship_types` is ["Managed By", "Praised By"])
110+
{{
111+
"entities": [
112+
{{
113+
"_id": "Artemis II Mission",
114+
"type": "Event",
115+
"attributes": {{ "date": ["2023-03-01"] }},
116+
"relationships": {{
117+
"targets": ["NASA"],
118+
"types": ["Managed By"]
119+
}}
120+
}},
121+
{{
122+
"_id": "NASA",
123+
"type": "Organization"
124+
}},
125+
{{
126+
"_id": "Bill Nelson",
127+
"type": "Person",
128+
"relationships": {{
129+
"targets": ["Artemis II Mission"],
130+
"types": ["Praised By"]
131+
}}
132+
}}
133+
]
134+
}}
135+
136+
### Example 5: Technical Article
137+
#### Input
138+
Rust is a programming language that guarantees memory safety without requiring garbage collection.
139+
It is known for its strong ownership model, which prevents data races.
140+
141+
#### Output
142+
(If `allowed_entity_types` is ["Programming Language", "Concept"] and `allowed_relationship_types` is ["Ensures", "Uses"])
143+
{{
144+
"entities": [
145+
{{
146+
"_id": "Rust",
147+
"type": "Programming Language",
148+
"relationships": {{
149+
"targets": ["Memory Safety"],
150+
"types": ["Ensures"]
151+
}}
152+
}},
153+
{{
154+
"_id": "Memory Safety",
155+
"type": "Concept",
156+
"relationships": {{
157+
"targets": ["Ownership Model"],
158+
"types": ["Uses"]
159+
}}
160+
}},
161+
{{ "_id": "Ownership Model", "type": "Concept" }}
162+
]
163+
}}
164+
"""

0 commit comments

Comments
 (0)