File size: 1,336 Bytes
6b62834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Base modal processor — processes content items of a specific type."""

from abc import ABC, abstractmethod
from typing import Any

from agentic_rag.services.knowledge.content_list import ContentItem


class BaseModalProcessor(ABC):
    """Abstract base for modality-specific content processors.

    Each processor handles one ContentType:
    - ImageProcessor: VLM captioning
    - TableProcessor: structure interpretation
    - EquationProcessor: LaTeX parsing
    - VideoProcessor: keyframe + VLM
    - AudioProcessor: STT transcription
    """

    content_type: str
    description: str = ""

    @abstractmethod
    async def process(self, item: ContentItem) -> ContentItem:
        """Process a single content item. Returns the enriched item."""
        ...

    async def process_batch(self, items: list[ContentItem]) -> list[ContentItem]:
        """Process multiple items (default: sequential, override for concurrency)."""
        results = []
        for item in items:
            results.append(await self.process(item))
        return results

    def _result(self, item: ContentItem, **updates) -> ContentItem:
        """Helper to update an item with processing results."""
        for key, value in updates.items():
            if hasattr(item, key):
                setattr(item, key, value)
        return item