Skip to content

Commit 3f442ea

Browse files
committed
feat: add rag API
1 parent b88ee1b commit 3f442ea

File tree

128 files changed

+1891
-18700
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1891
-18700
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target/
1212
*.iml
1313
*.ipr
1414
/logs
15+
*.log
1516
### Eclipse ###
1617
.apt_generated
1718
.classpath
@@ -38,6 +39,4 @@ build/
3839
### Mac OS ###
3940
.DS_Store
4041

41-
42-
src/main/java/com/tinyengine/it/js/node_modules
43-
src/main/java/com/tinyengine/it/js/package-lock.json
42+
chroma_env/

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ WORKDIR /app
1515
COPY --from=build /app/app/target/tiny-engine-app-*.jar /app/tiny-engine-app.jar
1616
COPY --from=build /app/base/target/tiny-engine-base-*.jar /app/tiny-engine-base.jar
1717
# 设置环境变量
18-
ENV ACCESS_KEY_ID=" "
19-
ENV ACCESS_KEY_SECRET = " "
20-
ENV INDEX_ID = " "
21-
ENV WORK_SPACE_ID = ""
18+
19+
ENV FOLDER_PATH = "/app/documents"
2220
# 替换为自己的域名接口路径
2321
ENV TINY_ENGINE_URL="https://agent.opentiny.design/material-center/api/resource/download"
2422
ENTRYPOINT ["java", "-jar", "tiny-engine-app.jar", "--spring.profiles.active=alpha"]

all-MiniLM-L6-v2/model.onnx

86.2 MB
Binary file not shown.

all-MiniLM-L6-v2/tokenizer.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/com/tinyengine/it/task/CleanupProperties.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.springframework.boot.context.properties.ConfigurationProperties;
1616
import org.springframework.context.annotation.Configuration;
17+
1718
import java.util.List;
1819

1920
@Configuration
@@ -26,18 +27,43 @@ public class CleanupProperties {
2627
private String cronExpression = "0 0 0 * * ?";
2728
private boolean sendWarning = true;
2829

29-
public boolean isEnabled() { return enabled; }
30-
public void setEnabled(boolean enabled) { this.enabled = enabled; }
30+
public boolean isEnabled() {
31+
return enabled;
32+
}
33+
34+
public void setEnabled(boolean enabled) {
35+
this.enabled = enabled;
36+
}
37+
38+
public boolean isUseTruncate() {
39+
return useTruncate;
40+
}
41+
42+
public void setUseTruncate(boolean useTruncate) {
43+
this.useTruncate = useTruncate;
44+
}
45+
46+
public List<String> getWhitelistTables() {
47+
return whitelistTables;
48+
}
49+
50+
public void setWhitelistTables(List<String> whitelistTables) {
51+
this.whitelistTables = whitelistTables;
52+
}
3153

32-
public boolean isUseTruncate() { return useTruncate; }
33-
public void setUseTruncate(boolean useTruncate) { this.useTruncate = useTruncate; }
54+
public String getCronExpression() {
55+
return cronExpression;
56+
}
3457

35-
public List<String> getWhitelistTables() { return whitelistTables; }
36-
public void setWhitelistTables(List<String> whitelistTables) { this.whitelistTables = whitelistTables; }
58+
public void setCronExpression(String cronExpression) {
59+
this.cronExpression = cronExpression;
60+
}
3761

38-
public String getCronExpression() { return cronExpression; }
39-
public void setCronExpression(String cronExpression) { this.cronExpression = cronExpression; }
62+
public boolean isSendWarning() {
63+
return sendWarning;
64+
}
4065

41-
public boolean isSendWarning() { return sendWarning; }
42-
public void setSendWarning(boolean sendWarning) { this.sendWarning = sendWarning; }
66+
public void setSendWarning(boolean sendWarning) {
67+
this.sendWarning = sendWarning;
68+
}
4369
}

