feat(ai): 新增知识库 V2 Entity(bases/documents/chunks)
三张新表对应的 SeaORM Entity,embedding 字段标记 #[sea_orm(ignore)] 通过 raw SQL 操作 pgvector 列。
This commit is contained in:
31
crates/erp-ai/src/entity/ai_knowledge_bases.rs
Normal file
31
crates/erp-ai/src/entity/ai_knowledge_bases.rs
Normal file
@@ -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<String>,
|
||||
pub icon: Option<String>,
|
||||
pub chunk_strategy: serde_json::Value,
|
||||
pub intent_keywords: serde_json::Value,
|
||||
pub embedding_model: Option<String>,
|
||||
pub is_enabled: bool,
|
||||
pub document_count: i32,
|
||||
pub chunk_count: i32,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
34
crates/erp-ai/src/entity/ai_knowledge_chunks.rs
Normal file
34
crates/erp-ai/src/entity/ai_knowledge_chunks.rs
Normal file
@@ -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<i32>,
|
||||
// pgvector 字段 — SeaORM 不原生支持 vector 类型,查询时用 raw SQL
|
||||
#[sea_orm(ignore)]
|
||||
pub embedding: Option<Vec<f32>>,
|
||||
pub start_offset: Option<i32>,
|
||||
pub end_offset: Option<i32>,
|
||||
pub page_number: Option<i32>,
|
||||
pub metadata: serde_json::Value,
|
||||
pub hit_count: i32,
|
||||
pub last_hit_at: Option<DateTimeUtc>,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
36
crates/erp-ai/src/entity/ai_knowledge_documents.rs
Normal file
36
crates/erp-ai/src/entity/ai_knowledge_documents.rs
Normal file
@@ -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<String>,
|
||||
pub file_name: Option<String>,
|
||||
pub file_size: Option<i64>,
|
||||
pub file_mime_type: Option<String>,
|
||||
pub content: Option<String>,
|
||||
pub status: String,
|
||||
pub chunk_count: i32,
|
||||
pub embedded_count: i32,
|
||||
pub error_message: Option<String>,
|
||||
pub processing_started_at: Option<DateTimeUtc>,
|
||||
pub processing_completed_at: Option<DateTimeUtc>,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user