Chunkers now set chunk.order directly
This commit is contained in:
parent
d77bf89aad
commit
50b7fb4461
5 changed files with 43 additions and 9 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
### Changed
|
### 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
|
- **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
|
- Disables auto_vacuum during population, vacuums every N documents with retention=0
|
||||||
- New `--vacuum-interval` CLI option (default: 100) to control vacuum frequency
|
- New `--vacuum-interval` CLI option (default: 100) to control vacuum frequency
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,12 @@ class DoclingLocalChunker(DocumentChunker):
|
||||||
labels=labels,
|
labels=labels,
|
||||||
page_numbers=sorted(page_numbers),
|
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
|
return result
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,12 @@ class DoclingServeChunker(DocumentChunker):
|
||||||
labels=labels,
|
labels=labels,
|
||||||
page_numbers=sorted(page_numbers) if page_numbers else [],
|
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
|
return result
|
||||||
|
|
|
||||||
|
|
@ -194,13 +194,7 @@ class HaikuRAG:
|
||||||
from haiku.rag.chunkers import get_chunker
|
from haiku.rag.chunkers import get_chunker
|
||||||
|
|
||||||
chunker = get_chunker(self._config)
|
chunker = get_chunker(self._config)
|
||||||
chunks = await chunker.chunk(docling_document)
|
return await chunker.chunk(docling_document)
|
||||||
|
|
||||||
# Set order for each chunk
|
|
||||||
for i, chunk in enumerate(chunks):
|
|
||||||
chunk.order = i
|
|
||||||
|
|
||||||
return chunks
|
|
||||||
|
|
||||||
async def _ensure_chunks_embedded(self, chunks: list[Chunk]) -> list[Chunk]:
|
async def _ensure_chunks_embedded(self, chunks: list[Chunk]) -> list[Chunk]:
|
||||||
"""Ensure all chunks have embeddings, embedding any that don't.
|
"""Ensure all chunks have embeddings, embedding any that don't.
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,33 @@ async def test_local_chunker_markdown_tables():
|
||||||
assert "," in table_content and "|" not in table_content
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_local_chunker_metadata_extraction():
|
async def test_local_chunker_metadata_extraction():
|
||||||
"""Test that DoclingLocalChunker extracts metadata correctly."""
|
"""Test that DoclingLocalChunker extracts metadata correctly."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue