Drop redundant _apply_descriptions_sync unit test, annotate the helper
This commit is contained in:
parent
a137b91654
commit
775dc58b53
2 changed files with 5 additions and 29 deletions
|
|
@ -18,6 +18,8 @@ from haiku.rag.store.models.document_item import extract_items
|
||||||
from haiku.rag.store.repositories.settings import SettingsRepository
|
from haiku.rag.store.repositories.settings import SettingsRepository
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from docling_core.types.doc.document import DoclingDocument
|
||||||
|
|
||||||
from haiku.rag.client import HaikuRAG, RebuildMode
|
from haiku.rag.client import HaikuRAG, RebuildMode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -621,7 +623,9 @@ async def _rebuild_rechunk(
|
||||||
await _flush_rebuild_batch(client, pending_docs, pending_chunks)
|
await _flush_rebuild_batch(client, pending_docs, pending_chunks)
|
||||||
|
|
||||||
|
|
||||||
def _apply_descriptions_sync(docling_doc, doc, descriptions):
|
def _apply_descriptions_sync(
|
||||||
|
docling_doc: "DoclingDocument", doc: Document, descriptions: dict[str, str]
|
||||||
|
) -> int:
|
||||||
"""Patch picture descriptions into the docling document and re-compress.
|
"""Patch picture descriptions into the docling document and re-compress.
|
||||||
|
|
||||||
Updates only docling_document — set_docling would also overwrite
|
Updates only docling_document — set_docling would also overwrite
|
||||||
|
|
|
||||||
|
|
@ -970,34 +970,6 @@ async def test_rebuild_descriptions_raises_when_blob_is_missing(
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_apply_descriptions_sync_skips_pictures_without_descriptions():
|
|
||||||
"""_apply_descriptions_sync skips pictures not in the descriptions dict."""
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
from haiku.rag.client.rebuild import _apply_descriptions_sync
|
|
||||||
|
|
||||||
pic_with = MagicMock()
|
|
||||||
pic_with.self_ref = "pic-1"
|
|
||||||
pic_with.meta = None
|
|
||||||
|
|
||||||
pic_without = MagicMock()
|
|
||||||
pic_without.self_ref = "pic-2"
|
|
||||||
|
|
||||||
docling_doc = MagicMock()
|
|
||||||
docling_doc.pictures = [pic_with, pic_without]
|
|
||||||
docling_doc.model_dump_json.return_value = "{}"
|
|
||||||
docling_doc.version = "1.0"
|
|
||||||
|
|
||||||
doc = MagicMock()
|
|
||||||
|
|
||||||
descriptions = {"pic-1": "A red square."}
|
|
||||||
n = _apply_descriptions_sync(docling_doc, doc, descriptions)
|
|
||||||
|
|
||||||
assert n == 1
|
|
||||||
assert pic_with.meta is not None
|
|
||||||
assert pic_with.meta.description.text == "A red square."
|
|
||||||
|
|
||||||
|
|
||||||
async def _add_chunk(client: HaikuRAG, vector: list[float]) -> str:
|
async def _add_chunk(client: HaikuRAG, vector: list[float]) -> str:
|
||||||
"""Insert a chunk row directly, bypassing the embedder."""
|
"""Insert a chunk row directly, bypassing the embedder."""
|
||||||
record = client.store.ChunkRecord(
|
record = client.store.ChunkRecord(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue