from datetime import datetime, timezone from app import db class KnowledgeChunk(db.Model): """ Fragmentos de documentación oficial indexados para la arquitectura RAG de UdeCi. Permite recuperación semántica eficiente y filtrado estricto por rol. """ __tablename__ = 'knowledge_chunks' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(150), nullable=False) content = db.Column(db.Text, nullable=False) role = db.Column(db.String(50), nullable=False, default='general', index=True) keywords = db.Column(db.String(255), nullable=True, index=True) category = db.Column(db.String(50), nullable=True, default='manual') created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None)) def __init__(self, **kwargs): super().__init__(**kwargs) def to_dict(self): return { 'id': self.id, 'title': self.title, 'content': self.content, 'role': self.role, 'keywords': self.keywords, 'category': self.category }