Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knowledge base support konwledge graph #2916

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-pr-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Prevent file change
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
pattern: ^(?!.*_ee\/.*$)(?!.*_ee\.go$)(?!.*_ee_test\.go$)(?!.*_rel\.go$)(?!.*_rel_test\.go$)(?!go\.mod$)(?!go\.sum$)(?!\.github\/workflows\/check-pr-files\.yml$)(?!vendor\/.*)(?!.*_qa\.go$).*
pattern: ^(?!.*_ee\/.*$)(?!.*_ee\.go$)(?!.*_ee_test\.go$)(?!.*_rel\.go$)(?!.*_rel_test\.go$)(?!go\.mod$)(?!go\.sum$)(?!\.github\/workflows\/check-pr-files\.yml$)(?!vendor\/.*)(?!.*_qa\.go$)(?!.*\.xml$).*
trustedAuthors: xalvarez

# 禁止actions自动提交commit
Expand Down
1 change: 1 addition & 0 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
// 知识库 Knowledge Base
v1Router.GET("/knowledge_bases", v1.GetKnowledgeBaseList)
v1Router.GET("/knowledge_bases/tags", v1.GetKnowledgeBaseTagList)
v1Router.GET("/knowledge_bases/graph", v1.GetKnowledgeGraph)

//rule
v1Router.GET("/rules", v1.GetRules)
Expand Down
14 changes: 2 additions & 12 deletions sqle/api/controller/v1/knowledge_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,12 @@ type NodeResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Weight uint64 `json:"weight"`
Data interface{} `json:"data,omitempty"`
}

