Skip to content
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
2 changes: 1 addition & 1 deletion openrag/components/indexer/loaders/CustomDocLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ async def aload_document(self, file_path, metadata: dict = None):

s = ""
for page_num, p in enumerate(pages, start=1):
s = p.page_content.strip() + f"\n[PAGE_{page_num}]\n"
s += p.page_content.strip() + f"\n[PAGE_{page_num}]\n"

return Document(page_content=s, metadata=metadata)
40 changes: 40 additions & 0 deletions openrag/components/indexer/loaders/test_customdocloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Regression test for CustomDocLoader page accumulation (#376).

The previous loop body used ``s = ...`` instead of ``s += ...``, so only
the final page survived. This test confirms every page's content is now
in the returned ``Document``.
"""

from unittest.mock import AsyncMock, MagicMock, patch

import pytest
from langchain_core.documents.base import Document as LCDocument


@pytest.mark.asyncio
async def test_customdocloader_accumulates_all_pages(tmp_path):
from components.indexer.loaders.CustomDocLoader import CustomDocLoader

fake_pages = [
LCDocument(page_content="page-one"),
LCDocument(page_content="page-two"),
LCDocument(page_content="page-three"),
]
fake_loader_instance = MagicMock()
fake_loader_instance.aload = AsyncMock(return_value=fake_pages)
fake_loader_cls = MagicMock(return_value=fake_loader_instance)

file_path = tmp_path / "stub.docx"
file_path.write_text("ignored")

with patch.dict(CustomDocLoader.doc_loaders, {".docx": fake_loader_cls}, clear=True):
# BaseLoader.__init__ pulls a config; we bypass it with object.__new__
loader = object.__new__(CustomDocLoader)
result = await loader.aload_document(str(file_path), metadata={"src": "x"})

assert "page-one" in result.page_content
assert "page-two" in result.page_content
assert "page-three" in result.page_content
assert "[PAGE_1]" in result.page_content
assert "[PAGE_2]" in result.page_content
assert "[PAGE_3]" in result.page_content
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Loading