Skip to content

Commit

Permalink
知识库增删改查支持配置目录 (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
userpj authored Feb 25, 2025
1 parent 78d3267 commit faa0692
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 97 deletions.
36 changes: 31 additions & 5 deletions docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
| esUserName | string | type=bes 和 vdb 时填写 | 用户名/账号<br>请在bes、vdb控制台中查看 | "username" |
| esPassword | string | type=bes 和 vdb 时填写 | 密码/API密钥<br>请在bes、vdb控制台中查看 | "password" |
|location|string|type=bes 和 vdb 时填写|托管资源的区域,type填vdb时填写<br>可选值:<br>- bj:北京<br>- bd:保定<br>- sz:苏州<br>- gz:广州|"bj"|
|pathPrefix|string||创建知识库的指定目录,最大层级为5,默认为根目录下|"/全部群组/##/##"|

#### 方法返回值

Expand All @@ -48,6 +49,7 @@ class KnowledgeBaseDetailResponse(BaseModel):
```python
class KnowledgeBaseConfig(BaseModel):
index: Optional[KnowledgeBaseConfigIndex] = Field(..., description="索引配置")
catalogue: Optional[KnowledgeBaseConfigCatalogue] = Field(None, description="知识库目录配置")
```

衍生类`KnowledgeBaseConfigIndex`定义如下:
Expand All @@ -61,6 +63,13 @@ class KnowledgeBaseConfigIndex(BaseModel):
location: Optional[str] = Field(None, description="托管资源的区域", enum=["bj", "bd", "sz", "gz"])
```

衍生类`KnowledgeBaseConfigCatalogue`

```python
class KnowledgeBaseConfigCatalogue(BaseModel):
pathPrefix: Optional[str] = Field(None, description="知识库所属目录绝对路径")
```

#### 方法示例

```python
Expand Down Expand Up @@ -132,6 +141,7 @@ class KnowledgeBaseDetailResponse(BaseModel):
```python
class KnowledgeBaseConfig(BaseModel):
index: Optional[KnowledgeBaseConfigIndex] = Field(..., description="索引配置")
catalogue: Optional[KnowledgeBaseConfigCatalogue] = Field(None, description="知识库目录配置")
```

衍生类`KnowledgeBaseConfigIndex`定义如下:
Expand All @@ -144,6 +154,13 @@ class KnowledgeBaseConfigIndex(BaseModel):
password: Optional[str] = Field(None, description="ES密码")
```

衍生类`KnowledgeBaseConfigCatalogue`

```python
class KnowledgeBaseConfigCatalogue(BaseModel):
pathPrefix: Optional[str] = Field(None, description="知识库所属目录绝对路径")
```

#### 方法示例

```python
Expand Down Expand Up @@ -199,6 +216,7 @@ class KnowledgeBaseDetailResponse(BaseModel):
```python
class KnowledgeBaseConfig(BaseModel):
index: Optional[KnowledgeBaseConfigIndex] = Field(..., description="索引配置")
catalogue: Optional[KnowledgeBaseConfigCatalogue] = Field(None, description="知识库目录配置")
```

衍生类`KnowledgeBaseConfigIndex`定义如下:
Expand All @@ -211,6 +229,13 @@ class KnowledgeBaseConfigIndex(BaseModel):
password: Optional[str] = Field(None, description="ES密码")
```

衍生类`KnowledgeBaseConfigCatalogue`

```python
class KnowledgeBaseConfigCatalogue(BaseModel):
pathPrefix: Optional[str] = Field(None, description="知识库所属目录绝对路径")
```

#### 方法示例:

```python
Expand All @@ -227,11 +252,12 @@ print("获取到的知识库列表: ", resp)

#### 方法参数

| 参数名称 | 参数类型 | 是否必传 | 描述 | 示例值 |
| ----------------- | -------- | -------- | ------------------ | ---------------- |
| knowledge_base_id | string || 起始位置,知识库id | "正确的知识库ID" |
| name | string || 修改后的知识库名称 | "new_name" |
| description | string || 修改后的知识库描述 | "测试" |
| 参数名称 | 参数类型 | 是否必传 | 描述 | 示例值 |
| ----------------- | -------- | -------- | --------------------------------------------- | ---------------- |
| knowledge_base_id | string || 起始位置,知识库id | "正确的知识库ID" |
| name | string || 修改后的知识库名称 | "new_name" |
| description | string || 修改后的知识库描述 | "测试" |
| pathPrefix | string || 知识库的指定目录,最大层级为5,默认为根目录下 | |

#### 方法示例

Expand Down
4 changes: 0 additions & 4 deletions go/appbuilder/app_builder_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,6 @@ func TestAppBuilderClientRunChatflow(t *testing.T) {
}
}
}
if len(interruptId) == 0 {
t.Logf("%s========== FAIL: %s ==========%s", "\033[31m", t.Name(), "\033[0m")
t.Fatalf("interrupt id is empty")
}

