Spaces:
Sleeping
Sleeping
| """Document model for pgvector-based knowledge base.""" | |
| from datetime import datetime | |
| from sqlalchemy import Column, String, Text, DateTime, Integer, JSON | |
| from pgvector.sqlalchemy import Vector | |
| from uuid import uuid4 | |
| from app.database import Base | |
| class Document(Base): | |
| """Vector store for course materials and knowledge base.""" | |
| __tablename__ = "documents" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid4())) | |
| content = Column(Text, nullable=False) | |
| embedding = Column(Vector(768), nullable=False) # Google text-embedding-004 dimension | |
| meta = Column(JSON, nullable=True) # Store lesson_id, module_id, source, etc. | |
| # File metadata | |
| filename = Column(String(500), nullable=True) | |
| file_path = Column(String(1000), nullable=True) | |
| chunk_index = Column(Integer, default=0) | |
| # Timestamps | |
| created_at = Column(DateTime, default=datetime.utcnow) | |
| updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) | |
| def __repr__(self): | |
| return f"<Document {self.id[:8]}... from {self.filename}>" | |