mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
2.3 KiB
2.3 KiB
Mô Hình Dữ Liệu (Backend)
Tài liệu này mô tả schema cơ sở dữ liệu Postgres, được quản lý bởi SQLAlchemy và Alembic.
Các Thực Thể Chính (Core Entities)
User
Đại diện cho người dùng hệ thống.
id:Integer(Primary Key)email:String(Unique)hashed_password:Stringis_active:Booleancreated_at:DateTime
Usage
Theo dõi hạn ngạch sử dụng (quota) của người dùng.
id:Integeruser_id:ForeignKey -> Userrequest_count:Integer(Số request API đã gọi)token_consumed:Integer(Số token LLM đã dùng)
Document
Đơn vị kiến thức cơ bản. Một tài liệu có thể là một file PDF, một trang web, hoặc một ghi chú Notion.
id:Integertitle:Stringcontent:Text(Nội dung thô, nếu có)url:String(Nguồn gốc)source_type:Enum(PDF, WEB, NOTION, SLACK...)owner_id:ForeignKey -> Userembedding_status:Enum(PENDING, INDEXED, FAILED)
Chunk
Phần nhỏ của tài liệu dùng cho Vector Search.
id:Integerdocument_id:ForeignKey -> Documentcontent:Text(Nội dung của đoạn chunk)embedding:Vector(1536)(Vector đại diện, dùng cho pgvector)metadata:JSONB(Thông tin bổ sung)
ChatThread
Đại diện cho một cuộc hội thoại.
id:Integeruser_id:ForeignKey -> Usertitle:Stringcreated_at:DateTime
ChatMessage
Một tin nhắn trong cuộc hội thoại.
id:Integerthread_id:ForeignKey -> ChatThreadrole:Enum(USER, ASSISTANT, SYSTEM)content:Texttool_calls:JSONB(Lưu trữ các function calls nếu có)
ConnectorCredential
Lưu trữ token xác thực cho các ứng dụng bên ngoài.
id:Integeruser_id:ForeignKey -> Userconnector_type:String(ví dụ: "google_drive")encrypted_token:String(Token đã mã hóa)refresh_token:String
Mối Quan Hệ ERD (Tóm tắt)
User1 -- nDocumentDocument1 -- nChunkUser1 -- nChatThreadChatThread1 -- nChatMessageUser1 -- 1Usage