i4, err := client.Run(AppBuilderClientRunRequest{
ConversationID: conversationID,
Expand Down
82 changes: 44 additions & 38 deletions go/appbuilder/knowledge_base_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package appbuilder
type QueryType string

const (
Fulltext QueryType = "fulltext"
Semantic QueryType = "semantic"
Hybrid QueryType = "hybrid"
Fulltext QueryType = "fulltext"
Semantic QueryType = "semantic"
Hybrid QueryType = "hybrid"
)

const (
Expand Down Expand Up @@ -93,15 +93,20 @@ type UploadFileResponse struct {
}

type KnowlegeBaseConfig struct {
Index KnowledgeBaseConfigIndex `json:"index"`
Index KnowledgeBaseConfigIndex `json:"index"`
Catalogue *KnowledgeBaseConfigCatalogue `json:"catalogue,omitempty"`
}

type KnowledgeBaseConfigIndex struct {
Type string `json:"type"`
ClusterId string `json:"clusterId"`
Username string `json:"username"`
Password string `json:"password"`
Location string `json:"location"`
Type string `json:"type"`
ClusterId string `json:"clusterId"`
Username string `json:"username"`
Password string `json:"password"`
Location string `json:"location"`
}

type KnowledgeBaseConfigCatalogue struct {
PathPrefix string `json:"pathPrefix,omitempty"`
}

type KnowledgeBaseDetail struct {
Expand All @@ -113,10 +118,11 @@ type KnowledgeBaseDetail struct {
}

type ModifyKnowlegeBaseRequest struct {
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
ClientToken string `json:"client_token,omitempty"`
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Config *KnowlegeBaseConfig `json:"config,omitempty"`
ClientToken string `json:"client_token,omitempty"`
}

type DeleteKnowlegeBaseRequest struct {
Expand Down Expand Up @@ -294,8 +300,8 @@ type VectorDBRetrieveConfig struct {
}

type SmallToBigConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Name string `json:"name"`
Type string `json:"type"`
}

type RankingConfig struct {
Expand All @@ -312,14 +318,14 @@ type QueryPipelineConfig struct {
}

type QueryKnowledgeBaseRequest struct {
Query string `json:"query"`
KnowledgebaseIDs []string `json:"knowledgebase_ids"`
Type *QueryType `json:"type,omitempty"`
Top int `json:"top,omitempty"`
Skip int `json:"skip,omitempty"`
RankScoreThreshold *float64 `json:"rank_score_threshold,omitempty"`
MetadataFileters MetadataFilters `json:"metadata_fileters,omitempty"`
PipelineConfig QueryPipelineConfig `json:"pipeline_config,omitempty"`
Query string `json:"query"`
KnowledgebaseIDs []string `json:"knowledgebase_ids"`
Type *QueryType `json:"type,omitempty"`
Top int `json:"top,omitempty"`
Skip int `json:"skip,omitempty"`
RankScoreThreshold *float64 `json:"rank_score_threshold,omitempty"`
MetadataFileters MetadataFilters `json:"metadata_fileters,omitempty"`
PipelineConfig QueryPipelineConfig `json:"pipeline_config,omitempty"`
}

type RowLine struct {
Expand All @@ -336,22 +342,22 @@ type ChunkLocation struct {
}

type Chunk struct {
ChunkID string `json:"chunk_id"`
KnowledgebaseID string `json:"knowledgebase_id"`
DocumentID string `json:"document_id"`
DocumentName string `json:"document_name"`
Meta map[string]any `json:"meta"`
Type string `json:"type"`
Content string `json:"content"`
CreateTime string `json:"create_time"`
UpdateTime string `json:"update_time"`
RetrievalScore float64 `json:"retrieval_score"`
RankScore float64 `json:"rank_score"`
Locations ChunkLocation `json:"locations"`
Children []Chunk `json:"children"`
ChunkID string `json:"chunk_id"`
KnowledgebaseID string `json:"knowledgebase_id"`
DocumentID string `json:"document_id"`
DocumentName string `json:"document_name"`
Meta map[string]any `json:"meta"`
Type string `json:"type"`
Content string `json:"content"`
CreateTime string `json:"create_time"`
UpdateTime string `json:"update_time"`
RetrievalScore float64 `json:"retrieval_score"`
RankScore float64 `json:"rank_score"`
Locations ChunkLocation `json:"locations"`
Children []Chunk `json:"children"`
NeighbourChunks []Chunk `json:"neighbour_chunks"`
OriginalChunkId string `json:"original_chunk_id"`
OriginalChunkOffset int `json:"original_chunk_offset"`
OriginalChunkId string `json:"original_chunk_id"`
OriginalChunkOffset int `json:"original_chunk_offset"`
}

type QueryKnowledgeBaseResponse struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@

public class KnowledgeBaseConfig {
private Index index;
private Catalogue catalogue;

public KnowledgeBaseConfig(Index index) {
this.index = index;
}

public KnowledgeBaseConfig(Index index, Catalogue catalogue) {
this.index = index;
this.catalogue = catalogue;
}

public Index getIndex() {
return index;
}

public void setIndex(Index index) {
this.index = index;
}

public void setCatalogue(Catalogue catalogue) {
this.catalogue = catalogue;
}

public Catalogue getCatalogue() {
return catalogue;
}

public static class Index {
private String type;
private String clusterId;
Expand Down Expand Up @@ -46,4 +64,16 @@ public String getLocation() {
return location;
}
}

public static class Catalogue {
private String pathPrefix;

public void setPathPrefix(String pathPrefix) {
this.pathPrefix = pathPrefix;
}

public String getPathPrefix() {
return pathPrefix;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class KnowledgeBaseModifyRequest {
private String knowledgeBaseId;
private String name;
private String description;
private KnowledgeBaseConfig config;

public String getKnowledgeBaseId() {
return knowledgeBaseId;
Expand All @@ -31,4 +32,12 @@ public String getDescription() {
public void setDescription(String description) {
this.description = description;
}

public KnowledgeBaseConfig getConfig() {
return config;
}

public void setConfig(KnowledgeBaseConfig config) {
this.config = config;
}
}
6 changes: 6 additions & 0 deletions python/core/console/knowledge_base/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ class KnowledgeBaseConfigIndex(BaseModel):
location: Optional[str] = Field(None, description="托管资源的区域", enum=["bj", "bd", "sz", "gz"])


class KnowledgeBaseConfigCatalogue(BaseModel):
pathPrefix: Optional[str] = Field(None, description="知识库所属目录绝对路径")


class KnowledgeBaseConfig(BaseModel):
index: Optional[KnowledgeBaseConfigIndex] = Field(..., description="索引配置")
catalogue: Optional[KnowledgeBaseConfigCatalogue] = Field(None, description="知识库目录配置")


class KnowledgeBaseCreateKnowledgeBaseRequest(BaseModel):
Expand All @@ -130,6 +135,7 @@ class KnowledgeBaseModifyRequest(BaseModel):
id: str = Field(..., description="知识库ID")
name: Optional[str] = Field(None, description="知识库名称")
description: Optional[str] = Field(None, description="知识库描述")
config: Optional[KnowledgeBaseConfig] = Field(None, description="知识库配置")


class KnowledgeBaseDeleteRequest(BaseModel):
Expand Down
Loading

0 comments on commit faa0692

Please sign in to comment.