@@ -108,5 +108,148 @@ async def test_pipeline_builder_happy_path(
108108 )
109109
110110 # Run the knowledge graph building process with text input
111- text_input = "John Doe lives in New York City."
112- await kg_builder_text .run_async (text = text_input )
111+ await kg_builder_text .run_async (text = harry_potter_text )
112+
113+
114+
115+ @pytest .mark .asyncio
116+ @pytest .mark .usefixtures ("setup_neo4j_for_kg_construction" )
117+ async def test_pipeline_builder_two_documents (
118+ harry_potter_text_part1 : str ,
119+ harry_potter_text_part2 : str ,
120+ llm : MagicMock ,
121+ embedder : MagicMock ,
122+ driver : neo4j .Driver ,
123+ ) -> None :
124+ """When everything works as expected, extracted entities, relations and text
125+ chunks must be in the DB
126+ """
127+ driver .execute_query ("MATCH (n) DETACH DELETE n" )
128+ embedder .embed_query .return_value = [1 , 2 , 3 ]
129+ llm .ainvoke .side_effect = [
130+ # first document
131+ # first chunk
132+ LLMResponse (
133+ content = """{
134+ "nodes": [
135+ {
136+ "id": "0",
137+ "label": "Person",
138+ "properties": {
139+ "name": "Harry Potter"
140+ }
141+ },
142+ ],
143+ "relationships": []
144+ }"""
145+ ),
146+ # second chunk
147+ LLMResponse (content = '{"nodes": [], "relationships": []}' ),
148+ # second document
149+ # first chunk
150+ LLMResponse (
151+ content = """{
152+ "nodes": [
153+ {
154+ "id": "0",
155+ "label": "Person",
156+ "properties": {
157+ "name": "Hermione Granger"
158+ }
159+ },
160+ ],
161+ "relationships": []
162+ }"""
163+ ),
164+ # second chunk
165+ LLMResponse (content = '{"nodes": [], "relationships": []}' ),
166+ ]
167+
168+ # Create an instance of the SimpleKGPipeline
169+ kg_builder_text = SimpleKGPipeline (
170+ llm = llm ,
171+ driver = driver ,
172+ embedder = embedder ,
173+ from_pdf = False ,
174+ )
175+
176+ # Run the knowledge graph building process with text input
177+ await kg_builder_text .run_async (text = harry_potter_text_part1 )
178+ await kg_builder_text .run_async (text = harry_potter_text_part2 )
179+
180+ # check graph content
181+ records , _ , _ = driver .execute_query ("MATCH (n) RETURN n" )
182+ print (records )
183+
184+ assert False
185+
186+
187+ @pytest .mark .asyncio
188+ @pytest .mark .usefixtures ("setup_neo4j_for_kg_construction" )
189+ async def test_pipeline_builder_same_document_two_runs (
190+ harry_potter_text_part1 : str ,
191+ llm : MagicMock ,
192+ embedder : MagicMock ,
193+ driver : neo4j .Driver ,
194+ ) -> None :
195+ """When everything works as expected, extracted entities, relations and text
196+ chunks must be in the DB
197+ """
198+ driver .execute_query ("MATCH (n) DETACH DELETE n" )
199+ embedder .embed_query .return_value = [1 , 2 , 3 ]
200+ llm .ainvoke .side_effect = [
201+ # first run
202+ # first chunk
203+ LLMResponse (
204+ content = """{
205+ "nodes": [
206+ {
207+ "id": "0",
208+ "label": "Person",
209+ "properties": {
210+ "name": "Harry Potter"
211+ }
212+ },
213+ ],
214+ "relationships": []
215+ }"""
216+ ),
217+ # second chunk
218+ LLMResponse (content = '{"nodes": [], "relationships": []}' ),
219+ # second run
220+ # first chunk
221+ LLMResponse (
222+ content = """{
223+ "nodes": [
224+ {
225+ "id": "0",
226+ "label": "Person",
227+ "properties": {
228+ "name": "Harry Potter"
229+ }
230+ },
231+ ],
232+ "relationships": []
233+ }"""
234+ ),
235+ # second chunk
236+ LLMResponse (content = '{"nodes": [], "relationships": []}' ),
237+ ]
238+
239+ # Create an instance of the SimpleKGPipeline
240+ kg_builder_text = SimpleKGPipeline (
241+ llm = llm ,
242+ driver = driver ,
243+ embedder = embedder ,
244+ from_pdf = False ,
245+ )
246+
247+ # Run the knowledge graph building process with text input
248+ await kg_builder_text .run_async (text = harry_potter_text_part1 )
249+ await kg_builder_text .run_async (text = harry_potter_text_part1 )
250+
251+ # check graph content
252+ records , _ , _ = driver .execute_query ("MATCH (n) RETURN n" )
253+ print (records )
254+
255+ assert False
0 commit comments