Add FastAPI backend with agent system
This commit is contained in:
33
backend/app/models/document.py
Normal file
33
backend/app/models/document.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, String, Integer, Text, ForeignKey, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.models.base import BaseModel
|
||||
|
||||
|
||||
class Document(BaseModel):
|
||||
__tablename__ = "documents"
|
||||
|
||||
user_id = Column(String(36), ForeignKey("users.id"), nullable=False, index=True)
|
||||
title = Column(String(500), nullable=False)
|
||||
filename = Column(String(500), nullable=False)
|
||||
file_type = Column(String(50), nullable=False) # pdf, md, txt, docx
|
||||
file_size = Column(Integer, nullable=False)
|
||||
file_path = Column(String(1000), nullable=False)
|
||||
folder_id = Column(String(36), ForeignKey("folders.id"), nullable=True) # 新增
|
||||
summary = Column(Text, nullable=True)
|
||||
chunk_count = Column(Integer, default=0)
|
||||
is_indexed = Column(Boolean, default=False)
|
||||
|
||||
chunks = relationship("DocumentChunk", back_populates="document", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class DocumentChunk(BaseModel):
|
||||
__tablename__ = "document_chunks"
|
||||
|
||||
document_id = Column(String(36), ForeignKey("documents.id"), nullable=False, index=True)
|
||||
chunk_index = Column(Integer, nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
metadata_ = Column(String(2000), nullable=True) # JSON 存储元数据
|
||||
chroma_collection = Column(String(255), nullable=True)
|
||||
chroma_id = Column(String(255), nullable=True)
|
||||
|
||||
document = relationship("Document", back_populates="chunks")
|
||||
Reference in New Issue
Block a user