feat(ai): Phase 3A-1/2 RAG 知识库基础 — Embedding 服务 + pgvector 向量搜索

- EmbeddingService: OpenAI 兼容 embedding API 客户端(单条+批量)
- 从 settings 表读取配置(base_url/api_key/model)
- KnowledgeSearchRepository: pgvector 余弦相似度搜索(references+guides UNION)
- format_vector 辅助函数,Embedding 失败降级为 NULL
- 6 个 embedding 单元测试通过
This commit is contained in:
iven
2026-05-19 08:46:36 +08:00
parent 9576e80175
commit 7658bc3cdf
5 changed files with 496 additions and 2 deletions

View File

@@ -313,7 +313,7 @@ pub async fn load_ai_config_raw(
}
/// 开发模式默认 KEK
fn get_dev_kek() -> [u8; 32] {
pub fn get_dev_kek() -> [u8; 32] {
*erp_core::crypto::PiiCrypto::dev_default().kek()
}
@@ -442,7 +442,7 @@ pub async fn save_ai_config(
}
/// 直接从 settings 表读取所有 ai.* 配置项tenant → platform fallback
async fn read_settings_batch(
pub async fn read_settings_batch(
tenant_id: Uuid,
db: &DatabaseConnection,
) -> std::collections::HashMap<String, serde_json::Value> {