// EdgeResponse represents an edge in the API response
type EdgeResponse struct {
FromID string `json:"from_id"` // 存储Node的ID而不是指针
FromName string `json:"from_name"` // 方便前端显示
ToID string `json:"to_id"` // 存储Node的ID而不是指针
ToName string `json:"to_name"` // 方便前端显示
FromID string `json:"from_id"` // 存储Node的ID
ToID string `json:"to_id"` // 存储Node的ID
Weight uint64 `json:"weight"` // 权重
IsDirected bool `json:"is_directed"` // 是否有向
}
Expand All @@ -106,11 +103,4 @@ type EdgeResponse struct {
type GraphResponse struct {
Nodes []*NodeResponse `json:"nodes"` // 节点集合
Edges []*EdgeResponse `json:"edges"` // 边集合
Stats GraphStats `json:"stats"` // 添加图的统计信息
}

// GraphStats 包含图的统计信息
type GraphStats struct {
TotalNodes uint64 `json:"total_nodes"`
TotalEdges uint64 `json:"total_edges"`
}
1 change: 1 addition & 0 deletions sqle/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type SqleOptions struct {
Service SeviceOpts `yaml:"service"`
OptimizationConfig OptimizationConfig `yaml:"optimization_config"`
SQLRewritingConfig SQLRewritingConfig `yaml:"sql_rewriting_config"`
KnowledgeBaseTempLicense string `yaml:"knowledge_base_temp_license"`
}

type SeviceOpts struct {
Expand Down
31 changes: 2 additions & 29 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13573,23 +13573,15 @@ var doc = `{
"type": "object",
"properties": {
"from_id": {
"description": "存储Node的ID而不是指针",
"type": "string"
},
"from_name": {
"description": "方便前端显示",
"description": "存储Node的ID",
"type": "string"
},
"is_directed": {
"description": "是否有向",
"type": "boolean"
},
"to_id": {
"description": "存储Node的ID而不是指针",
"type": "string"
},
"to_name": {
"description": "方便前端显示",
"description": "存储Node的ID",
"type": "string"
},
"weight": {
Expand Down Expand Up @@ -16054,22 +16046,6 @@ var doc = `{
"items": {
"$ref": "#/definitions/v1.NodeResponse"
}
},
"stats": {
"description": "添加图的统计信息",
"type": "object",
"$ref": "#/definitions/v1.GraphStats"
}
}
},
"v1.GraphStats": {
"type": "object",
"properties": {
"total_edges": {
"type": "integer"
},
"total_nodes": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -16575,9 +16551,6 @@ var doc = `{
"v1.NodeResponse": {
"type": "object",
"properties": {
"data": {
"type": "object"
},
"id": {
"type": "string"
},
Expand Down
31 changes: 2 additions & 29 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13557,23 +13557,15 @@
"type": "object",
"properties": {
"from_id": {
"description": "存储Node的ID而不是指针",
"type": "string"
},
"from_name": {
"description": "方便前端显示",
"description": "存储Node的ID",
"type": "string"
},
"is_directed": {
"description": "是否有向",
"type": "boolean"
},
"to_id": {
"description": "存储Node的ID而不是指针",
"type": "string"
},
"to_name": {
"description": "方便前端显示",
"description": "存储Node的ID",
"type": "string"
},
"weight": {
Expand Down Expand Up @@ -16038,22 +16030,6 @@
"items": {
"$ref": "#/definitions/v1.NodeResponse"
}
},
"stats": {
"description": "添加图的统计信息",
"type": "object",
"$ref": "#/definitions/v1.GraphStats"
}
}
},
"v1.GraphStats": {
"type": "object",
"properties": {
"total_edges": {
"type": "integer"
},
"total_nodes": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -16559,9 +16535,6 @@
"v1.NodeResponse": {
"type": "object",
"properties": {
"data": {
"type": "object"
},
"id": {
"type": "string"
},
Expand Down
23 changes: 2 additions & 21 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,19 +1367,13 @@ definitions:
v1.EdgeResponse:
properties:
from_id:
description: 存储Node的ID而不是指针
type: string
from_name:
description: 方便前端显示
description: 存储Node的ID
type: string
is_directed:
description: 是否有向
type: boolean
to_id:
description: 存储Node的ID而不是指针
type: string
to_name:
description: 方便前端显示
description: 存储Node的ID
type: string
weight:
description: 权重
Expand Down Expand Up @@ -3078,17 +3072,6 @@ definitions:
items:
$ref: '#/definitions/v1.NodeResponse'
type: array
stats:
$ref: '#/definitions/v1.GraphStats'
description: 添加图的统计信息
type: object
type: object
v1.GraphStats:
properties:
total_edges:
type: integer
total_nodes:
type: integer
type: object
v1.HighPriorityConditionReq:
properties:
Expand Down Expand Up @@ -3430,8 +3413,6 @@ definitions:
type: object
v1.NodeResponse:
properties:
data:
type: object
id:
type: string
name:
Expand Down
10 changes: 10 additions & 0 deletions sqle/license/temp_knowledge_license_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !enterprise
// +build !enterprise

package license

import "fmt"

func CheckKnowledgeBaseLicense(license string) error {
return fmt.Errorf("knowledge base license is not supported in community edition")
}
1 change: 1 addition & 0 deletions sqle/model/knowledge_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ()

type Knowledge struct {
Model
RuleName string `gorm:"type:varchar(255);default:''" json:"rule_name"` // 规则名称
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字需要在后续移除,改成关联关系

Title string `gorm:"type:varchar(255);not null" json:"title"` // 标题
Description string `gorm:"type:text" json:"description"` // 描述
Content string `gorm:"type:text;index:,class:FULLTEXT" json:"content"` // 内容
Expand Down
17 changes: 17 additions & 0 deletions sqle/server/support_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package server
import (
"fmt"

"github.com/actiontech/sqle/sqle/config"
"github.com/actiontech/sqle/sqle/driver"
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
"github.com/actiontech/sqle/sqle/license"
optimization "github.com/actiontech/sqle/sqle/server/optimization/rule"
)

const (
executeSqlFileMode string = "execute_sql_file_mode"
sqlOptimization string = "sql_optimization"
backup string = "backup"
knowledge_base string = "knowledge_base"
)

type StatusChecker interface {
Expand All @@ -26,6 +29,8 @@ func NewModuleStatusChecker(driverType string, moduleName string) (StatusChecker
return sqlOptimizationChecker{}, nil
case backup:
return sqlBackupChecker{driverType: driverType}, nil
case knowledge_base:
return knowledgeBaseChecker{driverType: driverType}, nil
}
return nil, fmt.Errorf("no checker matched")
}
Expand Down Expand Up @@ -53,3 +58,15 @@ func (s sqlBackupChecker) CheckIsSupport() bool {
svc := BackupService{}
return svc.CheckIsDbTypeSupportEnableBackup(s.driverType) == nil
}

// knowledgeBaseChecker 知识库检查器
type knowledgeBaseChecker struct {
driverType string
}

func (s knowledgeBaseChecker) CheckIsSupport() bool {
if license.CheckKnowledgeBaseLicense(config.GetOptions().SqleOptions.KnowledgeBaseTempLicense) != nil {
return false
}
return true
}
Loading