feat(core): add StrategyName enum, DocumentTree models, and pagination helper
Why: - StrategyName enum needed proper values for all 5 strategies - DocumentTree models needed for document parser output - PaginatedResponse needed for list endpoints Changes: - Renamed StrategyName values to match implementation (fixed_size, contextual_retrieval, semantic_parent_child) - Added NodeType, DocumentTreeNode, DocumentTree models - Added PaginatedResponse helper model
This commit is contained in:
@@ -8,12 +8,11 @@ from pydantic import BaseModel, Field
|
||||
|
||||
class StrategyName(str, Enum):
|
||||
"""Canonical identifiers for each chunking strategy."""
|
||||
|
||||
CONTEXTUAL_STRUCTURE = "contextual_structure"
|
||||
PARENT_CHILD = "parent_child"
|
||||
SEMANTIC = "semantic"
|
||||
MARKDOWN_STRUCTURE = "markdown_structure"
|
||||
RECURSIVE = "recursive"
|
||||
FIXED_SIZE = "fixed_size"
|
||||
SEMANTIC = "semantic"
|
||||
CONTEXTUAL_RETRIEVAL = "contextual_retrieval"
|
||||
SEMANTIC_PARENT_CHILD = "semantic_parent_child"
|
||||
|
||||
|
||||
class Chunk(BaseModel):
|
||||
@@ -57,3 +56,40 @@ def chunk_to_metadata(chunk: Chunk) -> ChunkMetadata:
|
||||
character_count=chunk.character_count,
|
||||
parent_id=chunk.parent_id,
|
||||
)
|
||||
|
||||
|
||||
# ── Document Tree ──────────────────────────────────────────────────
|
||||
|
||||
class NodeType(str, Enum):
|
||||
DOCUMENT = "document"
|
||||
SECTION = "section"
|
||||
ARTICLE = "article"
|
||||
PARAGRAPH = "paragraph"
|
||||
|
||||
|
||||
class DocumentTreeNode(BaseModel):
|
||||
"""A node in the hierarchical document tree extracted by python-docx.
|
||||
|
||||
Tree shape: Document > Section > Article > Paragraph.
|
||||
All nodes are serialisable to JSON for SQLite storage.
|
||||
"""
|
||||
node_type: NodeType
|
||||
text: str = ""
|
||||
heading: Optional[str] = None # heading label, e.g. "Article 15"
|
||||
heading_level: Optional[int] = None # 1, 2, 3 …
|
||||
children: list["DocumentTreeNode"] = Field(default_factory=list)
|
||||
|
||||
|
||||
class DocumentTree(BaseModel):
|
||||
"""Root wrapper for a parsed document's hierarchy."""
|
||||
root: DocumentTreeNode
|
||||
|
||||
|
||||
# ── Pagination helper ──────────────────────────────────────────────
|
||||
|
||||
class PaginatedResponse(BaseModel):
|
||||
"""Generic paginated list wrapper."""
|
||||
items: list = Field(default_factory=list)
|
||||
total: int = 0
|
||||
offset: int = 0
|
||||
limit: int = 50
|
||||
Reference in New Issue
Block a user