File size: 837 Bytes
4d85858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from dataclasses import dataclass, field
from typing import Any


@dataclass(frozen=True)
class PageMarker:
    page: int
    char_start: int
    char_end: int


@dataclass(frozen=True)
class TextSpan:
    text: str
    char_start: int
    char_end: int


@dataclass
class Chunk:
    chunk_id: str
    doc_id: str
    source_file: str
    chunk_index: int
    content: str
    content_for_embedding: str
    metadata: dict[str, Any] = field(default_factory=dict)

    def to_dict(self) -> dict[str, Any]:
        return {
            "chunk_id": self.chunk_id,
            "doc_id": self.doc_id,
            "source_file": self.source_file,
            "chunk_index": self.chunk_index,
            "content": self.content,
            "content_for_embedding": self.content_for_embedding,
            "metadata": self.metadata,
        }