Chunkers now set chunk.order directly

This commit is contained in:
Yiorgis Gozadinos 2025-12-18 11:35:48 +02:00
parent d77bf89aad
commit 50b7fb4461
No known key found for this signature in database
5 changed files with 43 additions and 9 deletions

View file

@ -14,6 +14,7 @@
### Changed
- **Chunker Sets Order**: Chunkers now set `chunk.order` directly
- **Evaluations Vacuum Strategy**: `populate_db` now uses periodic vacuum to prevent disk exhaustion with large datasets
- Disables auto_vacuum during population, vacuums every N documents with retention=0
- New `--vacuum-interval` CLI option (default: 100) to control vacuum frequency

View file

@ -155,6 +155,12 @@ class DoclingLocalChunker(DocumentChunker):
labels=labels,
page_numbers=sorted(page_numbers),
)
result.append(Chunk(content=text, metadata=chunk_metadata.model_dump()))
result.append(
Chunk(
content=text,
metadata=chunk_metadata.model_dump(),
order=len(result),
)
)
return result

View file

@ -192,6 +192,12 @@ class DoclingServeChunker(DocumentChunker):
labels=labels,
page_numbers=sorted(page_numbers) if page_numbers else [],
)
result.append(Chunk(content=text, metadata=chunk_metadata.model_dump()))
result.append(
Chunk(
content=text,
metadata=chunk_metadata.model_dump(),
order=len(result),
)
)
return result

View file

@ -194,13 +194,7 @@ class HaikuRAG:
from haiku.rag.chunkers import get_chunker
chunker = get_chunker(self._config)
chunks = await chunker.chunk(docling_document)
# Set order for each chunk
for i, chunk in enumerate(chunks):
chunk.order = i
return chunks
return await chunker.chunk(docling_document)
async def _ensure_chunks_embedded(self, chunks: list[Chunk]) -> list[Chunk]:
"""Ensure all chunks have embeddings, embedding any that don't.

View file

@ -144,6 +144,33 @@ async def test_local_chunker_markdown_tables():
assert "," in table_content and "|" not in table_content
@pytest.mark.asyncio
async def test_local_chunker_sets_order():
"""Test that DoclingLocalChunker sets sequential order on chunks."""
sample_md = """# Introduction
First paragraph with some content.
## Section One
Second paragraph.
## Section Two
Third paragraph.
"""
converter = get_converter(Config)
doc = await converter.convert_text(sample_md, name="test.md")
chunker = DoclingLocalChunker()
chunks = await chunker.chunk(doc)
assert len(chunks) > 0
# Verify order is set sequentially starting from 0
for i, chunk in enumerate(chunks):
assert chunk.order == i, f"Chunk {i} has order {chunk.order}, expected {i}"
@pytest.mark.asyncio
async def test_local_chunker_metadata_extraction():
"""Test that DoclingLocalChunker extracts metadata correctly."""