ruby2210/rag-chatbot
0
1"""2QueryContext model for the RAG Chatbot application.3Represents the context provided for a specific query (either full book or selected text only).4"""5from sqlalchemy import Column, String, Text, Integer, DateTime, ForeignKey6from sqlalchemy.dialects.postgresql import JSONB7from datetime import datetime8from ..utils.database import Base9 10 11class QueryContext(Base):12 """13 Represents the context provided for a specific query (either full book or selected text only).14 """15 __tablename__ = "query_contexts"16 17 id = Column(String, primary_key=True, index=True) # Unique identifier for the query context18 session_id = Column(String, ForeignKey("chat_sessions.id"), index=True) # Link to the session19 context_type = Column(String, nullable=False) # Either "full_book" or "selected_text_only"20 retrieved_content = Column(JSONB, default=[]) # The content chunks retrieved for the query21 original_query = Column(Text, nullable=False) # The user's original query22 selected_text = Column(Text, nullable=True) # The text selected by the user for selected-text queries23 created_at = Column(DateTime, default=datetime.utcnow)24 25 def __repr__(self):26 return f"<QueryContext(id={self.id}, session_id={self.session_id}, context_type={self.context_type})>"