mmap-backend / app /documents /chunks_model.py
jugalgajjar's picture
initial backend deploy
0fdb7bd
Raw
History Blame Contribute Delete
965 Bytes
from datetime import UTC, datetime
from uuid import UUID, uuid4
from sqlalchemy import DateTime, ForeignKey, Integer, Text, Uuid
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
def _utcnow() -> datetime:
return datetime.now(UTC)
class DocumentChunk(Base):
__tablename__ = "document_chunks"
id: Mapped[UUID] = mapped_column(Uuid, primary_key=True, default=uuid4)
document_id: Mapped[UUID] = mapped_column(
Uuid,
ForeignKey("documents.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
chunk_index: Mapped[int] = mapped_column(Integer, nullable=False)
text: Mapped[str] = mapped_column(Text, nullable=False)
char_start: Mapped[int] = mapped_column(Integer, nullable=False)
char_end: Mapped[int] = mapped_column(Integer, nullable=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=_utcnow, nullable=False
)