An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
Liang Ding74ef94875b24
diff --git a/kernel/model/search.go b/kernel/model/search.goindex 0ba4dad2ac..e9ba5ffe5d 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -38,6 +38,7 @@ import ("github.com/siyuan-note/siyuan/kernel/conf""github.com/siyuan-note/siyuan/kernel/search""github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/task""github.com/siyuan-note/siyuan/kernel/treenode""github.com/siyuan-note/siyuan/kernel/util""github.com/xrash/smetrics"@@ -69,6 +70,9 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMod}sqlBlocks = tmp+ // 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112+ task.AppendTask(task.DatabaseIndexEmbedBlock, updateEmbedBlockContent, embedBlockID, sqlBlocks)+// 缓存最多 128 棵语法树trees := map[string]*parse.Tree{}count := 0diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex 1af9342aba..cc5685faf9 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -1219,21 +1219,24 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha// AutoIndexEmbedBlock 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112func AutoIndexEmbedBlock() {for {- task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock)+ embedBlocks := sql.QueryEmptyContentEmbedBlocks()+ task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock, embedBlocks)time.Sleep(10 * time.Minute)}}-func autoIndexEmbedBlock() {- embedBlocks := sql.QueryEmptyContentEmbedBlocks()+func autoIndexEmbedBlock(embedBlocks []*sql.Block) {for i, embedBlock := range embedBlocks {stmt := strings.TrimPrefix(embedBlock.Markdown, "{{")stmt = strings.TrimSuffix(stmt, "}}")- blocks := sql.SelectBlocksRawStmtNoParse(stmt, 102400)- for _, block := range blocks {- embedBlock.Content = block.Content- sql.UpdateBlockContent(embedBlock)+ queryResultBlocks := sql.SelectBlocksRawStmtNoParse(stmt, 102400)+ for _, block := range queryResultBlocks {+ embedBlock.Content += block.Content}+ if "" == embedBlock.Content {+ embedBlock.Content = "no query result"+ }+ sql.UpdateBlockContent(embedBlock)if 63 <= i { // 一次任务中最多处理 64 个嵌入块,防止卡顿break@@ -1241,6 +1244,21 @@ func autoIndexEmbedBlock() {}}+func updateEmbedBlockContent(embedBlockID string, queryResultBlocks []*sql.Block) {+ embedBlock := sql.GetBlock(embedBlockID)+ if nil == embedBlock {+ return+ }++ for _, block := range queryResultBlocks {+ embedBlock.Content += block.Content+ }+ if "" == embedBlock.Content {+ embedBlock.Content = "no query result"+ }+ sql.UpdateBlockContent(embedBlock)+}+// AutoFixIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016func AutoFixIndex() {for {