Skip to content

Commit 3662c0c

Browse files
authored
fix: 字段或表描述为空字符串时,部分嵌入模型API调用报错导致,导致初始化失败。 (spring-ai-alibaba#170)
1 parent 24e9ccb commit 3662c0c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

data-agent-management/src/main/java/com/alibaba/cloud/ai/dataagent/common/util/DocumentConverterUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.alibaba.cloud.ai.dataagent.entity.AgentKnowledge;
2323
import com.alibaba.cloud.ai.dataagent.entity.BusinessKnowledge;
2424
import lombok.extern.slf4j.Slf4j;
25+
import org.apache.commons.lang3.StringUtils;
2526
import org.springframework.ai.document.Document;
2627

2728
import java.util.*;
@@ -56,7 +57,8 @@ public static List<Document> convertColumnsToDocuments(String agentId, List<Tabl
5657
*/
5758
public static Document convertColumnToDocumentForAgent(String agentId, TableInfoBO tableInfoBO,
5859
ColumnInfoBO columnInfoBO) {
59-
String text = Optional.ofNullable(columnInfoBO.getDescription()).orElse(columnInfoBO.getName());
60+
String text = StringUtils.isBlank(columnInfoBO.getDescription()) ? columnInfoBO.getName()
61+
: columnInfoBO.getDescription();
6062
Map<String, Object> metadata = new HashMap<>();
6163
metadata.put("name", columnInfoBO.getName());
6264
metadata.put("tableName", tableInfoBO.getName());
@@ -80,7 +82,8 @@ public static Document convertColumnToDocumentForAgent(String agentId, TableInfo
8082
* @return Document object with table metadata
8183
*/
8284
public static Document convertTableToDocumentForAgent(String agentId, TableInfoBO tableInfoBO) {
83-
String text = Optional.ofNullable(tableInfoBO.getDescription()).orElse(tableInfoBO.getName());
85+
String text = StringUtils.isBlank(tableInfoBO.getDescription()) ? tableInfoBO.getName()
86+
: tableInfoBO.getDescription();
8487
Map<String, Object> metadata = new HashMap<>();
8588
metadata.put("schema", Optional.ofNullable(tableInfoBO.getSchema()).orElse(""));
8689
metadata.put("name", tableInfoBO.getName());

0 commit comments

Comments
 (0)