| """RAG / Knowledgebase models."""
|
|
|
| import uuid
|
| from datetime import datetime, timezone
|
| from sqlalchemy import String, Integer, DateTime, Text, ForeignKey
|
| from sqlalchemy.orm import Mapped, mapped_column
|
| from mac.database import Base
|
|
|
|
|
| def _utcnow():
|
| return datetime.now(timezone.utc)
|
|
|
|
|
| def _gen_uuid():
|
| return str(uuid.uuid4())
|
|
|
|
|
| class RAGCollection(Base):
|
| __tablename__ = "rag_collections"
|
|
|
| id: Mapped[str] = mapped_column(String(36), primary_key=True, default=_gen_uuid)
|
| name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True)
|
| description: Mapped[str] = mapped_column(String(500), nullable=False, default="")
|
| document_count: Mapped[int] = mapped_column(Integer, default=0)
|
| created_by: Mapped[str] = mapped_column(String(36), nullable=False)
|
| created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_utcnow)
|
|
|
|
|
| class RAGDocument(Base):
|
| __tablename__ = "rag_documents"
|
|
|
| id: Mapped[str] = mapped_column(String(36), primary_key=True, default=_gen_uuid)
|
| collection_id: Mapped[str] = mapped_column(String(36), ForeignKey("rag_collections.id", ondelete="CASCADE"), nullable=False)
|
| title: Mapped[str] = mapped_column(String(200), nullable=False)
|
| filename: Mapped[str] = mapped_column(String(200), nullable=False)
|
| content_type: Mapped[str] = mapped_column(String(50), nullable=False, default="text/plain")
|
| file_size: Mapped[int] = mapped_column(Integer, default=0)
|
| chunk_count: Mapped[int] = mapped_column(Integer, default=0)
|
| page_count: Mapped[int] = mapped_column(Integer, default=0)
|
| status: Mapped[str] = mapped_column(String(20), nullable=False, default="processing")
|
| error_message: Mapped[str] = mapped_column(Text, nullable=True)
|
| uploaded_by: Mapped[str] = mapped_column(String(36), nullable=False)
|
| created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_utcnow)
|
|
|