Skip to content
Open
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
142 changes: 142 additions & 0 deletions app-builder/plugins/data-mate-knowledge/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>modelengine.fit.jade</groupId>
<artifactId>app-builder-plugin-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<groupId>modelengine.jade.plugin</groupId>
<artifactId>data-mate-knowledge</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- FIT -->
<dependency>
<groupId>org.fitframework</groupId>
<artifactId>fit-api</artifactId>
</dependency>

<!-- Service -->
<dependency>
<groupId>modelengine.fit.jade.service</groupId>
<artifactId>knowledge-service</artifactId>
</dependency>

<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<!-- Mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>

<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.fitframework</groupId>
<artifactId>fit-test-framework</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.fitframework</groupId>
<artifactId>fit-build-maven-plugin</artifactId>
<version>${fit.version}</version>
<executions>
<execution>
<id>build-plugin</id>
<goals>
<goal>build-plugin</goal>
</goals>
</execution>
<execution>
<id>package-plugin</id>
<goals>
<goal>package-plugin</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.fitframework</groupId>
<artifactId>fit-dependency-maven-plugin</artifactId>
<version>${fit.version}</version>
<executions>
<execution>
<id>dependency</id>
<phase>compile</phase>
<goals>
<goal>dependency</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.version}</version>
<configuration>
<archive>
<manifestEntries>
<Created-By>FIT Lab</Created-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven.antrun.version}</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.jar"
todir="../../../build/plugins"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package modelengine.fit.jade.datamate.knowledge.knowledge.convertor;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import modelengine.fitframework.util.StringUtils;
import modelengine.jade.knowledge.KnowledgeRepo;
import modelengine.jade.knowledge.ReferenceLimit;
import modelengine.jade.knowledge.document.KnowledgeDocument;
import modelengine.fit.jade.datamate.knowledge.knowledge.dto.DataMateRetrievalParam;
import modelengine.fit.jade.datamate.knowledge.knowledge.entity.DataMateKnowledgeEntity;
import modelengine.fit.jade.datamate.knowledge.knowledge.entity.DataMateRetrievalChunksEntity;
import modelengine.jade.knowledge.support.FlatKnowledgeOption;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
* DataMate 内部数据的转换器接口。
*
* @author 陈镕希
* @since 2025-12-15
*/
@Mapper
public interface ParamConvertor {
ParamConvertor INSTANCE = Mappers.getMapper(ParamConvertor.class);
int TOP = 400;

/**
* 将 {@link DataMateKnowledgeEntity} 转换为 {@link KnowledgeRepo}。
*
* @param entity 表示待转换的 {@link DataMateKnowledgeEntity}。
* @return 转换完成的 {@link KnowledgeRepo}。
*/
@Mapping(target = "type", source = "entity", qualifiedByName = "mapIndexTypeToType")
@Mapping(target = "createdAt", source = "entity", qualifiedByName = "stringToLocalDateTime")
KnowledgeRepo convertToKnowledgeRepo(DataMateKnowledgeEntity entity);

/**
* 将 DataMate 知识库的检索 type 映射为 平台知识库元数据 type。
*
* @param entity 表示待转换的 {@link DataMateKnowledgeEntity}。
* @return 表示转换完成的 {@link String}。
*/
@Named("mapIndexTypeToType")
default String mapIndexTypeToType(DataMateKnowledgeEntity entity) {
return entity == null ? null : entity.getEmbeddingModel();
}

/**
* 将 DataMate 知识库的 createdAt 映射为 平台知识库元数据 createdAt。
*
* @param entity 表示待转换的 {@link DataMateKnowledgeEntity}。
* @return 表示转换完成的 {@link LocalDateTime}。
*/
@Named("stringToLocalDateTime")
default LocalDateTime stringToLocalDateTime(DataMateKnowledgeEntity entity) {
String dateStr = entity.getCreatedAt();
if (dateStr == null || StringUtils.isEmpty(dateStr)) {
return null;
}
return LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_DATE_TIME);
}

