作者 lixiang

删除无用代码

1 -package org.jeecg.modules.airag.app.config;  
2 -  
3 -import org.springframework.boot.context.properties.ConfigurationProperties;  
4 -import org.springframework.boot.jdbc.DataSourceBuilder;  
5 -import org.springframework.context.annotation.Bean;  
6 -import org.springframework.context.annotation.Configuration;  
7 -import org.springframework.context.annotation.Primary;  
8 -  
9 -import javax.sql.DataSource;  
10 -  
11 -@Configuration  
12 -public class DataSourceConfig {  
13 -  
14 -// @Bean(name = "mysqlDataSource")  
15 -// @Primary  
16 -// @ConfigurationProperties(prefix = "spring.datasource.mysql")  
17 -// public DataSource mysqlDataSource() {  
18 -// return DataSourceBuilder.create().build();  
19 -// }  
20 -//  
21 -// @Bean(name = "postgresDataSource")  
22 -// @ConfigurationProperties(prefix = "spring.datasource.postgres")  
23 -// public DataSource postgresDataSource() {  
24 -// return DataSourceBuilder.create().build();  
25 -// }  
26 -}  
1 -//package org.jeecg.modules.airag.app.config;  
2 -//  
3 -//import org.springframework.beans.factory.annotation.Qualifier;  
4 -//import org.springframework.boot.context.properties.ConfigurationProperties;  
5 -//import org.springframework.boot.jdbc.DataSourceBuilder;  
6 -//import org.springframework.context.annotation.Bean;  
7 -//import org.springframework.context.annotation.Configuration;  
8 -//import org.springframework.jdbc.core.JdbcTemplate;  
9 -//  
10 -//import javax.sql.DataSource;  
11 -//  
12 -//@Configuration  
13 -//public class PgVectorDataSourceConfig {  
14 -//  
15 -// @Bean(name = "pgVectorDataSource")  
16 -// @ConfigurationProperties(prefix = "spring.datasource.dynamic.datasource.pgvector")  
17 -// public DataSource pgVectorDataSource() {  
18 -// return DataSourceBuilder.create().build();  
19 -// }  
20 -//  
21 -// @Bean(name = "pgVectorJdbcTemplate")  
22 -// public JdbcTemplate pgVectorJdbcTemplate(  
23 -// @Qualifier("pgVectorDataSource") DataSource dataSource) {  
24 -// return new JdbcTemplate(dataSource);  
25 -// }  
26 -//}  
1 -//package org.jeecg.modules.airag.app.config;  
2 -//import dev.langchain4j.data.document.Metadata;  
3 -//import dev.langchain4j.data.embedding.Embedding;  
4 -//import dev.langchain4j.data.segment.TextSegment;  
5 -//import dev.langchain4j.store.embedding.EmbeddingMatch;  
6 -//import dev.langchain4j.store.embedding.EmbeddingSearchRequest;  
7 -//import dev.langchain4j.store.embedding.EmbeddingSearchResult;  
8 -//import dev.langchain4j.store.embedding.EmbeddingStore;  
9 -//import dev.langchain4j.store.embedding.filter.Filter;  
10 -//import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;  
11 -//import lombok.extern.log4j.Log4j2;  
12 -//import org.springframework.beans.factory.annotation.Autowired;  
13 -//import org.springframework.beans.factory.annotation.Qualifier;  
14 -//import org.springframework.jdbc.core.JdbcTemplate;  
15 -//import org.springframework.stereotype.Component;  
16 -//  
17 -//import javax.sql.DataSource;  
18 -//import java.util.ArrayList;  
19 -//import java.util.Collection;  
20 -//import java.util.List;  
21 -//import java.util.Map;  
22 -//import java.util.Collection;  
23 -//import java.util.List;  
24 -//import java.util.stream.Collectors;  
25 -//  
26 -//@Component  
27 -//@Log4j2  
28 -//public class PostgreEmbeddingStore implements EmbeddingStore<TextSegment> {  
29 -//  
30 -// @Autowired  
31 -// private PgVectorEmbeddingStore pgVectorEmbeddingStore;  
32 -//  
33 -// @Autowired  
34 -// private JdbcTemplate pgJdbcTemplate;  
35 -//  
36 -// @Autowired  
37 -// public PostgreEmbeddingStore(  
38 -// PgVectorEmbeddingStore pgVectorEmbeddingStore) {  
39 -// this.pgJdbcTemplate = pgJdbcTemplate;  
40 -// this.pgVectorEmbeddingStore = pgVectorEmbeddingStore;  
41 -// }  
42 -//  
43 -//  
44 -// @Override  
45 -// public String add(Embedding embedding) {  
46 -// return "";  
47 -// }  
48 -//  
49 -// @Override  
50 -// public void add(String id, Embedding embedding) {  
51 -//  
52 -// }  
53 -//  
54 -// @Override  
55 -// public String add(Embedding embedding, TextSegment textSegment) {  
56 -// return "";  
57 -// }  
58 -//  
59 -// @Override  
60 -// public List<String> addAll(List<Embedding> embeddings) {  
61 -// return List.of();  
62 -// }  
63 -//  
64 -// @Override  
65 -// public List<String> addAll(List<Embedding> embeddings, List<TextSegment> embedded) {  
66 -// return List.of();  
67 -// }  
68 -//  
69 -// @Override  
70 -// public void remove(String id) {  
71 -// EmbeddingStore.super.remove(id);  
72 -// }  
73 -//  
74 -// @Override  
75 -// public void removeAll(Collection<String> ids) {  
76 -// EmbeddingStore.super.removeAll(ids);  
77 -// }  
78 -//  
79 -// @Override  
80 -// public void removeAll(Filter filter) {  
81 -// EmbeddingStore.super.removeAll(filter);  
82 -// }  
83 -//  
84 -// @Override  
85 -// public void removeAll() {  
86 -// EmbeddingStore.super.removeAll();  
87 -// }  
88 -//  
89 -// @Override  
90 -// public EmbeddingSearchResult<TextSegment> search(EmbeddingSearchRequest request) {  
91 -// return EmbeddingStore.super.search(request);  
92 -// }  
93 -//  
94 -// @Override  
95 -// public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding referenceEmbedding, int maxResults) {  
96 -// return findRelevant(referenceEmbedding, maxResults, 0.0);  
97 -// }  
98 -//  
99 -// @Override  
100 -// public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding referenceEmbedding, int maxResults, double minScore) {  
101 -// try {  
102 -//// // 使用 PgVectorEmbeddingStore 进行查询  
103 -//// EmbeddingSearchRequest request = EmbeddingSearchRequest.builder()  
104 -//// .queryEmbedding(referenceEmbedding)  
105 -//// .maxResults(maxResults)  
106 -//// .minScore(minScore)  
107 -//// .build();  
108 -//  
109 -// // 构建带内存ID过滤的查询  
110 -// String sql = "SELECT id, content, metadata, embedding <=> ? AS distance " +  
111 -// "FROM embeddings " +  
112 -// "WHERE (1 - (embedding <=> ?)) >= ? " +  
113 -// "ORDER BY distance " +  
114 -// "LIMIT ?";  
115 -//  
116 -// List<Map<String, Object>> rows = pgJdbcTemplate.queryForList(  
117 -// sql,  
118 -// referenceEmbedding.vectorAsList(),  
119 -// referenceEmbedding.vectorAsList(),  
120 -// minScore,  
121 -// maxResults  
122 -// );  
123 -//  
124 -//  
125 -//  
126 -//// EmbeddingSearchResult<TextSegment> result = pgVectorEmbeddingStore.search(request);  
127 -////  
128 -////  
129 -// return convertToMatches(rows);  
130 -// } catch (Exception e) {  
131 -// log.error("向量查询失败", e);  
132 -// throw new RuntimeException("向量搜索失败: " + e.getMessage(), e);  
133 -// }  
134 -// }  
135 -//  
136 -// @Override  
137 -// public List<EmbeddingMatch<TextSegment>> findRelevant(Object memoryId, Embedding referenceEmbedding, int maxResults) {  
138 -// return findRelevant(memoryId, referenceEmbedding, maxResults, 0.0);  
139 -// }  
140 -//  
141 -// @Override  
142 -// public List<EmbeddingMatch<TextSegment>> findRelevant(Object memoryId, Embedding referenceEmbedding,  
143 -// int maxResults, double minScore) {  
144 -// try {  
145 -// // 构建带内存ID过滤的查询  
146 -// String sql = "SELECT id, content, metadata, embedding <=> ? AS distance " +  
147 -// "FROM embeddings " +  
148 -// "WHERE metadata->>'memory_id' = ? " +  
149 -// "AND (1 - (embedding <=> ?)) >= ? " +  
150 -// "ORDER BY distance " +  
151 -// "LIMIT ?";  
152 -//  
153 -// List<Map<String, Object>> rows = pgJdbcTemplate.queryForList(  
154 -// sql,  
155 -// referenceEmbedding.vectorAsList(),  
156 -// memoryId.toString(),  
157 -// referenceEmbedding.vectorAsList(),  
158 -// minScore,  
159 -// maxResults  
160 -// );  
161 -//  
162 -// return convertToMatches(rows);  
163 -// } catch (Exception e) {  
164 -// log.error("带内存ID的向量查询失败", e);  
165 -// throw new RuntimeException("带内存ID的向量搜索失败: " + e.getMessage(), e);  
166 -// }  
167 -// }  
168 -//  
169 -// private List<EmbeddingMatch<TextSegment>> convertToMatches(List<Map<String, Object>> rows) {  
170 -// List<EmbeddingMatch<TextSegment>> matches = new ArrayList<>();  
171 -// for (Map<String, Object> row : rows) {  
172 -// String id = row.get("id").toString();  
173 -// String content = (String) row.get("content");  
174 -//  
175 -// // 处理 Metadata  
176 -// Map<String, String> metadataMap = (Map<String, String>) row.get("metadata");  
177 -// Metadata metadata = Metadata.from(metadataMap);  
178 -//  
179 -// // 处理 Embedding 转换  
180 -// List<Float> embeddingList = (List<Float>) row.get("embedding");  
181 -// float[] embeddingArray = new float[embeddingList.size()];  
182 -// for (int i = 0; i < embeddingList.size(); i++) {  
183 -// embeddingArray[i] = embeddingList.get(i);  
184 -// }  
185 -// Embedding embedding = new Embedding(embeddingArray);  
186 -//  
187 -// double score = 1 - (double) row.get("distance");  
188 -// TextSegment textSegment = TextSegment.from(content, metadata);  
189 -//  
190 -// matches.add(new EmbeddingMatch<>(score, id, embedding, textSegment));  
191 -// }  
192 -// return matches;  
193 -// }  
194 -//}  
1 -//package org.jeecg.modules.airag.app.config;  
2 -//  
3 -//import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;  
4 -//import org.springframework.beans.factory.annotation.Value;  
5 -//import org.springframework.context.annotation.Bean;  
6 -//import org.springframework.context.annotation.Configuration;  
7 -//  
8 -//@Configuration  
9 -//public class VectorStoreConfig {  
10 -// @Value("${jeecg.ai-rag.embed-store.host}")  
11 -// private String host;  
12 -// @Value("${jeecg.ai-rag.embed-store.port}")  
13 -// private Integer port;  
14 -// @Value("${jeecg.ai-rag.embed-store.database}")  
15 -// private String database;  
16 -// @Value("${jeecg.ai-rag.embed-store.user}")  
17 -// private String user;  
18 -// @Value("${jeecg.ai-rag.embed-store.password}")  
19 -// private String password;  
20 -//// @Value("${spring.datasource.vector.url}")  
21 -//// private String url;  
22 -////  
23 -//// @Value("${spring.datasource.vector.username}")  
24 -//// private String username;  
25 -////  
26 -//// @Value("${spring.datasource.vector.password}")  
27 -//// private String password;  
28 -//  
29 -// @Bean  
30 -// public PgVectorEmbeddingStore pgVectorEmbeddingStore() {  
31 -// return PgVectorEmbeddingStore.builder()  
32 -// .host(host) // 如果使用独立参数  
33 -// .port(port)  
34 -// .user(user)  
35 -// .password(password)  
36 -// .database(database)  
37 -// .table("embeddings")  
38 -// .dimension(1536) // 根据你的模型维度设置  
39 -// .useIndex(true)  
40 -// .createTable(true)  
41 -// .build();  
42 -//  
43 -//// return PgVectorEmbeddingStore.builder()  
44 -//// .dataSource(dataSource) // 注入配置好的DataSource  
45 -//// .table("embeddings")  
46 -//// .dimension(1536)  
47 -//// .build();  
48 -// }  
49 -//}  
1 package org.jeecg.modules.airag.app.controller; 1 package org.jeecg.modules.airag.app.controller;
2 2
3 -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;  
4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 3 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 import com.baomidou.mybatisplus.core.metadata.IPage; 4 import com.baomidou.mybatisplus.core.metadata.IPage;
6 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7 -import com.fasterxml.jackson.core.JsonProcessingException;  
8 import io.swagger.v3.oas.annotations.Operation; 6 import io.swagger.v3.oas.annotations.Operation;
9 import io.swagger.v3.oas.annotations.tags.Tag; 7 import io.swagger.v3.oas.annotations.tags.Tag;
10 import lombok.extern.slf4j.Slf4j; 8 import lombok.extern.slf4j.Slf4j;
@@ -14,12 +12,10 @@ import org.jeecg.common.api.vo.Result; @@ -14,12 +12,10 @@ import org.jeecg.common.api.vo.Result;
14 import org.jeecg.common.aspect.annotation.AutoLog; 12 import org.jeecg.common.aspect.annotation.AutoLog;
15 import org.jeecg.common.system.base.controller.JeecgController; 13 import org.jeecg.common.system.base.controller.JeecgController;
16 import org.jeecg.common.system.query.QueryGenerator; 14 import org.jeecg.common.system.query.QueryGenerator;
17 -import org.jeecg.modules.airag.app.config.DataSourceConfig;  
18 import org.jeecg.modules.airag.app.entity.AiragButton; 15 import org.jeecg.modules.airag.app.entity.AiragButton;
19 import org.jeecg.modules.airag.app.entity.AiragLog; 16 import org.jeecg.modules.airag.app.entity.AiragLog;
20 import org.jeecg.modules.airag.app.entity.Embeddings; 17 import org.jeecg.modules.airag.app.entity.Embeddings;
21 import org.jeecg.modules.airag.app.entity.QuestionEmbedding; 18 import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
22 -import org.jeecg.modules.airag.app.mapper.AiragButtonMapper;  
23 import org.jeecg.modules.airag.app.service.IAiragButtonService; 19 import org.jeecg.modules.airag.app.service.IAiragButtonService;
24 import org.jeecg.modules.airag.app.service.IAiragLogService; 20 import org.jeecg.modules.airag.app.service.IAiragLogService;
25 import org.jeecg.modules.airag.app.service.IEmbeddingsService; 21 import org.jeecg.modules.airag.app.service.IEmbeddingsService;
1 -package org.jeecg.modules.airag.app.entity;  
2 -  
3 -import java.io.Serializable;  
4 -import java.io.UnsupportedEncodingException;  
5 -import java.util.Date;  
6 -import java.math.BigDecimal;  
7 -import com.baomidou.mybatisplus.annotation.IdType;  
8 -import com.baomidou.mybatisplus.annotation.TableId;  
9 -import com.baomidou.mybatisplus.annotation.TableName;  
10 -import com.baomidou.mybatisplus.annotation.TableLogic;  
11 -import org.jeecg.common.constant.ProvinceCityArea;  
12 -import org.jeecg.common.util.SpringContextUtils;  
13 -import lombok.Data;  
14 -import com.fasterxml.jackson.annotation.JsonFormat;  
15 -import org.springframework.format.annotation.DateTimeFormat;  
16 -import org.jeecgframework.poi.excel.annotation.Excel;  
17 -import org.jeecg.common.aspect.annotation.Dict;  
18 -import io.swagger.v3.oas.annotations.media.Schema;  
19 -import lombok.EqualsAndHashCode;  
20 -import lombok.experimental.Accessors;  
21 -  
22 -/**  
23 - * @Description: test  
24 - * @Author: jeecg-boot  
25 - * @Date: 2025-05-26  
26 - * @Version: V1.0  
27 - */  
28 -@Data  
29 -@TableName("test")  
30 -@Accessors(chain = true)  
31 -@EqualsAndHashCode(callSuper = false)  
32 -@Schema(description="test")  
33 -public class Test implements Serializable {  
34 - private static final long serialVersionUID = 1L;  
35 -  
36 - /**id*/  
37 - @TableId(type = IdType.ASSIGN_ID)  
38 - @Schema(description = "id")  
39 - private Integer id;  
40 - /**name*/  
41 - @Excel(name = "name", width = 15)  
42 - @Schema(description = "name")  
43 - private String name;  
44 -}  
1 -package org.jeecg.modules.airag.app.mapper;  
2 -  
3 -import java.util.List;  
4 -  
5 -import org.apache.ibatis.annotations.Param;  
6 -import com.baomidou.mybatisplus.core.mapper.BaseMapper;  
7 -import org.jeecg.modules.airag.app.entity.Embeddings;  
8 -import org.jeecg.modules.airag.app.entity.Test;  
9 -  
10 -/**  
11 - * @Description: test  
12 - * @Author: jeecg-boot  
13 - * @Date: 2025-05-26  
14 - * @Version: V1.0  
15 - */  
16 -public interface EmbeddingsMapper {  
17 -  
18 -}  
@@ -26,6 +26,4 @@ public interface PgVectorMapper { @@ -26,6 +26,4 @@ public interface PgVectorMapper {
26 26
27 int deleteByIds(@Param("ids") List<String> ids); 27 int deleteByIds(@Param("ids") List<String> ids);
28 28
29 - List<Embeddings> similaritySearch(@Param("vector") float[] vector,  
30 - @Param("limit") int limit);  
31 } 29 }
@@ -64,7 +64,5 @@ @@ -64,7 +64,5 @@
64 </foreach> 64 </foreach>
65 </delete> 65 </delete>
66 66
67 - <select id="similaritySearch" resultMap="embeddingsResultMap">  
68 67
69 - </select>  
70 </mapper> 68 </mapper>
1 -//package org.jeecg.modules.airag.app.utils;  
2 -//  
3 -//import java.sql.*;  
4 -//import java.util.ArrayList;  
5 -//import java.util.HashMap;  
6 -//import java.util.List;  
7 -//import java.util.Map;  
8 -//  
9 -//public class PureJdbcVectorQuery {  
10 -//  
11 -// // PostgreSQL连接参数  
12 -// private static final String URL = "jdbc:postgresql://192.168.100.103:5432/postgres";  
13 -// private static final String USER = "postgres";  
14 -// private static final String PASSWORD = "postgres";  
15 -//  
16 -// public static List<Map<String, Object>> queryVectors() {  
17 -// List<Map<String, Object>> results = new ArrayList<>();  
18 -//  
19 -// try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);  
20 -// PreparedStatement stmt = conn.prepareStatement("SELECT * FROM embeddings");  
21 -// ResultSet rs = stmt.executeQuery()) {  
22 -//  
23 -// ResultSetMetaData metaData = rs.getMetaData();  
24 -// int columnCount = metaData.getColumnCount();  
25 -//  
26 -// while (rs.next()) {  
27 -// Map<String, Object> row = new HashMap<>();  
28 -// for (int i = 1; i <= columnCount; i++) {  
29 -// String columnName = metaData.getColumnName(i);  
30 -// Object value = "embedding".equals(columnName)  
31 -// ? rs.getBytes(i) // 向量字段特殊处理  
32 -// : rs.getObject(i);  
33 -// row.put(columnName, value);  
34 -// }  
35 -// results.add(row);  
36 -// }  
37 -// } catch (SQLException e) {  
38 -// e.printStackTrace();  
39 -// }  
40 -// return results;  
41 -// }  
42 -//  
43 -//  
44 -// public static void main(String[] args) {  
45 -// List<Map<String, Object>> maps = queryVectors();  
46 -// for (Map<String, Object> map : maps) {  
47 -// System.out.println(map);  
48 -// }  
49 -// }  
50 -//}