nex_docus/backend/app/models/document_vector.py

37 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
文档向量化模型
"""
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, Index, Text
from sqlalchemy.sql import func
from app.core.database import Base
class DocumentVector(Base):
"""文档向量表模型"""
__tablename__ = "document_vector"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="向量ID")
project_id = Column(BigInteger, nullable=False, index=True, comment="项目ID")
file_path = Column(String(500), nullable=False, comment="文件相对路径")
chunk_index = Column(Integer, nullable=False, default=0, comment="分块序号0起同一文件可有多个分块")
chunk_text = Column(Text, comment="分块首段文本,作为点击引用时的定位锚点")
content_hash = Column(String(64), comment="整个文件内容哈希值,用于判断文件是否变更")
zvec_id = Column(String(256), comment="ZVec返回的向量ID每个分块独立")
zvec_response = Column(Text, comment="ZVec完整响应JSON")
status = Column(String(32), nullable=False, default="success", comment="向量化状态success/failed/pending")
error_message = Column(String(500), comment="错误信息")
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
__table_args__ = (
Index("idx_project_file", "project_id", "file_path"),
Index("idx_project_file_chunk", "project_id", "file_path", "chunk_index"),
)
def __repr__(self):
return (
f"<DocumentVector(id={self.id}, project_id={self.project_id}, "
f"file_path='{self.file_path}', chunk_index={self.chunk_index}, status='{self.status}')>"
)