/**
* 将 {@link FlatKnowledgeOption} 转换为 {@link DataMateRetrievalParam}。
*
* @param option 表示待转换的 {@link FlatKnowledgeOption}。
* @return 转换完成的 {@link DataMateRetrievalParam}。
*/
@Mapping(target = "knowledgeBaseIds", source = "repoIds")
@Mapping(target = "query", source = "query")
@Mapping(target = "topK", source = "referenceLimit", qualifiedByName = "mapReferenceLimitToTop")
@Mapping(target = "threshold", source = "similarityThreshold")
DataMateRetrievalParam convertToRetrievalParam(FlatKnowledgeOption option);

/**
* 将平台检索请求 ReferenceLimit 映射为 DataMate 检索请求 top。
*
* @param limit 表示待转换的 {@link ReferenceLimit}。
* @return 转换完成的 {@link int}。
*/
@Named("mapReferenceLimitToTop")
default int mapReferenceLimitToTop(ReferenceLimit limit) {
if (limit == null) {
return TOP;
}
return limit.getValue();
}

/**
* 将 {@link DataMateRetrievalChunksEntity} 转换为 {@link KnowledgeDocument}。
*
* @param entity 表示待转换的 {@link DataMateRetrievalChunksEntity}。
* @return 转换完成的 {@link KnowledgeDocument}。
*/
@Mapping(target = "id", expression = "java(entity.chunkId())")
@Mapping(target = "text", expression = "java(entity.content())")
@Mapping(target = "score", expression = "java(entity.retrievalScore())")
@Mapping(target = "metadata", source = ".", qualifiedByName = "mapChunksEntityToMetadata")
KnowledgeDocument convertToKnowledgeDocument(DataMateRetrievalChunksEntity entity);

/**
* 将 DataMate 检索结果 entity 映射为 平台检索结果 metadata。
*
* @param entity 表示待转换的 {@link DataMateRetrievalChunksEntity}。
* @return 转换完成的 {@link Map}{@code <}{@link String}{@code , }{@link Object}{@code >}。
*/
@Named("mapChunksEntityToMetadata")
default Map<String, Object> mapChunksEntityToMetadata(DataMateRetrievalChunksEntity entity) {
Map<String, Object> metadata = new HashMap<>();
if (entity == null || entity.getEntity() == null) {
return metadata;
}
metadata.put("primaryKey", entity.getPrimaryKey());
String rawMetadata = entity.getEntity().getMetadata();
if (!StringUtils.isEmpty(rawMetadata)) {
try {
Map<String, Object> parsed = new ObjectMapper().readValue(rawMetadata, Map.class);
metadata.putAll(parsed);
} catch (JsonProcessingException ex) {
metadata.put("metadata", rawMetadata);
}
}
return metadata;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package modelengine.fit.jade.datamate.knowledge.knowledge.dto;

import lombok.Builder;
import lombok.Data;
import modelengine.fitframework.serialization.annotation.SerializeStrategy;

/**
* DataMate 知识库列表查询参数。
*
* @author 陈镕希
* @since 2025-12-15
*/
@Data
@Builder
@SerializeStrategy(include = SerializeStrategy.Include.NON_NULL)
public class DataMateKnowledgeListQueryParam {
/**
* 页码,从0开始。
*/
private Integer page;

/**
* 每页大小。
*/
private Integer size;

/**
* 知识库名称过滤。
*/
private String name;

/**
* 知识库描述过滤。
*/
private String description;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package modelengine.fit.jade.datamate.knowledge.knowledge.dto;

import lombok.Builder;
import lombok.Data;
import modelengine.fitframework.annotation.Property;

import java.util.List;

/**
* DataMate 知识库检索查询参数。
*
* @author 陈镕希
* @since 2025-12-15
*/
@Data
@Builder
public class DataMateRetrievalParam {
/**
* 检索 query。
*/
private String query;
/**
* 返回前多少的条目。
*/
@Property(description = "topK", name = "topK")
Copy link
Contributor

Choose a reason for hiding this comment

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

image 字段间需要换行

private Integer topK;
/**
* 相关性阈值。
Copy link
Contributor

Choose a reason for hiding this comment

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

Uploading image.png…
字段间需要换行

*/
@Property(description = "threshold", name = "threshold")
private Double threshold;
/**
* 指定知识库的id集合。
*/
@Property(description = "knowledgeBaseIds", name = "knowledgeBaseIds")
private List<String> knowledgeBaseIds;
}

Loading
Loading