diff --git a/docs/configuration/processing.md b/docs/configuration/processing.md index f57b23d7..aee16c3b 100644 --- a/docs/configuration/processing.md +++ b/docs/configuration/processing.md @@ -35,6 +35,7 @@ processing: # Image settings images_scale: 2.0 # Image scale factor + generate_picture_images: false # Include embedded images in output ``` ### Conversion Options @@ -73,10 +74,12 @@ conversion_options: ```yaml conversion_options: - images_scale: 2.0 # Image resolution scale factor + images_scale: 2.0 # Image resolution scale factor + generate_picture_images: false # Include embedded images in output ``` - **images_scale**: Scale factor for extracted images. Higher values = better quality but larger size. Typical range: 1.0-3.0. +- **generate_picture_images**: When `true`, embedded images (figures, diagrams) are included as base64-encoded data in the document. When `false` (default), images are excluded to reduce chunk size and avoid context bloat. ### Local vs Remote Processing diff --git a/haiku_rag_slim/haiku/rag/config/models.py b/haiku_rag_slim/haiku/rag/config/models.py index 9c8eeec2..36b58d11 100644 --- a/haiku_rag_slim/haiku/rag/config/models.py +++ b/haiku_rag_slim/haiku/rag/config/models.py @@ -106,6 +106,7 @@ class ConversionOptions(BaseModel): # Image options images_scale: float = 2.0 + generate_picture_images: bool = False class ProcessingConfig(BaseModel): diff --git a/haiku_rag_slim/haiku/rag/converters/docling_local.py b/haiku_rag_slim/haiku/rag/converters/docling_local.py index 64d817b5..594090a8 100644 --- a/haiku_rag_slim/haiku/rag/converters/docling_local.py +++ b/haiku_rag_slim/haiku/rag/converters/docling_local.py @@ -79,6 +79,7 @@ class DoclingLocalConverter(DocumentConverter): do_table_structure=opts.do_table_structure, images_scale=opts.images_scale, generate_page_images=True, + generate_picture_images=opts.generate_picture_images, table_structure_options=TableStructureOptions( do_cell_matching=opts.table_cell_matching, mode=( diff --git a/haiku_rag_slim/haiku/rag/converters/docling_serve.py b/haiku_rag_slim/haiku/rag/converters/docling_serve.py index 5f61d7bb..4cdb8257 100644 --- a/haiku_rag_slim/haiku/rag/converters/docling_serve.py +++ b/haiku_rag_slim/haiku/rag/converters/docling_serve.py @@ -88,6 +88,7 @@ class DoclingServeConverter(DocumentConverter): "table_mode": opts.table_mode, "table_cell_matching": str(opts.table_cell_matching).lower(), "images_scale": str(opts.images_scale), + "generate_picture_images": str(opts.generate_picture_images).lower(), } if opts.ocr_lang: diff --git a/tests/test_converters.py b/tests/test_converters.py index c8fd2f85..595831bb 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -237,6 +237,45 @@ class TestDoclingLocalConverter: assert converter.config.processing.conversion_options.table_mode == "fast" assert converter.config.processing.conversion_options.images_scale == 3.0 + @pytest.mark.asyncio + async def test_convert_pdf_without_picture_images(self, config): + """Test PDF conversion excludes embedded images by default.""" + pdf_path = Path("tests/data/doclaynet.pdf") + if not pdf_path.exists(): + pytest.skip("doclaynet.pdf not found") + + config.processing.conversion_options.generate_picture_images = False + converter = DoclingLocalConverter(config) + + doc = await converter.convert_file(pdf_path) + assert isinstance(doc, DoclingDocument) + + # Check that pictures don't have image data + for picture in doc.pictures: + assert picture.image is None, ( + "Pictures should not have image data when generate_picture_images=False" + ) + + @pytest.mark.asyncio + async def test_convert_pdf_with_picture_images(self, config): + """Test PDF conversion includes embedded images when enabled.""" + pdf_path = Path("tests/data/doclaynet.pdf") + if not pdf_path.exists(): + pytest.skip("doclaynet.pdf not found") + + config.processing.conversion_options.generate_picture_images = True + converter = DoclingLocalConverter(config) + + doc = await converter.convert_file(pdf_path) + assert isinstance(doc, DoclingDocument) + + # Check that at least some pictures have image data + pictures_with_images = [p for p in doc.pictures if p.image is not None] + if doc.pictures: + assert len(pictures_with_images) > 0, ( + "Pictures should have image data when generate_picture_images=True" + ) + class TestDoclingServeConverter: """Tests for DoclingServeConverter (mocked)."""