app/src/main/java/com/tinyengine/it/task/DatabaseCleanupService.java

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,35 @@
1919
import org.springframework.stereotype.Service;
2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
22+
2223
import java.time.LocalDateTime;
2324
import java.time.format.DateTimeFormatter;
2425
import java.util.*;
2526
import java.util.concurrent.ConcurrentHashMap;
2627
import java.util.concurrent.atomic.AtomicInteger;
28+
2729
@Service
2830
public class DatabaseCleanupService {
2931

3032
private static final Logger logger = LoggerFactory.getLogger(DatabaseCleanupService.class);
31-
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
33+
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
3234

3335
@Autowired
3436
private JdbcTemplate jdbcTemplate;
3537

3638
@Autowired
3739
private CleanupProperties cleanupProperties;
38-
// 执行统计
40+
3941
private final Map<String, ExecutionStats> executionStats = new ConcurrentHashMap<>();
42+
4043
private final AtomicInteger totalExecutions = new AtomicInteger(0);
4144

4245
// 默认白名单表(如果配置文件未设置)
4346
private static final List<String> DEFAULT_TABLES = Arrays.asList(
44-
"t_resource", "t_resource_group", "r_resource_group_resource", "t_app_extension",
45-
"t_block", "t_block_carriers_relation", "t_block_group", "t_block_history",
46-
"r_material_block", "r_material_history_block", "r_block_group_block", "t_datasource",
47-
"t_i18n_entry", "t_model", "t_page", "t_page_history", "t_page_template"
47+
"t_resource", "t_resource_group", "r_resource_group_resource", "t_app_extension",
48+
"t_block", "t_block_carriers_relation", "t_block_group", "t_block_history",
49+
"r_material_block", "r_material_history_block", "r_block_group_block", "t_datasource",
50+
"t_i18n_entry", "t_model", "t_page", "t_page_history", "t_page_template"
4851
);
4952

5053
/**
@@ -53,32 +56,32 @@ public class DatabaseCleanupService {
5356
@Scheduled(cron = "${cleanup.cron-expression:0 0 0 * * ?}")
5457
public void autoCleanupAtMidnight() {
5558
if (!cleanupProperties.isEnabled()) {
56-
logger.info("⏸️ 清空任务已禁用,跳过执行");
59+
logger.info("⏸️ Clearing tasks is disabled, skipping execution");
5760
return;
5861
}
5962

6063
String executionId = UUID.randomUUID().toString().substring(0, 8);
61-
String startTime = LocalDateTime.now().format(formatter);
64+
String startTime = LocalDateTime.now().format(FORMATTER);
6265

63-
logger.info("🎯 ======= 开始执行数据库清空任务 [{}] =======", executionId);
64-
logger.info("⏰ 执行时间: {}", startTime);
65-
logger.info("📋 目标表: {}", getWhitelistTables());
66+
logger.info("======= Start executing the database clearing task [{}] =======", executionId);
67+
logger.info("⏰ Time: {}", startTime);
68+
logger.info("📋 Tables: {}", getWhitelistTables());
6669

6770
ExecutionStats stats = new ExecutionStats(executionId, startTime);
6871
executionStats.put(executionId, stats);
6972
totalExecutions.incrementAndGet();
7073

7174
int successCount = 0;
7275
int failedCount = 0;
73-
long totalRowsCleaned = 0;
76+
long totalRowsCleaned = 0L;
7477

7578
for (String tableName : getWhitelistTables()) {
7679
try {
7780
validateTableName(tableName);
7881

7982
if (!tableExists(tableName)) {
80-
logger.warn("⚠️ {} 不存在,跳过", tableName);
81-
stats.recordSkipped(tableName, "表不存在");
83+
logger.warn("⚠️ Table {} does not exist, skip", tableName);
84+
stats.recordSkipped(tableName, "Table does not exist");
8285
continue;
8386
}
8487

@@ -87,35 +90,35 @@ public void autoCleanupAtMidnight() {
8790

8891
if (cleanupProperties.isUseTruncate()) {
8992
truncateTable(tableName);
90-
rowsCleaned = beforeCount; // TRUNCATE会清空所有数据
93+
rowsCleaned = beforeCount;
9194
} else {
9295
rowsCleaned = clearTableData(tableName);
9396
}
9497

9598
totalRowsCleaned += rowsCleaned;
9699
successCount++;
97100

98-
logger.info("✅ {} 清空完成: 删除 {} 条记录", tableName, rowsCleaned);
101+
logger.info("✅ Table {} cleared: {} records deleted", tableName, rowsCleaned);
99102
stats.recordSuccess(tableName, rowsCleaned);
100103

101104
} catch (Exception e) {
102105
failedCount++;
103-
logger.error("❌ 表 {} 清空失败: {}", tableName, e.getMessage(), e);
106+
logger.error("❌ Failed to clear table {}: {}", tableName, e.getMessage(), e);
104107
stats.recordFailure(tableName, e.getMessage());
105108
}
106109
}
107110

108-
String endTime = LocalDateTime.now().format(formatter);
111+
String endTime = LocalDateTime.now().format(FORMATTER);
109112
stats.setEndTime(endTime);
110113
stats.setTotalRowsCleaned(totalRowsCleaned);
111114

112-
logger.info("📊 ======= 任务完成统计 [{}] =======", executionId);
113-
logger.info("✅ 成功表数: {}", successCount);
114-
logger.info("❌ 失败表数: {}", failedCount);
115-
logger.info("📈 总共删除记录: {}", totalRowsCleaned);
116-
logger.info("⏰ 耗时: {} ", stats.getDurationSeconds());
117-
logger.info("🕐 开始: {}, 结束: {}", startTime, endTime);
118-
logger.info("🎉 ======= 任务执行完成 =======\n");
115+
logger.info("📊 ======= Task Completion Statistics [{}] =======", executionId);
116+
logger.info("✅ Successful table count: {}", successCount);
117+
logger.info("❌ Failure count: {}", failedCount);
118+
logger.info("📈 Total deleted records: {}", totalRowsCleaned);
119+
logger.info("⏰ Time-consuming: {} second", stats.getDurationSeconds());
120+
logger.info("🕐 Start: {}, End: {}", startTime, endTime);
121+
logger.info("🎉 ======= Task execution completed =======\n");
119122
}
120123

121124
/**
@@ -127,10 +130,10 @@ public void sendCleanupWarning() {
127130
return;
128131
}
129132

130-
logger.warn("⚠️ ⚠️ ⚠️ 重要通知:5分钟后将自动清空数据库表!");
131-
logger.warn("📋 目标表: {}", getWhitelistTables());
132-
logger.warn("⏰ 执行时间: 00:00:00");
133-
logger.warn("💡 如需取消,请修改配置: cleanup.enabled=false");
133+
logger.warn("⚠️ ⚠️ ⚠️ Important Notice: The database table will be automatically cleared in 5 minutes!");
134+
logger.warn("📋 Target table: {}", getWhitelistTables());
135+
logger.warn("⏰ Execution Time: 00:00:00");
136+
logger.warn("💡 If you need to cancel, please change the settings: cleanup.enabled=false");
134137
logger.warn("==========================================");
135138
}
136139

@@ -139,12 +142,13 @@ public void sendCleanupWarning() {
139142
*/
140143
@PostConstruct
141144
public void init() {
142-
logger.info("🚀 数据库自动清空服务初始化完成");
143-
logger.info("📋 配置表: {}", getWhitelistTables());
144-
logger.info("⏰ 执行时间: {}", cleanupProperties.getCronExpression());
145-
logger.info("🔧 使用模式: {}", cleanupProperties.isUseTruncate() ? "TRUNCATE" : "DELETE");
146-
logger.info("✅ 服务状态: {}", cleanupProperties.isEnabled() ? "已启用" : "已禁用");
145+
logger.info("🚀 Database auto-clear service initialization completed");
146+
logger.info("📋 Configuration table: {}", getWhitelistTables());
147+
logger.info("⏰ Execution time: {}", cleanupProperties.getCronExpression());
148+
logger.info("🔧 Mode in use: {}", cleanupProperties.isUseTruncate() ? "TRUNCATE" : "DELETE");
149+
logger.info("✅ Service status: {}", cleanupProperties.isEnabled() ? "Enabled" : "Disabled");
147150
logger.info("==========================================");
151+
148152
}
149153

150154
/**
@@ -184,7 +188,7 @@ public boolean tableExists(String tableName) {
184188
Integer count = jdbcTemplate.queryForObject(sql, Integer.class, tableName.toUpperCase());
185189
return count != null && count > 0;
186190
} catch (Exception e) {
187-
logger.warn("检查表存在失败: {}", e.getMessage());
191+
logger.warn("The checklist has failed: {}", e.getMessage());
188192
return false;
189193
}
190194
}
@@ -209,10 +213,10 @@ public long getTableRecordCount(String tableName) {
209213
*/
210214
private void validateTableName(String tableName) {
211215
if (tableName == null || tableName.trim().isEmpty()) {
212-
throw new IllegalArgumentException("表名不能为空");
216+
throw new IllegalArgumentException("Table name cannot be empty");
213217
}
214218
if (!tableName.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
215-
throw new IllegalArgumentException("无效的表名格式: " + tableName);
219+
throw new IllegalArgumentException("Invalid table name format: " + tableName);
216220
}
217221
}
218222

@@ -255,18 +259,38 @@ public void recordSkipped(String tableName, String reason) {
255259
}
256260

257261
// Getters and setters
258-
public String getExecutionId() { return executionId; }
259-
public String getStartTime() { return startTime; }
260-
public String getEndTime() { return endTime; }
261-
public void setEndTime(String endTime) { this.endTime = endTime; }
262-
public long getTotalRowsCleaned() { return totalRowsCleaned; }
263-
public void setTotalRowsCleaned(long totalRowsCleaned) { this.totalRowsCleaned = totalRowsCleaned; }
264-
public Map<String, TableResult> getTableResults() { return tableResults; }
262+
public String getExecutionId() {
263+
return executionId;
264+
}
265+
266+
public String getStartTime() {
267+
return startTime;
268+
}
269+
270+
public String getEndTime() {
271+
return endTime;
272+
}
273+
274+
public void setEndTime(String endTime) {
275+
this.endTime = endTime;
276+
}
277+
278+
public long getTotalRowsCleaned() {
279+
return totalRowsCleaned;
280+
}
281+
282+
public void setTotalRowsCleaned(long totalRowsCleaned) {
283+
this.totalRowsCleaned = totalRowsCleaned;
284+
}
285+
286+
public Map<String, TableResult> getTableResults() {
287+
return tableResults;
288+
}
265289

266290
public long getDurationSeconds() {
267291
if (startTime != null && endTime != null) {
268-
LocalDateTime start = LocalDateTime.parse(startTime, formatter);
269-
LocalDateTime end = LocalDateTime.parse(endTime, formatter);
292+
LocalDateTime start = LocalDateTime.parse(startTime, FORMATTER);
293+
LocalDateTime end = LocalDateTime.parse(endTime, FORMATTER);
270294
return java.time.Duration.between(start, end).getSeconds();
271295
}
272296
return 0;
@@ -288,8 +312,16 @@ public TableResult(String status, long rowsCleaned, String message) {
288312
}
289313

290314
// Getters
291-
public String getStatus() { return status; }
292-
public long getRowsCleaned() { return rowsCleaned; }
293-
public String getMessage() { return message; }
315+
public String getStatus() {
316+
return status;
317+
}
318+
319+
public long getRowsCleaned() {
320+
return rowsCleaned;
321+
}
322+
323+
public String getMessage() {
324+
return message;
325+
}
294326
}
295327
}

