World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
Nine public functions that nothing calls are removed (#1128)
WaylandYang3bd116d0bacf
diff --git a/crates/utopia-store/src/documents.rs b/crates/utopia-store/src/documents.rsindex e28c91a1..6980e9b3 100644--- a/crates/utopia-store/src/documents.rs+++ b/crates/utopia-store/src/documents.rs@@ -671,35 +671,6 @@ pub async fn set_content_date(pool: &PgPool, id: Uuid, date: DateTime<Utc>) -> AOk(())}-/// 变更:原地替换文档内容(新 sha),状态回 pending 待重跑管道。-#[allow(clippy::too_many_arguments)]-pub async fn replace_content(- pool: &PgPool,- id: Uuid,- filename: &str,- mime: &str,- size_bytes: i64,- sha256: &str,- doc_time: Option<chrono::DateTime<chrono::Utc>>,-) -> AppResult<()> {- sqlx::query(- "UPDATE documents SET filename = $2, mime = $3, size_bytes = $4, sha256 = $5,- doc_time = COALESCE($6, doc_time),- status = 'pending', graph_status = 'none', error = NULL,- missing_since = NULL, updated_at = now()- WHERE id = $1",- )- .bind(id)- .bind(filename)- .bind(mime)- .bind(size_bytes)- .bind(sha256)- .bind(doc_time)- .execute(pool)- .await?;- Ok(())-}-/// 移动/改名:同内容换了路径,只更新身份,不重跑管道。pub async fn update_location(pool: &PgPool,@@ -1865,21 +1836,6 @@ pub async fn extract_epoch(pool: &PgPool, id: Uuid) -> AppResult<i32> {Ok(epoch)}-/// 这个库还有没有在排队或正在跑的抽取。-///-/// 冷启动自动扩本体要等一批文档都抽完再动手:只看第一篇的话,-/// 先到的那篇的词汇会独占本体。最后一篇跑完的任务负责触发。-pub async fn extraction_idle(pool: &PgPool, kb_id: Uuid) -> AppResult<bool> {- let (pending,): (i64,) = sqlx::query_as(- "SELECT count(*) FROM documents- WHERE kb_id = $1 AND deleted_at IS NULL AND graph_status IN ('queued', 'extracting')",- )- .bind(kb_id)- .fetch_one(pool)- .await?;- Ok(pending == 0)-}-/// 全库分块,按文档分组,供检索索引重建用。////// **一次全取**:这条只在启动发现索引落空时跑,那时候要的正是全部;diff --git a/crates/utopia-store/src/ontology.rs b/crates/utopia-store/src/ontology.rsindex 87f4c11a..20ddea89 100644--- a/crates/utopia-store/src/ontology.rs+++ b/crates/utopia-store/src/ontology.rs@@ -1053,53 +1053,6 @@ pub async fn update_type_from_import(Ok(row.map(|(id,)| id))}-/// 设父类。自环与已是该父类的情形静默跳过。-/// 从导入建一个属性(`kind='attribute'`),带 IRI。-///-/// 与 [`create_relation_type`] 的区别只在多了 `iri` 与 key 冲突的处置:-/// 导入按 IRI 认身份,key 撞了是"两个不同的东西争一个短标签",-/// 由调用方在计划阶段报告并跳过,到这里不该再撞——所以冲突时返回 None-/// 而不是覆盖,让调用方把它计进"跳过"。-///-/// `temporal` 固定 `state`:属性是随时间变化的取值(薪资、人数),-/// 新值闭合旧值正是我们要的。OWL 里没有对应概念,猜 event 或 eternal 都更差。-#[allow(clippy::too_many_arguments)]-pub async fn create_attribute_with_iri(- pool: &PgPool,- kb_id: Uuid,- key: &str,- label: &str,- description: &str,- iri: &str,- domains: &[Uuid],- datatype: &str,-) -> AppResult<Option<Uuid>> {- validate_key(key)?;- let id = Uuid::now_v7();- let row: Option<(Uuid,)> = sqlx::query_as(- "INSERT INTO relation_types- (id, kb_id, key, label, temporal, functional, inverse_functional,- description, kind, datatype, iri)- VALUES ($1, $2, $3, $4, 'state', FALSE, FALSE, $5, 'attribute', $6, $7)- ON CONFLICT (kb_id, key) DO NOTHING- RETURNING id",- )- .bind(id)- .bind(kb_id)- .bind(key)- .bind(label)- .bind(description)- .bind(datatype)- .bind(iri)- .fetch_optional(pool)- .await?;- let Some((new_id,)) = row else {- return Ok(None);- };- set_domains_ranges(&mut *pool.acquire().await?, new_id, domains, &[]).await?;- Ok(Some(new_id))-}-/// 从导入建一个关系(`kind='relation'`),带 IRI。////// `temporal` 固定 `state`:OWL 没有对应概念,而 state(有区间)是三者里唯一@@ -1685,71 +1638,6 @@ pub async fn adopt_iri_onto_key(Ok(row.map(|(id,)| id))}-/// 与给定向量最近的若干**类 id**(只回 id,调用方手里已有类的全量数据)。-///-/// 给抽取用:分块向量在抽取循环里本来就有(实体消解在用),拿它检索出这一块-/// 可能用得上的类,只把这些铺进提示词。-pub async fn nearest_entity_type_ids(- pool: &PgPool,- kb_id: Uuid,- embedding: &[f32],- limit: i64,-) -> AppResult<Vec<Uuid>> {- let rows: Vec<(Uuid,)> = sqlx::query_as(- "SELECT id FROM entity_types- WHERE kb_id = $1 AND embedding IS NOT NULL- ORDER BY embedding <=> $2- LIMIT $3",- )- .bind(kb_id)- .bind(Vector::from(embedding.to_vec()))- .bind(limit)- .fetch_all(pool)- .await?;- Ok(rows.into_iter().map(|(id,)| id).collect())-}--/// 同上,关系与属性。`only_kind` 分道:关系清单与属性清单在提示词里是两段。-/// 同上,但**只在 domain 落在这批类上的那些关系里**检索。-///-/// 存在的理由:全库检索对关系几乎没有区分度(1500 字的分块向量 vs 几个词的-/// 关系标签,距离全挤在一条窄带里)。实测一块讲「Jensen Huang, founder and CEO-/// of NVIDIA」的正文,`founder` 排 267、`job_title` 排 618(共 1026)——两个都进不了-/// 前 30 的窗口,于是模型没有地方写职务,索性不写。**不是抽错,是没被问到。**-///-/// 把池子先按 domain 收窄到「这一块认出来的那些类身上声明的关系」,同一块里-/// `founder` 升到 29、`job_title` 升到 55(共 86)。收窄靠的是本体自己声明的-/// 结构,不是又一个相似度模型。-pub async fn nearest_relation_type_ids_in_domains(- pool: &PgPool,- kb_id: Uuid,- embedding: &[f32],- limit: i64,- only_kind: Option<&str>,- domains: &[Uuid],-) -> AppResult<Vec<Uuid>> {- if domains.is_empty() {- return Ok(Vec::new());- }- let rows: Vec<(Uuid,)> = sqlx::query_as(- "SELECT r.id FROM relation_types r- WHERE r.kb_id = $1 AND r.embedding IS NOT NULL- AND ($4::text IS NULL OR r.kind = $4)- AND EXISTS (SELECT 1 FROM relation_type_domains d- WHERE d.relation_type_id = r.id AND d.entity_type_id = ANY($5))- ORDER BY r.embedding <=> $2- LIMIT $3",- )- .bind(kb_id)- .bind(Vector::from(embedding.to_vec()))- .bind(limit)- .bind(only_kind)- .bind(domains)- .fetch_all(pool)- .await?;- Ok(rows.into_iter().map(|(id,)| id).collect())-}-pub async fn nearest_relation_type_ids(pool: &PgPool,kb_id: Uuid,@@ -2249,18 +2137,6 @@ pub async fn decide_proposal(Ok(())}-/// 还有多少条等着看。0003 的缺口:关掉自动扩展开关之后没有「自上次以来有 N 条」-/// 的提醒,信号在面板里但没人主动看——有了这张表,提醒就是这一句。-pub async fn open_proposal_count(pool: &PgPool, kb_id: Uuid) -> AppResult<i64> {- let (n,): (i64,) = sqlx::query_as(- "SELECT count(*) FROM ontology_proposals WHERE kb_id = $1 AND status = 'open'",- )- .bind(kb_id)- .fetch_one(pool)- .await?;- Ok(n)-}-/// 主语的类型合不合这个关系声明的 domain。沿继承链往上找。////// **只回答,不动数据。** 0001 已经判过:签名是提示不是闸门,diff --git a/crates/utopia-store/src/settings.rs b/crates/utopia-store/src/settings.rsindex edf56df3..e145631e 100644--- a/crates/utopia-store/src/settings.rs+++ b/crates/utopia-store/src/settings.rs@@ -23,19 +23,6 @@ pub async fn get(pool: &PgPool, workspace_id: Uuid) -> AppResult<Option<LlmSettirow.map(opened).transpose()}-/// 任取一个配了对话模型的工作区设置。给端点探针用:端点地址是部署共用的,-/// 从哪个工作区的配置读到的都是同一个地方,而探针没有"当前工作区"这个上下文。-pub async fn any_with_chat(pool: &PgPool) -> AppResult<Option<LlmSettings>> {- let row: Option<LlmSettings> = sqlx::query_as(- "SELECT * FROM llm_settings- WHERE chat_base_url IS NOT NULL AND chat_model IS NOT NULL- ORDER BY workspace_id LIMIT 1",- )- .fetch_optional(pool)- .await?;- row.map(opened).transpose()-}-/// upsert;api_key 传 None 表示保留旧值(前端不回传密钥)。#[allow(clippy::too_many_arguments)]pub async fn upsert(diff --git a/crates/utopia-store/src/sources.rs b/crates/utopia-store/src/sources.rsindex b5780530..7f596c6e 100644--- a/crates/utopia-store/src/sources.rs+++ b/crates/utopia-store/src/sources.rs@@ -418,49 +418,6 @@ pub async fn finish_sync(Ok(true)}-/// 文档打标签(整组替换)。-///-/// **零调用,故意留着**:没有路由,界面上也没有入口。标签会是文档上唯一-/// 「人自己贴的」维度——来源是它从哪来的,名字与状态是系统给的,三者都表达-/// 不了「这批要脱敏」这种横跨来源、只有人知道的分组。要不要有这个维度,-/// 悬而未决——完整的两面之辞写在 `migrations/0002_ingest.sql` 的 `tags` 列上,-/// 别当死代码删掉。-pub async fn set_document_tags(- pool: &PgPool,- kb_id: Uuid,- document_id: Uuid,- tags: &[String],-) -> AppResult<()> {- let cleaned: Vec<String> = tags- .iter()- .map(|t| t.trim().to_string())- .filter(|t| !t.is_empty())- .collect();- let res = sqlx::query(- "UPDATE documents SET tags = $3, updated_at = now() WHERE id = $1 AND kb_id = $2",- )- .bind(document_id)- .bind(kb_id)- .bind(&cleaned)- .execute(pool)- .await?;- if res.rows_affected() == 0 {- return Err(AppError::NotFound);- }- Ok(())-}--/// 同步用去重:该 KB 是否已有同内容文档。-pub async fn document_exists_by_sha(pool: &PgPool, kb_id: Uuid, sha256: &str) -> AppResult<bool> {- let row: Option<(Uuid,)> =- sqlx::query_as("SELECT id FROM documents WHERE kb_id = $1 AND sha256 = $2 LIMIT 1")- .bind(kb_id)- .bind(sha256)- .fetch_optional(pool)- .await?;- Ok(row.is_some())-}-/// 记录同步时刻(避免调度器在长同步过程中重复触发后又立刻到期)。pub async fn touch_sync_time(pool: &PgPool, id: Uuid, at: DateTime<Utc>) -> AppResult<()> {sqlx::query("UPDATE sources SET last_sync_at = $2 WHERE id = $1")