From 86dbd74f3f72ea323eb6a579271e7270e80b7836 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 26 May 2026 23:13:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(ai):=20=E6=96=B0=E5=A2=9E=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=20V2=20Entity=EF=BC=88bases/documents/chunks?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三张新表对应的 SeaORM Entity,embedding 字段标记 #[sea_orm(ignore)] 通过 raw SQL 操作 pgvector 列。 --- .../erp-ai/src/entity/ai_knowledge_bases.rs | 31 ++++++++++++++++ .../erp-ai/src/entity/ai_knowledge_chunks.rs | 34 ++++++++++++++++++ .../src/entity/ai_knowledge_documents.rs | 36 +++++++++++++++++++ crates/erp-ai/src/entity/mod.rs | 3 ++ 4 files changed, 104 insertions(+) create mode 100644 crates/erp-ai/src/entity/ai_knowledge_bases.rs create mode 100644 crates/erp-ai/src/entity/ai_knowledge_chunks.rs create mode 100644 crates/erp-ai/src/entity/ai_knowledge_documents.rs diff --git a/crates/erp-ai/src/entity/ai_knowledge_bases.rs b/crates/erp-ai/src/entity/ai_knowledge_bases.rs new file mode 100644 index 0000000..11c8ce4 --- /dev/null +++ b/crates/erp-ai/src/entity/ai_knowledge_bases.rs @@ -0,0 +1,31 @@ +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] +#[sea_orm(table_name = "ai_knowledge_bases")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub tenant_id: Uuid, + pub name: String, + pub kb_type: String, + pub description: Option, + pub icon: Option, + pub chunk_strategy: serde_json::Value, + pub intent_keywords: serde_json::Value, + pub embedding_model: Option, + pub is_enabled: bool, + pub document_count: i32, + pub chunk_count: i32, + pub created_at: DateTimeUtc, + pub updated_at: DateTimeUtc, + pub created_by: Option, + pub updated_by: Option, + pub deleted_at: Option, + pub version_lock: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/crates/erp-ai/src/entity/ai_knowledge_chunks.rs b/crates/erp-ai/src/entity/ai_knowledge_chunks.rs new file mode 100644 index 0000000..f833163 --- /dev/null +++ b/crates/erp-ai/src/entity/ai_knowledge_chunks.rs @@ -0,0 +1,34 @@ +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] +#[sea_orm(table_name = "ai_knowledge_chunks")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub tenant_id: Uuid, + pub knowledge_base_id: Uuid, + pub document_id: Uuid, + pub chunk_index: i32, + pub content: String, + pub token_count: Option, + // pgvector 字段 — SeaORM 不原生支持 vector 类型,查询时用 raw SQL + #[sea_orm(ignore)] + pub embedding: Option>, + pub start_offset: Option, + pub end_offset: Option, + pub page_number: Option, + pub metadata: serde_json::Value, + pub hit_count: i32, + pub last_hit_at: Option, + pub created_at: DateTimeUtc, + pub updated_at: DateTimeUtc, + pub created_by: Option, + pub updated_by: Option, + pub deleted_at: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/crates/erp-ai/src/entity/ai_knowledge_documents.rs b/crates/erp-ai/src/entity/ai_knowledge_documents.rs new file mode 100644 index 0000000..8d344d7 --- /dev/null +++ b/crates/erp-ai/src/entity/ai_knowledge_documents.rs @@ -0,0 +1,36 @@ +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] +#[sea_orm(table_name = "ai_knowledge_documents")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub tenant_id: Uuid, + pub knowledge_base_id: Uuid, + pub title: String, + pub doc_type: String, + pub source_type: String, + pub source_url: Option, + pub file_name: Option, + pub file_size: Option, + pub file_mime_type: Option, + pub content: Option, + pub status: String, + pub chunk_count: i32, + pub embedded_count: i32, + pub error_message: Option, + pub processing_started_at: Option, + pub processing_completed_at: Option, + pub created_at: DateTimeUtc, + pub updated_at: DateTimeUtc, + pub created_by: Option, + pub updated_by: Option, + pub deleted_at: Option, + pub version_lock: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/crates/erp-ai/src/entity/mod.rs b/crates/erp-ai/src/entity/mod.rs index 09dbdb1..772ac29 100644 --- a/crates/erp-ai/src/entity/mod.rs +++ b/crates/erp-ai/src/entity/mod.rs @@ -3,6 +3,9 @@ pub mod ai_analysis_queue; pub mod ai_chat_message; pub mod ai_chat_session; pub mod ai_feature_flags; +pub mod ai_knowledge_bases; +pub mod ai_knowledge_chunks; +pub mod ai_knowledge_documents; pub mod ai_knowledge_guides; pub mod ai_knowledge_references; pub mod ai_knowledge_rules;