Download backend/app/models/document.py from Punit1/Enterprise-AI-Copilot: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/Punit1/Enterprise-AI-Copilot/resolve/main/backend/app/models/document.py
- Command line
-
hf download hf://spaces/Punit1/Enterprise-AI-Copilot/backend/app/models/document.py
-
curl -L -o document.py https://huggingface.co/spaces/Punit1/Enterprise-AI-Copilot/resolve/main/backend/app/models/document.py
2.1 kB
| """ | |
| Document model — stores metadata for every uploaded file. | |
| The actual binary is stored on the filesystem (uploads/). | |
| Embeddings/chunks live in Qdrant. | |
| """ | |
| from __future__ import annotations | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, func | |
| from sqlalchemy.orm import Mapped, mapped_column | |
| from app.core.database import Base | |
| class Document(Base): | |
| __tablename__ = "documents" | |
| id: Mapped[str] = mapped_column( | |
| String(36), primary_key=True, default=lambda: str(uuid.uuid4()) | |
| ) | |
| # Ownership | |
| tenant_id: Mapped[str] = mapped_column( | |
| String(36), ForeignKey("tenants.id"), nullable=False, index=True | |
| ) | |
| uploaded_by: Mapped[str] = mapped_column( | |
| String(36), ForeignKey("users.id"), nullable=False | |
| ) | |
| # File metadata | |
| filename: Mapped[str] = mapped_column(String(512), nullable=False) | |
| original_name: Mapped[str] = mapped_column(String(512), nullable=False) | |
| file_path: Mapped[str] = mapped_column(String(1024), nullable=False) | |
| file_size_bytes: Mapped[int] = mapped_column(Integer, default=0) | |
| mime_type: Mapped[str] = mapped_column(String(100), default="application/pdf") | |
| # Classification | |
| doc_type: Mapped[str] = mapped_column( | |
| String(50), default="general" | |
| ) # general | hr | finance | legal | technical | |
| # Processing status | |
| status: Mapped[str] = mapped_column( | |
| String(30), default="pending" | |
| ) # pending | processing | ready | failed | |
| error_message: Mapped[str | None] = mapped_column(Text, nullable=True) | |
| chunk_count: Mapped[int] = mapped_column(Integer, default=0) | |
| page_count: Mapped[int] = mapped_column(Integer, default=0) | |
| # Timestamps | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), index=True | |
| ) | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), onupdate=func.now() | |
| ) | |
| def __repr__(self) -> str: | |
| return f"<Document {self.filename} [{self.status}]>" | |