base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,42 @@ public enum ExceptionEnum implements IBaseError {
255255
/**
256256
* Cm 326 exception enum.
257257
*/
258-
CM326("CM326", "Failed to write stream data");
258+
CM326("CM326", "Failed to write stream data"),
259+
260+
/**
261+
* Cm 327 exception enum.
262+
*/
263+
CM327("CM327", "无法初始化 ChromaDB 存储"),
264+
265+
/**
266+
* Cm 328 exception enum.
267+
*/
268+
CM328("CM328", "连接 ChromaDB 存储 失败"),
269+
270+
/**
271+
* Cm 329 exception enum.
272+
*/
273+
CM329("CM329", "未成功加载任何文档"),
274+
275+
/**
276+
* Cm 330 exception enum.
277+
*/
278+
CM330("CM330", "文档处理失败"),
279+
280+
/**
281+
* Cm 331 exception enum.
282+
*/
283+
CM331("CM331", "检索文档失败"),
284+
285+
/**
286+
* Cm 332 exception enum.
287+
*/
288+
CM332("CM332", "删除文档失败"),
289+
290+
/**
291+
* Cm 333 exception enum.
292+
*/
293+
CM333("CM333", "文件夹扫描失败");
259294

260295
/**
261296
* 错误码

base/src/main/java/com/tinyengine/it/common/log/SystemControllerLog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@Retention(RetentionPolicy.RUNTIME) // 运行时注解
2929
@Documented // 表明这个注解应该被 javadoc工具记录
3030
public @interface SystemControllerLog {
31+
3132
/**
3233
* description
3334
*

0 commit comments

Comments
 (0)