-
Notifications
You must be signed in to change notification settings - Fork 229
[app-platform] Add open source knowledge repo impl. #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RonnyChan96
wants to merge
1
commit into
ModelEngine-Group:1.3.x
Choose a base branch
from
RonnyChan96:1.3.x_add_open_source_knowledge_repo
base: 1.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
140 changes: 140 additions & 0 deletions
140
...main/java/modelengine/fit/jade/datamate/knowledge/knowledge/convertor/ParamConvertor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
|
43 changes: 43 additions & 0 deletions
43
...odelengine/fit/jade/datamate/knowledge/knowledge/dto/DataMateKnowledgeListQueryParam.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
44 changes: 44 additions & 0 deletions
44
...in/java/modelengine/fit/jade/datamate/knowledge/knowledge/dto/DataMateRetrievalParam.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| private Integer topK; | ||
| /** | ||
| * 相关性阈值。 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| */ | ||
| @Property(description = "threshold", name = "threshold") | ||
| private Double threshold; | ||
| /** | ||
desAweis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * 指定知识库的id集合。 | ||
| */ | ||
| @Property(description = "knowledgeBaseIds", name = "knowledgeBaseIds") | ||
| private List<String> knowledgeBaseIds; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.