Skip to content

Commit fd4b679

Browse files
author
Wang Zesong
committed
feat: knowledge base
1 parent a337061 commit fd4b679

15 files changed

Lines changed: 2061 additions & 0 deletions
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
commit 007d45e5b1f813debf643958c9527131b5eaee90
2+
Author: 王泽松 <zesong.wang1@bytedance.com>
3+
Date: Thu Sep 25 15:51:05 2025 +0000
4+
5+
feat: kb outer
6+
7+
* feat: max keyword
8+
* feat: max keyword
9+
* feat: kb outer
10+
* feat: kb outer
11+
12+
See merge request: !10464
13+
14+
diff --git a/idl/grpc/responses.proto b/idl/grpc/responses.proto
15+
index 66f1b4cda9..9f10d2f508 100644
16+
--- a/idl/grpc/responses.proto
17+
+++ b/idl/grpc/responses.proto
18+
@@ -26,6 +26,7 @@ message AnnotationType {
19+
enum Enum {
20+
unspecified = 0;
21+
url_citation = 1;
22+
+ doc_citation = 2;
23+
}
24+
}
25+
26+
@@ -47,8 +48,8 @@ message CoverImage {
27+
28+
message Annotation {
29+
AnnotationType.Enum type = 1;
30+
- string title = 2;
31+
- string url = 3;
32+
+ optional string title = 2;
33+
+ optional string url = 3;
34+
35+
// openai does not have
36+
optional string logo_url = 4;
37+
@@ -58,6 +59,12 @@ message Annotation {
38+
optional CoverImage cover_image = 8;
39+
optional string summary = 9;
40+
optional string freshness_info = 10;
41+
+
42+
+ // knowledge search citations
43+
+ optional string doc_id = 11;
44+
+ optional string doc_name = 12;
45+
+ optional int32 chunk_id = 13;
46+
+ repeated google.protobuf.Struct chunk_attachment = 14;
47+
}
48+
49+
50+
@@ -76,6 +83,7 @@ message ItemType {
51+
mcp_approval_response = 10;
52+
mcp_list_tools = 11;
53+
mcp_call = 12;
54+
+ knowledge_search_call = 13;
55+
}
56+
}
57+
58+
@@ -166,6 +174,7 @@ message ToolType {
59+
web_search = 3;
60+
image_process = 4;
61+
mcp = 5;
62+
+ knowledge_search = 6;
63+
}
64+
}
65+
66+
@@ -239,6 +248,11 @@ message EventType {
67+
response_mcp_call_completed = 39;
68+
response_mcp_call_failed = 40;
69+
response_mcp_approval_request = 41;
70+
+
71+
+ response_knowledge_search_call_in_progress = 42;
72+
+ response_knowledge_search_call_searching = 43;
73+
+ response_knowledge_search_call_completed = 44;
74+
+ response_knowledge_search_call_failed = 45;
75+
}
76+
}
77+
78+
@@ -318,6 +332,7 @@ message InputItem {
79+
ItemFunctionMcpListTools mcp_list_tools = 11;
80+
ItemFunctionMcpCall function_mcp_call = 12;
81+
ItemFunctionWebSearch function_web_search_call = 13;
82+
+ ItemFunctionKnowledgeSearch function_knowledge_search = 14;
83+
}
84+
}
85+
86+
@@ -474,6 +489,14 @@ message ItemFunctionMcpCall {
87+
optional string id = 8;
88+
}
89+
90+
+message ItemFunctionKnowledgeSearch {
91+
+ ItemType.Enum type = 1;
92+
+ repeated string queries = 2;
93+
+ string knowledge_resource_id = 3;
94+
+ ItemStatus.Enum status = 4;
95+
+ optional string id = 5;
96+
+}
97+
+
98+
message ActionType {
99+
enum Enum {
100+
unspecified = 0;
101+
@@ -489,7 +512,6 @@ message Action {
102+
message OutputContentItemText {
103+
ContentItemType.Enum type = 1;
104+
string text = 2;
105+
- // other output specific field like annotation
106+
repeated Annotation annotations = 3;
107+
}
108+
109+
@@ -558,6 +580,7 @@ message ResponsesTool {
110+
ToolWebSearch tool_web_search = 2;
111+
ToolImageProcess tool_image_process = 3;
112+
ToolMcp tool_mcp = 4;
113+
+ ToolKnowledgeSearch tool_knowledge_search = 5;
114+
}
115+
}
116+
117+
@@ -586,6 +609,7 @@ message ToolWebSearch {
118+
optional int64 limit = 2;
119+
optional UserLocation user_location = 3;
120+
repeated SourceType.Enum sources = 4;
121+
+ optional int32 max_keyword = 5;
122+
}
123+
124+
message ImageProcessPointOptions {
125+
@@ -666,6 +690,17 @@ message ToolMcp {
126+
optional string server_description = 7;
127+
}
128+
129+
+message ToolKnowledgeSearch {
130+
+ ToolType.Enum type = 1;
131+
+ string knowledge_resource_id = 2;
132+
+ optional string description = 3;
133+
+ optional int64 limit = 4;
134+
+ optional double dense_weight = 5;
135+
+ optional google.protobuf.Struct doc_filter = 6;
136+
+ optional google.protobuf.Struct ranking_options = 7;
137+
+ optional int32 max_keyword = 8;
138+
+}
139+
+
140+
message ToolFunction {
141+
string name = 1;
142+
optional bool strict = 2;
143+
@@ -716,6 +751,7 @@ message OutputItem {
144+
ItemFunctionMcpApprovalRequest function_mcp_approval_request = 7;
145+
ItemFunctionMcpListTools function_mcp_list_tools = 8;
146+
ItemFunctionMcpCall function_mcp_call = 9;
147+
+ ItemFunctionKnowledgeSearch function_knowledge_search = 10;
148+
}
149+
}
150+
151+
@@ -747,12 +783,14 @@ message Usage {
152+
message ToolUsage {
153+
optional int64 web_search = 1;
154+
optional int64 mcp = 2;
155+
+ optional int64 knowledge_search = 3;
156+
}
157+
158+
159+
message ToolUsageDetail {
160+
map<string, int64> web_search = 1;
161+
map<string, int64> mcp = 2;
162+
+ map<string, int64> knowledge_search = 3;
163+
}
164+
165+
message InputTokensDetails {
166+
@@ -790,8 +828,11 @@ message Event {
167+
ResponseMcpCallArgumentsDoneEvent response_mcp_call_arguments_done = 22;
168+
ResponseMcpCallCompletedEvent response_mcp_call_completed = 23;
169+
ResponseMcpCallFailedEvent response_mcp_call_failed = 24;
170+
-
171+
ResponseMcpApprovalRequestEvent response_mcp_approval_request = 25;
172+
+ ResponseKnowledgeSearchCallInProgressEvent response_knowledge_search_call_in_progress = 26;
173+
+ ResponseKnowledgeSearchCallSearchingEvent response_knowledge_search_call_searching = 27;
174+
+ ResponseKnowledgeSearchCallCompletedEvent response_knowledge_search_call_completed = 28;
175+
+ ResponseKnowledgeSearchCallFailedEvent response_knowledge_search_call_failed = 29;
176+
}
177+
}
178+
179+
@@ -942,6 +983,34 @@ message ResponseMcpCallFailedEvent {
180+
int64 sequence_number = 4; // @inject_tag: json:"sequence_number"
181+
}
182+
183+
+message ResponseKnowledgeSearchCallInProgressEvent {
184+
+ EventType.Enum type = 1;
185+
+ string item_id = 2;
186+
+ int64 output_index = 3;
187+
+ int64 sequence_number = 4; // @inject_tag: json:"sequence_number"
188+
+}
189+
+
190+
+message ResponseKnowledgeSearchCallSearchingEvent {
191+
+ EventType.Enum type = 1;
192+
+ string item_id = 2;
193+
+ int64 output_index = 3;
194+
+ int64 sequence_number = 4; // @inject_tag: json:"sequence_number"
195+
+}
196+
+
197+
+message ResponseKnowledgeSearchCallCompletedEvent {
198+
+ EventType.Enum type = 1;
199+
+ string item_id = 2;
200+
+ int64 output_index = 3;
201+
+ int64 sequence_number = 4; // @inject_tag: json:"sequence_number"
202+
+}
203+
+
204+
+message ResponseKnowledgeSearchCallFailedEvent {
205+
+ EventType.Enum type = 1;
206+
+ string item_id = 2;
207+
+ int64 output_index = 3;
208+
+ int64 sequence_number = 4; // @inject_tag: json:"sequence_number"
209+
+}
210+
+
211+
message ResponseEvent {
212+
EventType.Enum type = 1;
213+
ResponseObject response = 2;

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/model/responses/constant/ResponsesConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class ResponsesConstants {
7878
public static final String TOOL_TYPE_WEB_SEARCH = "web_search";
7979
public static final String TOOL_TYPE_IMAGE_PROCESS = "image_process";
8080
public static final String TOOL_TYPE_MCP = "mcp";
81+
public static final String TOOL_TYPE_KNOWLEDGE_SEARCH = "knowledge_search";
8182
public static final String TOOL_TYPE_DOUBAO_APP = "doubao_app";
8283

8384
// UserLocationType.Enum
@@ -157,6 +158,12 @@ public class ResponsesConstants {
157158
public static final String EVENT_TYPE_RESPONSE_DOUBAO_APP_CALL_BLOCK_ADDED = "response.doubao_app_call_block.added";
158159
public static final String EVENT_TYPE_RESPONSE_DOUBAO_APP_CALL_BLOCK_DONE = "response.doubao_app_call_block.done";
159160

161+
// Knowledge search events
162+
public static final String EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_IN_PROGRESS = "response.knowledge_search_call.in_progress";
163+
public static final String EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_SEARCHING = "response.knowledge_search_call.searching";
164+
public static final String EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_COMPLETED = "response.knowledge_search_call.completed";
165+
public static final String EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_FAILED = "response.knowledge_search_call.failed";
166+
160167
// IncludeType.Enum
161168
public static final String INCLUDE_TYPE_IMAGE_URL = "message.input_image.image_url";
162169

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/model/responses/event/StreamEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.annotation.JsonTypeInfo;
77
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
88
import com.volcengine.ark.runtime.model.responses.event.doubaoapp.*;
9+
import com.volcengine.ark.runtime.model.responses.event.knowledgesearch.*;
910
import com.volcengine.ark.runtime.model.responses.event.mcp.*;
1011
import com.volcengine.ark.runtime.model.responses.event.outputtext.AnnotationAddedEvent;
1112
import com.volcengine.ark.runtime.model.responses.event.contentpart.ContentPartAddedEvent;
@@ -85,6 +86,10 @@
8586
@JsonSubTypes.Type(value = DoubaoAppCallReasoningSearchInProgressEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_DOUBAO_APP_CALL_REASONING_SEARCH_IN_PROGRESS),
8687
@JsonSubTypes.Type(value = DoubaoAppCallReasoningSearchSearchingEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_DOUBAO_APP_CALL_REASONING_SEARCH_SEARCHING),
8788
@JsonSubTypes.Type(value = DoubaoAppCallReasoningSearchCompletedEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_DOUBAO_APP_CALL_REASONING_SEARCH_COMPLETED),
89+
@JsonSubTypes.Type(value = KnowledgeSearchCallInProgressEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_IN_PROGRESS),
90+
@JsonSubTypes.Type(value = KnowledgeSearchCallSearchingEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_SEARCHING),
91+
@JsonSubTypes.Type(value = KnowledgeSearchCallCompletedEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_COMPLETED),
92+
@JsonSubTypes.Type(value = KnowledgeSearchCallFailedEvent.class, name = ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_FAILED),
8893
})
8994
public abstract class StreamEvent {
9095

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.volcengine.ark.runtime.model.responses.event.knowledgesearch;
2+
3+
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
4+
import com.volcengine.ark.runtime.model.responses.event.ItemEvent;
5+
6+
public class KnowledgeSearchCallCompletedEvent extends ItemEvent {
7+
8+
public KnowledgeSearchCallCompletedEvent() {
9+
super(ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_COMPLETED);
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return "KnowledgeSearchCallCompletedEvent{" +
15+
"type='" + getType() + '\'' +
16+
", sequenceNumber=" + getSequenceNumber() +
17+
", itemId='" + getItemId() + '\'' +
18+
", outputIndex=" + getOutputIndex() +
19+
'}';
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.volcengine.ark.runtime.model.responses.event.knowledgesearch;
2+
3+
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
4+
import com.volcengine.ark.runtime.model.responses.event.ItemEvent;
5+
6+
public class KnowledgeSearchCallFailedEvent extends ItemEvent {
7+
8+
public KnowledgeSearchCallFailedEvent() {
9+
super(ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_FAILED);
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return "KnowledgeSearchCallFailedEvent{" +
15+
"type='" + getType() + '\'' +
16+
", sequenceNumber=" + getSequenceNumber() +
17+
", itemId='" + getItemId() + '\'' +
18+
", outputIndex=" + getOutputIndex() +
19+
'}';
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.volcengine.ark.runtime.model.responses.event.knowledgesearch;
2+
3+
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
4+
import com.volcengine.ark.runtime.model.responses.event.ItemEvent;
5+
6+
public class KnowledgeSearchCallInProgressEvent extends ItemEvent {
7+
8+
public KnowledgeSearchCallInProgressEvent() {
9+
super(ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_IN_PROGRESS);
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return "KnowledgeSearchCallInProgressEvent{" +
15+
"type='" + getType() + '\'' +
16+
", sequenceNumber=" + getSequenceNumber() +
17+
", itemId='" + getItemId() + '\'' +
18+
", outputIndex=" + getOutputIndex() +
19+
'}';
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.volcengine.ark.runtime.model.responses.event.knowledgesearch;
2+
3+
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
4+
import com.volcengine.ark.runtime.model.responses.event.ItemEvent;
5+
6+
public class KnowledgeSearchCallSearchingEvent extends ItemEvent {
7+
8+
public KnowledgeSearchCallSearchingEvent() {
9+
super(ResponsesConstants.EVENT_TYPE_RESPONSE_KNOWLEDGE_SEARCH_CALL_SEARCHING);
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return "KnowledgeSearchCallSearchingEvent{" +
15+
"type='" + getType() + '\'' +
16+
", sequenceNumber=" + getSequenceNumber() +
17+
", itemId='" + getItemId() + '\'' +
18+
", outputIndex=" + getOutputIndex() +
19+
'}';
20+
}
21+
}

0 commit comments

Comments
 (0)