Search image-bearing documents while keeping captions, OCR text, crop coordinates and permissions tied to the exact source revision.
Multimodal retrieval: connect images, OCR and text to one asset identity
Define the asset graph
A diagram may have a text caption, OCR labels, a surrounding paragraph and a visual embedding. Give all views one immutable asset revision, then store their own modality and location. A match in OCR is evidence for visible words, not for a visual relation that OCR cannot read. A visual similarity match locates candidate images; it does not prove that two valves have the same operating limit. Source provenance must survive the modality change.
Retrieve and fuse carefully
Text queries can search captions and OCR; image queries can use visual embeddings. Fuse candidate asset IDs only after permission and revision checks. Preserve the match route in the result: caption, OCR, surrounding text or image similarity. This matters when a reviewer asks why a drawing ranked first. Rerank with the full question and a bounded set of candidate assets, not a collection of detached crop embeddings.
Resolve the cited region
An answer about a label in the upper-left crop should cite that region and its parent page. Store normalized crop coordinates and the original image dimensions so a viewer can highlight the right area. If preprocessing rotates or resizes the image, transform coordinates back before presenting them. A citation to an entire manual page may be too broad when the claim depends on a tiny annotation. Support checks should confirm the cited modality can prove the claim.
Measure modality-specific misses
Maintain query slices for exact OCR strings, paraphrased captions, visual resemblance and questions requiring both text and image. Evaluate candidate recall by modality and asset revision. A high combined score can conceal that OCR systematically misses rotated labels. Keep a no-answer slice where a visually similar image lacks the requested label, and require the system to say so.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class AssetView:
asset_id: str
revision: str
tenant: str
modality: str
content: str
def find_label(views: list[AssetView], label: str, tenant: str,
active_revisions: dict[str, str]) -> list[str]:
return sorted({view.asset_id for view in views
if view.tenant == tenant and view.modality == "ocr"
and active_revisions.get(view.asset_id) == view.revision
and label.casefold() in view.content.casefold()})
views = [AssetView("pump-47", "r3", "plant-a", "ocr", "Outlet 47 kPa"),
AssetView("pump-47", "r2", "plant-a", "ocr", "Outlet 73 kPa"),
AssetView("pump-47", "r3", "plant-b", "ocr", "Outlet 47 kPa")]
assert find_label(views, "47 kPa", "plant-a", {"pump-47": "r3"}) == ["pump-47"]
assert find_label(views, "73 kPa", "plant-a", {"pump-47": "r3"}) == []Performance and operating cost
The sample scans V views in O(V) time and uses O(A) result space for A matching assets. Production retrieval can index each modality, but storage and embedding work grow with the number of views and crops. Set crop limits and deduplicate near-identical renders; otherwise one document can flood the candidate window.
Common Mistakes
- Using visual similarity as proof of a printed numeric label.
- Returning a crop without its parent asset and revision.
- Mixing a fresh caption with OCR from an old image revision.
- Showing a broad page citation when only one crop supports the answer.
Validation drill
Index 17 diagrams with captions and OCR, including three rotated scans and two superseded revisions. Judge exact-label, visual and mixed queries separately; verify every cited crop opens at the correct page and coordinates.
Read next
- Document extraction: preserve passage provenance through OCR and parsing
- Context packing: retain independent evidence under a token cap
- Claim-level citations: verify each answer against its passage
- Filtered vector search: measure ANN recall inside the permitted set
