diff --git a/.semversioner/next-release/patch-20260705142108838934.json b/.semversioner/next-release/patch-20260705142108838934.json new file mode 100644 index 000000000..a5291f0f2 --- /dev/null +++ b/.semversioner/next-release/patch-20260705142108838934.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Ignore blank lines when loading JSONL input files." +} diff --git a/packages/graphrag-input/graphrag_input/jsonl.py b/packages/graphrag-input/graphrag_input/jsonl.py index f038aafaa..cea9d6b27 100644 --- a/packages/graphrag-input/graphrag_input/jsonl.py +++ b/packages/graphrag-input/graphrag_input/jsonl.py @@ -34,5 +34,5 @@ async def read_file(self, path: str) -> list[TextDocument]: - output - list with a TextDocument for each row in the file. """ text = await self._storage.get(path, encoding=self._encoding) - rows = [json.loads(line) for line in text.splitlines()] + rows = [json.loads(line) for line in text.splitlines() if line.strip()] return await self.process_data_columns(rows, path) diff --git a/tests/unit/indexing/input/test_jsonl_loader.py b/tests/unit/indexing/input/test_jsonl_loader.py index dd5609429..80aea5afe 100644 --- a/tests/unit/indexing/input/test_jsonl_loader.py +++ b/tests/unit/indexing/input/test_jsonl_loader.py @@ -40,3 +40,24 @@ async def test_jsonl_loader_one_file_with_title(): documents = await reader.read_files() assert len(documents) == 3 assert documents[0].title == "Hello" + + +async def test_jsonl_loader_ignores_blank_lines(tmp_path): + (tmp_path / "input.jsonl").write_text( + '{"title":"Hello","text":"Hi"}\n\n \n{"title":"Goodbye","text":"Bye"}\n', + encoding="utf-8", + ) + config = InputConfig( + type=InputType.JsonLines, + title_column="title", + ) + storage = create_storage( + StorageConfig( + base_dir=str(tmp_path), + ) + ) + reader = create_input_reader(config, storage) + documents = await reader.read_files() + assert len(documents) == 2 + assert [doc.title for doc in documents] == ["Hello", "Goodbye"] + assert [doc.text for doc in documents] == ["Hi", "Bye"]