PostgreSQL 向量
pgvector 插件和语义向量
pgvector 是一个用于 PostgreSQL 的扩展,允许存储、索引和查询向量嵌入。向量嵌入是数据的数值表示,通常用于机器学习和自然语言处理,以在低维空间中表示文本、图像或其他高维数据。
语义向量 是一种捕捉词语、短语或句子意义的向量嵌入。这些向量使用像 word2vec、GloVe 或基于 Transformer 的模型(如 BERT)创建。然后,这些向量可以用来根据其语义内容测量不同文本片段之间的相似性。
测试 pgvector 插件
1.安装了 pgvector 插件.
2.启用 pgvector 插件.
CREATE EXTENSION vector;
- 如果命令执行成功,您应该会看到一条消息说明扩展已创建。
- 为了验证扩展是否成功启用,您可以运行以下查询:
SELECT * FROM pg_extension WHERE extname = 'vector';
如果返回一行结果,说明扩展已成功启用。 5. 您还可以尝试创建一个使用 vector 类型的表来进一步确认:
CREATE TABLE vector_test (id serial PRIMARY KEY, v vector(3));
如果这个命令执行成功,说明 vector 类型现在可用了。
余弦相似度
什么是余弦相似度 余弦相似度用来计算两个向量之间的相似度.余弦相似度的值越大,两个向量越相似。具体来说:
- 余弦相似度为 1:表示两个向量完全相同。
- 余弦相似度为 0:表示两个向量正交(没有相似性)。
- 余弦相似度为-1:表示两个向量完全相反。
余弦相似度越大(越接近 1),表示两个向量越相似;越小(越接近-1),表示两个向量越不相似或相反。
余弦相似度公式
- 余弦相似度的定义:
[ \text{cosine_similarity} = \frac{\vec{A} \cdot \vec{B}}{|\vec{A}| |\vec{B}|} ]
其中,(\vec{A} \cdot \vec{B}) 是向量的点积,(|\vec{A}|) 和 (|\vec{B}|) 分别是向量 (\vec{A}) 和 (\vec{B}) 的范数。
- 值域和含义:
- 1:完全相似
- 0:完全不相似(正交)
- -1:完全相反
因此,余弦相似度越接近 1,表示两个向量越相似,而不是越小越相似。
使用 PostgreSQL 和 pgvector
扩展来计算两个嵌入向量的余弦相似度
在 PostgreSQL 中,使用 pgvector
扩展可以方便地进行向量存储和相似度计算。以下是一个详细的步骤指南,展示如何使用 PostgreSQL 和 pgvector
扩展来计算两个嵌入向量的余弦相似度。
1. 安装 pgvector
扩展
首先,确保已安装 pgvector
扩展。如果尚未安装,可以在 PostgreSQL 中运行以下命令:
CREATE EXTENSION IF NOT EXISTS vector;
2. 创建表并存储向量
创建一个表来存储向量:
CREATE TABLE embeddings (
id serial PRIMARY KEY,
embedding vector(3) -- 这里假设向量的维度是3
);
然后插入一些向量数据:
INSERT INTO embeddings (embedding) VALUES
('[1, 2, 3]'),
('[4, 5, 6]');
3. 计算向量距离
使用 pgvector
提供的函数来计算向量距离。以下是一个示例查询,计算两个向量之间的向量距离:
SELECT
id,
embedding,
(embedding <=> '[1, 2, 3]') AS cosine_similarity -- 计算与向量 [1, 2, 3] 的余弦相似度
FROM
embeddings
ORDER BY
cosine_similarity;
4.计算余弦相似度
假设我们有两个嵌入向量,并希望计算它们之间的余弦相似度:
WITH input_vector AS (
SELECT '[1, 2, 3]'::vector(3) AS embedding
)
SELECT
e.id,
e.embedding,
(1 - (e.embedding <=> iv.embedding)) AS cosine_similarity -- 计算余弦相似度
FROM
embeddings e,
input_vector iv
ORDER BY
cosine_similarity DESC;
在这个示例中:
WITH input_vector AS (...)
子查询定义了我们要比较的输入向量。e.embedding <=> iv.embedding
计算向量之间的距离,这里使用的是pgvector
的相似度操作符。1 - (e.embedding <=> iv.embedding)
计算余弦相似度,因为pgvector
提供的相似度值越大,表示距离越小,所以这里用1 -
来转换为余弦相似度。
在使用 pgvector
扩展时, <=>
操作符确实计算的是向量之间的余弦距离,而不是直接计算余弦相似度。因此,余弦相似度可以通过 1 减去余弦距离来得到。
professors 向量化和查询 示例
1.修改表结构添加向量字段
我们将为 name
、description
和 remark
添加三个向量字段,每个字段的维度为 1536,并添加一个字段记录是否已经完成向量。
CREATE TABLE rumi_sjsu_professors(
id BIGINT NOT NULL,
name VARCHAR(256),
department VARCHAR(256),
job_title VARCHAR(256),
email VARCHAR(256),
description TEXT,
files JSON,
remark VARCHAR(256),
name_vector VECTOR(1536),
description_vector VECTOR(1536),
remark_vector VECTOR(1536),
vectors_completed BOOLEAN DEFAULT FALSE,
creator VARCHAR(64) DEFAULT '',
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updater VARCHAR(64) DEFAULT '',
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted SMALLINT DEFAULT 0,
tenant_id BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
2. 数据插入示例
以下是三个包含向量数据的示例插入语句:
-- 示例1
INSERT INTO rumi_sjsu_professors (
id, name, department, job_title, email, description, files, remark, name_vector, description_vector, remark_vector, vectors_completed
) VALUES (
1,
'Dr. John Doe',
'Computer Science',
'Professor',
'jdoe@sjsu.edu',
'Expert in artificial intelligence and machine learning.',
'{"resume": "link_to_resume.pdf"}',
'Well-known researcher',
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
TRUE
);
-- 示例2
INSERT INTO rumi_sjsu_professors (
id, name, department, job_title, email, description, files, remark, name_vector, description_vector, remark_vector, vectors_completed
) VALUES (
2,
'Dr. Jane Smith',
'Mathematics',
'Associate Professor',
'jsmith@sjsu.edu',
'Specializes in algebraic topology and number theory.',
'{"cv": "link_to_cv.pdf"}',
'Renowned academic',
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
TRUE
);
-- 示例3
INSERT INTO rumi_sjsu_professors (
id, name, department, job_title, email, description, files, remark, name_vector, description_vector, remark_vector, vectors_completed
) VALUES (
3,
'Dr. Emily Zhang',
'Physics',
'Assistant Professor',
'ezhang@sjsu.edu',
'Researcher in quantum mechanics and particle physics.',
'{"portfolio": "link_to_portfolio.pdf"}',
'Emerging scientist',
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
'[0.1, 0.2, 0.3, ...]', -- 1536维向量
TRUE
);
3. 计算相似度的 SQL 查询
以下 SQL 查询计算输入向量与 name_vector
、description_vector
和 remark_vector
字段的相似度,并检索出相似度最高的三条记录。
SELECT
id,
name,
department,
job_title,
email,
description,
remark,
(1-(name_vector <=> input_vector)) AS name_similarity,
(1-(description_vector <=> input_vector)) AS description_similarity,
(1-(remark_vector <=> input_vector)) AS remark_similarity
FROM
rumi_sjsu_professors,
LATERAL (
VALUES (
ARRAY[0.1, 0.2, 0.3, ...]::VECTOR(1536) -- 替换为实际输入向量
)
) AS input(input_vector)
ORDER BY
GREATEST(
name_vector <=> input_vector,
description_vector <=> input_vector,
remark_vector <=> input_vector
) DESC
LIMIT 3;
增加 where 查询 在 SQL 中,不能直接在 WHERE 子句中引用 SELECT 列表中的别名(如 name_similarity、description_similarity、remark_similarity),因为 WHERE 子句在 SELECT 子句之前执行。因此,你需要在 WHERE 子句中重新计算这些相似度值。
SELECT
id,
name,
department,
job_title,
email,
description,
remark,
(1 - (name_vector <=> input_vector)) AS name_similarity,
(1 - (description_vector <=> input_vector)) AS description_similarity,
(1 - (remark_vector <=> input_vector)) AS remark_similarity
FROM
rumi_sjsu_professors,
LATERAL (
VALUES (
ARRAY[0.1, 0.2, 0.3, ...]::VECTOR(1536) -- 替换为实际输入向量
)
) AS input(input_vector)
WHERE
(1 - (name_vector <=> input_vector)) > 0.9
OR (1 - (description_vector <=> input_vector)) > 0.9
OR (1 - (remark_vector <=> input_vector)) > 0.9
ORDER BY
GREATEST(
1 - (name_vector <=> input_vector),
1 - (description_vector <=> input_vector),
1 - (remark_vector <=> input_vector)
) DESC
LIMIT 3;
4.优化建议
- 索引: 在向量字段上创建索引以提高相似度搜索的性能。
- 批处理: 如果向量计算较为耗时,考虑使用批处理来更新向量字段。
- 缓存: 对于频繁查询的向量使用缓存以减少计算时间。
- 监控: 设置监控以跟踪查询性能并进行优化。
使用代码操作向量数据库
1. 使用代码插入数据
如何使用代码代替上面的 INSERT INTO rumi_sjsu_professors 语句
import java.sql.SQLException;
import java.util.Arrays;
import org.junit.Test;
import org.postgresql.util.PGobject;
import com.litongjava.jfinal.plugin.activerecord.Db;
import com.litongjava.jfinal.plugin.activerecord.Record;
import com.litongjava.open.chat.config.DbConfig;
import com.litongjava.openai.client.OpenAiClient;
import com.litongjava.openai.constants.OpenAiModels;
import com.litongjava.openai.embedding.EmbeddingRequestVo;
import com.litongjava.openai.embedding.EmbeddingResponseVo;
import com.litongjava.tio.utils.environment.EnvUtils;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SjsuProfessorsTest {
@Test
public void testInsertDrEmilyZhang() {
EnvUtils.load();
new DbConfig().config();
int id = 3;
String name = "Dr. Emily Zhang";
String description = "Researcher in quantum mechanics and particle physics.";
String remark = "Emerging scientist";
Record record = new Record();
record.set("id", id).set("name", name).set("department", "Physics").set("job_title", "Associate Professor")
.set("email", "ezhang@sjsu.edu").set("description", description).set("remark", remark);
setNameVector(name, record);
setDescriptionVector(description, record);
setRemarkVector(remark, record);
record.setTableName("rumi_sjsu_professors");
boolean save = Db.save(record);
if (save) {
log.info("success");
}
}
@Test
public void testInsertDrJaneSmith() {
EnvUtils.load();
new DbConfig().config();
int id = 2;
String name = "Dr. Jane Smith";
String description = "Specializes in algebraic topology and number theory.";
String remark = "Renowned academic";
Record record = new Record();
record.set("id", id).set("name", name).set("department", "Mathematics").set("job_title", "Associate Professor")
.set("email", "jsmith@sjsu.edu").set("description", description).set("remark", remark);
setNameVector(name, record);
setDescriptionVector(description, record);
setRemarkVector(remark, record);
record.setTableName("rumi_sjsu_professors");
boolean save = Db.save(record);
if (save) {
log.info("success");
}
}
@Test
public void testInsertByRecord() {
EnvUtils.load();
new DbConfig().config();
String name = "Dr. John Doe";
String description = "Expert in artificial intelligence and machine learning.";
String remark = "Well-known researcher";
Record record = new Record();
record.set("id", 1).set("name", name).set("department", "Computer Science").set("job_title", "Professor")
.set("email", "jdoe@sjsu.edu").set("description", description).set("remark", remark);
setNameVector(name, record);
setDescriptionVector(description, record);
setRemarkVector(remark, record);
record.setTableName("rumi_sjsu_professors");
boolean save = Db.save(record);
if (save) {
log.info("success");
}
}
private void setRemarkVector(String description, Record record) {
PGobject nameVector = getPgVector(description);
record.set("remark_vector", nameVector);
}
private void setDescriptionVector(String description, Record record) {
PGobject nameVector = getPgVector(description);
record.set("description_vector", nameVector);
}
private void setNameVector(String name, Record record) {
PGobject nameVector = getPgVector(name);
record.set("name_vector", nameVector);
}
private PGobject getPgVector(String description) {
EmbeddingRequestVo reoVo = new EmbeddingRequestVo(description, OpenAiModels.text_embedding_3_small);
EmbeddingResponseVo respVo = OpenAiClient.embeddings(reoVo);
Float[] embedding = respVo.getData().get(0).getEmbedding();
String vectorString = Arrays.toString(embedding);
// 使用PGobject来设置vector类型
PGobject nameVector = new PGobject();
nameVector.setType("vector");
try {
nameVector.setValue(vectorString);
} catch (SQLException e) {
e.printStackTrace();
}
return nameVector;
}
}
插入其他的数据示例省略
2.查询数据
输出结果如下,为了方便展示,我省略了 vector 的 value 部分
import org.junit.Test;
import com.litongjava.jfinal.plugin.activerecord.Db;
import com.litongjava.jfinal.plugin.activerecord.Record;
import com.litongjava.open.chat.config.DbConfig;
import com.litongjava.tio.utils.environment.EnvUtils;
import com.litongjava.tio.utils.json.JsonUtils;
public class SjsuProfessorsQueryTest {
@Test
public void testQuery() {
EnvUtils.load();
new DbConfig().config();
int id = 3;
Record record = Db.findById("rumi_sjsu_professors", "id", id);
String json = JsonUtils.toJson(record.toMap());
System.out.println(json);
}
}
{
"id": 3,
"name": "Dr. Emily Zhang",
"department": "Physics",
"job_title": "Associate Professor",
"email": "ezhang@sjsu.edu",
"description": "Researcher in quantum mechanics and particle physics.",
"remark": "Emerging scientist",
"name_vector": [],
"description_vector": [],
"remark_vector": {
"value": "[]",
"type": "vector",
"null": true
},
"vectors_completed": false,
"creator": "",
"create_time": "2024-07-03 23:29:44",
"updater": "",
"update_time": "2024-07-03 23:29:44",
"deleted": 0,
"tenant_id": 0
}
3. Java 向量查询
在 Java 中使用余弦相似度进行查询,并将输入向量传递给 SQL 查询.
- 确保 PostgreSQL 数据库已配置好 pgvector 扩展:
CREATE EXTENSION IF NOT EXISTS vector;
- 创建包含向量的表:
CREATE TABLE vector_test (
id SERIAL PRIMARY KEY,
name TEXT,
embedding VECTOR(1536)
);
- 在 Java 中构建查询并传递向量参数:
可以使用 PreparedStatement
来构建和执行查询。以下是一个示例代码,展示如何将向量传递给 SQL 查询并执行查询。
package com.litongjava.open.chat.model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import com.litongjava.open.chat.config.DbConfig;
import com.litongjava.openai.client.OpenAiClient;
import com.litongjava.openai.constants.OpenAiModels;
import com.litongjava.openai.embedding.EmbeddingRequestVo;
import com.litongjava.openai.embedding.EmbeddingResponseVo;
import com.litongjava.tio.utils.dsn.DbDSNParser;
import com.litongjava.tio.utils.dsn.JdbcInfo;
import com.litongjava.tio.utils.environment.EnvUtils;
public class VectorSearchTest {
public static void main(String[] args) throws SQLException {
// 示例输入
EnvUtils.load();
new DbConfig().config();
String question = "Jane Smith";
EmbeddingRequestVo reoVo = new EmbeddingRequestVo(question, OpenAiModels.text_embedding_3_small);
EmbeddingResponseVo respVo = OpenAiClient.embeddings(reoVo);
Float[] embedding = respVo.getData().get(0).getEmbedding();
// 转换嵌入向量为 SQL 可用的字符串
String vectorString = Arrays.toString(embedding);
String dsn = EnvUtils.get("DATABASE_DSN");
JdbcInfo jdbc = new DbDSNParser().parse(dsn);
// PostgreSQL 连接配置
String url = jdbc.getUrl();
String user = jdbc.getUser();
String password = jdbc.getPswd();
// SQL 查询
String sql = "SELECT * FROM vector_test ORDER BY embedding <=> ? LIMIT 10";
try (Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement pstmt = conn.prepareStatement(sql)) {
// 设置向量参数
pstmt.setObject(1, vectorString, java.sql.Types.OTHER);
// 执行查询
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
// 处理查询结果
int id = rs.getInt("id");
String name = rs.getString("name");
// 继续处理其他字段
System.out.println("ID: " + id + ", Name: " + name);
}
}
}
}
}
解释:
获取嵌入向量:
- 调用
OpenAiClient.embeddings
函数来获取输入问题的嵌入向量。
- 调用
转换嵌入向量:
- 将 Java 中的数组转换为 PostgreSQL 可用的
[]
格式字符串。
- 将 Java 中的数组转换为 PostgreSQL 可用的
建立数据库连接和执行查询:
- 使用
DriverManager
来建立数据库连接。 - 使用
PreparedStatement
来构建和执行查询,并传递向量参数。 - 处理查询结果。
- 使用
4. 使用 Db 工具类进行向量查询
package com.litongjava.open.chat.model;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.litongjava.jfinal.plugin.activerecord.Db;
import com.litongjava.jfinal.plugin.activerecord.Record;
import com.litongjava.jfinal.plugin.template.SqlTemplates;
import com.litongjava.open.chat.config.SqlTplsConfig;
import com.litongjava.open.chat.config.DbConfig;
import com.litongjava.openai.client.OpenAiClient;
import com.litongjava.openai.constants.OpenAiModels;
import com.litongjava.openai.embedding.EmbeddingRequestVo;
import com.litongjava.openai.embedding.EmbeddingResponseVo;
import com.litongjava.tio.utils.environment.EnvUtils;
import com.litongjava.tio.utils.json.JsonUtils;
public class SjsuProfessorsSearchTest {
@Test
public void searchTest() {
EnvUtils.load();
new DbConfig().config();
new SqlTplsConfig().config();
String question = "Jane Smith";
EmbeddingRequestVo reoVo = new EmbeddingRequestVo(question, OpenAiModels.text_embedding_3_small);
EmbeddingResponseVo respVo = OpenAiClient.embeddings(reoVo);
Float[] embedding = respVo.getData().get(0).getEmbedding();
String string = Arrays.toString(embedding);
String sql = SqlTemplates.get("professor.vector_search");
List<Record> records = Db.find(sql, string, string, string, string, string, string);
String json = JsonUtils.toJson(records);
System.out.println(json);
}
}
String sql = SqlTemplates.get("professor.vector_search"); 返回的 sql 语句如下
SELECT
id,
name,
department,
job_title,
email,
description,
remark,
(1-(name_vector <=> ?)) AS name_similarity,
(1-(description_vector <=> ?)) AS description_similarity,
(1-(remark_vector <=> ?)) AS remark_similarity
FROM
rumi_sjsu_professors
ORDER BY
GREATEST(
1-(name_vector <=> ?),
1-(description_vector <=> ?),
1-(remark_vector <=> ?)
) DESC
LIMIT 3;
5. 合并查询参数
在上面的示例中 6 个查询参数都是相同的,能否合并为一个查询参数
SELECT
id,
name,
department,
job_title,
email,
description,
remark,
(1-(name_vector <=> ?)) AS name_similarity,
(1-(description_vector <=> ?)) AS description_similarity,
(1-(remark_vector <=> ?)) AS remark_similarity
FROM
rumi_sjsu_professors,
LATERAL (
VALUES (
?::VECTOR(1536)
)
) AS input(input_vector)
ORDER BY
GREATEST(
1-(name_vector <=> ?),
1-(description_vector <=> ?),
1-(remark_vector <=> ?)
) DESC
LIMIT 3;
查询时只用传入一个参数
List<Record> records = Db.find(sql, string);
SQL 语句解释: 这个 SQL 语句是在进行向量相似度搜索。它从 rumi_sjsu_professors 表中选择数据,并计算输入向量与表中存储的向量之间的相似度。
- 选择字段包括 id, name, department, job_title, email, description, remark。
- 计算输入向量与 name_vector, description_vector, remark_vector 的相似度。
- 使用 LATERAL 子句创建一个临时的输入向量。
- 按最大相似度降序排序。
- 限制返回前 3 条结果。
<==> 运算符:
- <==> 是 PostgreSQL 中用于计算向量距离的运算符。它返回两个向量之间的余弦距离。值越小表示向量越相似。
- 1 - 余弦距离,得到的是余弦相似度
6. db 工具类存储向量 和 查询向量示例
CREATE TABLE rumi_embedding (id bigint PRIMARY KEY,t text, v vector(1536));
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.Test;
import org.postgresql.util.PGobject;
import com.litongjava.data.utils.SnowflakeIdUtils;
import com.litongjava.jfinal.plugin.activerecord.Db;
import com.litongjava.jfinal.plugin.activerecord.Record;
import com.litongjava.jfinal.plugin.utils.PgVectorUtils;
import com.litongjava.open.chat.config.DbConfig;
import com.litongjava.openai.client.OpenAiClient;
import com.litongjava.tio.utils.environment.EnvUtils;
import com.litongjava.tio.utils.json.JsonUtils;
public class VectorTest {
@Test
public void testSave() {
EnvUtils.load();
new DbConfig().config();
long id = SnowflakeIdUtils.id();
String name = "Dr. John Doe";
Float[] embeddingArray = OpenAiClient.embeddingArray(name);
PGobject pgVector = PgVectorUtils.getPgVector(Arrays.toString(embeddingArray));
Record record = new Record().set("t", name).set("v", pgVector).set("id", id).setTableName("rumi_embedding");
Db.save(record);
}
@Test
public void testQuery() {
EnvUtils.load();
new DbConfig().config();
String sql = "select * from rumi_embedding";
List<Record> records = Db.find(sql);
List<Map<String, Object>> collect = records.stream().map((e) -> e.toMap()).collect(Collectors.toList());
String json = JsonUtils.toJson(collect);
System.out.println(json);
}
}
output
[{"id":398392108312608768,"t":"Dr. John Doe","v":"[0.016610185,-0.010182072,-0.0007115674,0.030582452,0.0014376289,-0.042989362,0.0058700917,0.01898721,-0.040525373,-0.06777419,0.040989183,-0.023726765,-0.008565986,0.013827327,0.0125373565,0.024596408,-0.03901799,-0.012877966,-0.017218936,0.04638097,0.009892192,0.020436615,0.051106032,-0.07919551,-0.023915188,-0.010290778,0.044148885,-0.021436704,0.021697598,0.009848709,0.040612336,-0.008551491,0.021436704,0.0265676,-0.0185234,-0.0052613416,0.012117028,0.0107835755,0.025915368,-0.031133227,0.031423107,-0.045830198,-0.019219115,0.0039351354,0.0041380525,-0.025219653,0.011334349,-0.013030154,0.06000538,0.029669328,-0.021567151,0.008913843,0.02210343,0.050207403,-0.028161945,0.03324936,0.011885123,-0.020581556,0.027263314,-0.019711912,0.01805959,-0.015813012,-0.030553464,0.0029875867,-0.010493695,-0.008029706,-0.008326834,0.004572874,0.0045547565,-0.017436346,0.0017900156,0.0714267,-0.038641147,0.025799414,0.0041380525,-0.03264061,-0.010971999,0.027799595,-0.044177875,0.023219474,0.009587816,0.028611261,-8.7403105e-06,-0.012088041,-0.0048156492,-0.006091126,-0.027350279,-0.007957235,-0.005399035,-0.049250793,-0.0044061923,-0.0070114983,-0.053946868,0.013479469,-0.004286616,-0.0018144744,0.020581556,0.0070984624,0.025915368,-0.029205518,-0.006529571,-0.013464975,0.022552747,0.033974063,-0.0045076506,0.01630581,-0.014334619,-0.022480277,-0.02474135,0.020103252,-0.008594974,0.0055874577,-0.0011894183,-0.024929771,-0.06899169,-0.003313703,-0.009971908,0.0056309397,-0.03536549,-0.038351264,-0.032727573,0.014385348,0.026132777,-0.048613057,0.015668072,0.0238862,-0.02810397,-0.008660197,-0.08087682,-0.015842,0.04365609,-0.037539598,-0.00025726945,-0.017045006,-0.033307336,0.03640906,-0.0036615601,-0.0034423377,-0.025582004,-0.011254633,0.008573232,0.032698583,0.01335627,0.0031886918,0.043076325,-0.021567151,0.0022954957,0.02832138,0.029509893,0.040989183,-0.01669715,0.033597216,-0.01716096,0.013921538,-0.047047697,-0.011385079,0.0667886,0.026886469,-0.007051357,0.04365609,-0.0039568767,-0.013928785,0.008392056,-0.0061708433,-0.037278704,0.0728761,0.027625665,-0.073223956,-0.036525015,0.047105674,-0.010211061,0.025089206,-0.00892109,0.0059027034,-0.041539956,0.04029347,0.013146106,-0.019566972,-0.0052142357,0.009015301,0.0263212,0.04406192,0.02527763,-0.006203455,0.012247475,-0.05388889,-0.05113502,-0.0025944356,0.031915907,0.0077253305,0.045540314,-0.0009819721,0.048294187,0.023523849,-0.022291854,-0.017102983,-0.017349381,0.014523041,0.026582094,-0.02817644,-0.022393312,-0.028263405,0.032031856,-0.047801387,-0.0035800312,-0.024915278,0.01240691,0.009921179,0.037249718,-0.073513836,0.110328734,-0.0056707985,0.01691456,0.0031361508,-0.024263045,-0.03858317,-0.008508009,0.012530109,0.04452573,-0.024451468,-0.008899349,0.0394818,0.002822717,0.04287341,0.050294366,-0.00818914,0.009892192,-0.022871615,-0.00610562,-0.013805586,0.004065582,0.028437333,0.01952349,-0.026190754,-0.015450661,0.004623603,-0.005859221,-0.016958043,0.019349562,0.008747161,-0.013305541,-0.022320842,-0.009247206,0.01866834,0.007790554,-0.0058193626,-0.037713528,-0.08522503,0.013834574,0.031307153,-0.0057541393,-0.028509803,0.0740936,-0.003150645,-0.017363876,0.016334798,-0.022393312,-0.014269396,0.018030602,-0.0061780903,0.020407626,-0.008058693,-0.0018180978,0.0086746905,-0.05820812,0.028147452,0.010863293,-0.026509624,0.0077543184,0.06046919,0.011885123,0.001228371,0.023451379,0.037423644,-0.06655669,0.0072542736,0.027466232,0.025625486,-0.030350547,-0.02793004,-0.011986583,0.050120436,0.02037864,-0.015175274,-0.032843526,-0.032234773,0.02113233,0.025045725,-0.055918057,-0.002985775,0.021088848,-0.050352342,0.009841463,-0.029828763,-0.026277719,-0.024857301,0.005428023,-0.038351264,-0.01382008,0.0141317025,0.015885482,0.059657525,-0.019219115,0.040815253,-0.02810397,0.06586098,0.005217859,-0.043308232,0.017450841,-0.02137873,-0.013747609,0.0358293,0.0084427865,0.019494502,-0.00058247976,-0.036930848,-0.0013144294,0.013030154,-0.02227736,-0.006783217,-0.034437872,-0.044351805,-0.008283352,-0.02710388,-0.00449678,0.033307336,0.04530841,-0.012240228,0.038989004,-0.006337525,0.007080345,-0.027045904,-0.022915099,-0.0111024445,-0.018624859,0.02793004,-0.01913215,0.04469966,0.003782948,0.02756769,-0.035423465,0.024625396,0.0140085025,-0.023118015,0.021103341,0.013950527,0.028408345,-0.025132688,-0.013936033,0.017045006,-0.018929234,0.02495876,-0.030814357,0.0147477,-0.031568047,0.023784742,0.029234506,-0.022262866,0.0112618795,0.007834036,0.0015599225,0.023335425,0.02724882,0.07623872,0.0075296606,0.04901889,-0.048033293,-0.023770247,0.010544424,0.010609647,0.022262866,0.039568767,-0.016943548,0.069803365,-0.029741798,0.02739376,-0.056410857,0.039626744,0.01147929,0.033945072,0.01805959,0.03429293,0.046265017,-0.048294187,-0.00784853,0.016537715,0.003007516,0.022407807,-0.0054678814,-0.022610724,0.03600323,0.0023806482,0.040177517,-0.019291585,-0.0621505,-0.0030709275,-0.012153264,0.08655848,0.005598328,-0.008696432,0.04182984,-0.004333722,8.0396705e-05,0.005688916,-0.008928337,0.015189768,-0.06933955,-0.011080704,0.0077543184,-0.029770786,0.01808858,-0.07276015,0.037278704,0.048642043,-0.018943727,0.02968382,0.01791465,-0.028901143,0.01455203,-0.018552389,-0.0008773432,-0.0033372557,0.01813206,-0.0128562255,0.017146464,0.03640906,0.016131882,-0.023625307,0.04148198,-0.00037775128,0.03182894,0.058498,-0.034524836,-0.0014258525,-0.0175523,0.0053120707,-0.011783665,0.018784294,-0.033800133,0.019784383,-0.028654743,0.05116401,0.0131750945,-0.017639263,-0.008196387,0.021726586,0.010971999,0.015581108,0.020103252,-0.02066852,-0.012667803,-0.06342598,-0.021030871,0.00076818484,0.03843823,0.013385259,0.039162934,0.020335156,0.010515436,-0.01645075,0.016740631,-0.06412169,-0.013798338,0.025625486,-0.024335515,0.012327192,-0.013095377,0.027988017,-0.029408434,0.014233161,0.021103341,-0.0052033653,-0.055454247,0.021335246,-0.009239959,0.047192637,-0.02810397,0.023871707,0.026669059,0.012559097,-0.0031470214,-0.015421673,-0.013196835,0.042061742,0.0065875473,0.00838481,0.010863293,0.02985775,-0.0068448167,0.008109422,0.012356181,0.0073992144,0.032118823,-0.017465334,-0.025335606,-0.026451647,0.05156984,-0.0077398247,0.009884944,-0.058295082,0.01591447,0.016146375,-0.007551402,0.02005977,0.042554542,0.012638815,-0.020654026,0.07073098,0.020001793,0.016334798,0.0018026979,-0.0018950974,-0.0238862,-0.04368508,-0.012827237,0.005913574,0.013754857,-0.036843885,0.0064208657,0.0025636356,-0.016900066,0.005257718,-0.01774072,0.023161497,0.009109513,-0.03385811,-0.03446686,0.05510639,0.031133227,0.012196746,0.02137873,-0.012348933,0.002540083,-0.0099864025,-0.025509534,-0.0072107916,0.003618078,-0.023610814,0.007127451,0.0040184762,-0.032234773,0.06052717,0.016653668,-0.04104716,0.0074789315,0.029162036,0.027451737,0.010037132,-0.019161139,0.007892012,-0.0048228963,0.03182894,0.0146245,0.0036742424,-0.024219563,0.049801566,-0.036756918,-0.0064172423,-0.023219474,0.009537087,0.022784652,0.0078122946,-0.011834394,0.0147477,0.017595781,0.018958222,0.014095467,-0.00382643,0.0008877608,-0.018929234,-0.0005072919,-0.0008891196,-0.03901799,-0.020567061,-0.006612912,0.04197478,0.030292572,0.009442876,0.016407268,-0.02163962,-0.0066092885,0.02871272,0.004340969,0.008819631,-0.060875025,0.050497282,0.0071636857,-0.010812564,-0.015407179,-0.011812653,0.013646151,0.025524028,0.012472133,-0.0064208657,0.01616087,-0.056005023,-0.033133406,-0.034553822,0.039916623,-0.026118284,-0.026582094,0.009015301,0.00979798,0.02005977,-0.019407537,0.012269217,-0.0039786175,0.0003075457,0.006199831,-0.009399394,-0.02449495,0.010421224,-0.005420776,-0.025915368,-0.0038155594,0.013421494,-0.034727752,-0.010124097,0.002166861,0.0033300088,-0.026524117,-0.03994561,-0.007058604,0.05649782,0.01428389,0.050468292,0.00068484404,0.0027574936,-0.010805317,-0.002545518,-0.018871257,-0.0035347373,0.005319318,0.0029006223,0.056265917,0.008710926,-0.04301835,-0.014827416,-0.003551043,-0.046612877,0.0060875025,0.01737837,0.013182341,0.008696432,0.030901322,0.024219563,0.013559187,-0.024799325,-0.024335515,0.015552119,-0.016262328,-0.02566897,0.0063230307,-0.012617073,0.010348754,0.0057215276,-0.0069571454,-0.017972626,0.016943548,0.038670134,-0.0007840377,0.0009357723,-0.0021487435,0.0011631477,0.015899977,0.031046262,-0.025828402,0.026813999,-0.022190396,0.04380103,0.037713528,0.033916086,0.015421673,-0.03597424,0.018436436,0.019813372,-0.050642222,-0.049366746,0.020827955,0.012522862,-0.008377563,-0.0123416865,0.023973165,0.024306528,0.018537894,0.013928785,-0.010544424,0.008406551,-0.0056164456,0.022190396,-0.026553106,-0.033307336,-0.00020167117,0.0006187149,0.006098373,-0.0048228963,0.010029885,-0.0045004035,0.042496566,-0.109401114,-0.028132958,-0.035191562,0.014341866,0.01874081,-0.032553643,-0.01408822,0.001704863,0.055309307,0.020291675,0.022987569,-0.0013370764,0.00018378007,0.009210971,0.004601862,0.007790554,0.018639352,-0.049250793,0.0066998764,-0.023871707,-0.00012535091,-0.005859221,0.030205607,0.010645882,-0.012348933,0.0045040273,0.0061237374,0.016668161,-0.013370764,0.001764651,-0.012957684,0.007609378,0.021494681,0.019552479,-0.008225375,-0.011421314,0.007551402,-0.007319497,0.036380075,0.004667085,0.015639083,-0.023900693,-0.0039786175,-0.029263495,0.0023498484,-0.01408822,0.027538702,-0.0008094023,-0.042612515,-0.05249746,0.014667982,-0.033974063,0.011761924,-0.053077225,0.007935494,0.007949988,-0.020422122,0.055338297,-0.0046815793,0.022117926,0.019943817,0.014472312,0.020407626,0.015856495,0.007609378,0.006866558,-0.015131792,-0.0040836995,0.0304665,-0.013262059,-0.022233877,0.013406999,0.0048192726,-0.01630581,-0.024089117,0.043076325,-0.013291047,-0.038351264,0.0411921,-0.045569304,-0.02549504,0.021407716,-0.026002333,-0.007978977,0.014972357,-0.005815739,-0.020683015,0.014059232,0.034032036,-0.020856943,-0.024407987,0.012066299,0.022074442,-0.019581467,-0.0077035893,0.025726944,-0.013863562,0.010131343,-0.073571816,0.0029658456,-0.022407807,-0.018552389,0.022726675,0.0132113295,0.06470145,0.062904194,-0.0020400381,0.014508547,-0.042931385,-0.04391698,0.02427754,0.007913753,0.016508726,0.021726586,-0.036959834,-0.016508726,-0.047859363,-0.010971999,-0.041250076,-0.025147183,-0.037858468,-0.008500762,-0.012718532,0.011689454,0.030582452,-0.00074417907,0.025509534,-0.02785757,0.014733206,-0.026379177,-0.022755664,-0.0026415412,-0.010008144,-0.039307874,0.0212048,0.0022918722,0.013841821,-0.023291944,-0.024552926,-0.030263584,-0.006627406,0.020480098,-0.008015212,-0.027988017,-0.018421942,-0.016595691,-0.030350547,0.017421853,0.009884944,-0.009819721,0.00014505377,-0.05156984,-0.013769351,0.001362441,-0.010718352,0.037307695,0.026582094,-0.02971281,-0.004710567,0.0029839633,0.005159883,-0.0012220299,-0.021393223,0.0020907673,-0.012617073,0.017102983,-0.02624873,-0.014204172,0.015537625,-0.01616087,0.006141855,0.01662468,0.0131606,-0.021494681,-0.014515795,0.033162393,0.010899528,-0.05185972,-0.0040221,0.005351929,0.0024386244,-0.0010779952,-0.005783127,0.021552658,0.009580569,0.027770607,0.020755485,-0.03617716,-0.00443518,-0.027843077,0.011327103,-0.0051417653,-0.0041815345,-0.051685795,-0.02646614,-0.012798249,-0.0013905233,-0.00016396398,-0.017972626,0.018305989,0.0091385,0.03432192,-0.012225734,0.015798518,-0.013022907,-0.0056599276,-0.0037358422,-0.005601952,0.00899356,0.01820453,0.020436615,0.0074354494,-0.024147093,-0.00056255044,-0.03568436,0.013711374,0.03690186,0.025466051,-0.0026832116,0.0111024445,-0.02810397,-0.00069299695,-0.05041032,-0.013269306,0.026016826,-0.006217949,0.0032140564,-0.015726048,0.014581018,0.029220011,0.038003407,0.019552479,0.011174915,-0.019929323,0.025842898,0.03536549,0.055686153,0.010254542,0.01591447,-0.008486268,-0.0032629739,-0.013117119,-0.022697687,0.00442431,-0.008065941,0.0024386244,-0.04336621,-0.002025544,0.0071093333,0.007236156,-0.027944535,-0.0036126429,0.0030401277,0.031568047,-0.003634384,0.012638815,0.009181983,0.0068411934,0.054758534,-0.020856943,-0.033133406,-0.018900245,-0.006283172,-0.023654295,-0.014349113,-0.02793004,-0.0027158232,-0.025726944,0.0077615655,-0.031162215,0.015204262,0.006149102,0.038003407,0.024016647,-0.023538342,-0.020581556,-0.009297935,-0.008123917,0.024871796,0.020943908,-0.0001288612,-0.007594884,0.059222702,0.0032448561,0.021248283,-0.017653758,0.00087371963,0.05235252,0.019697418,-0.01079807,0.035510432,-0.014167937,-0.02878519,-0.0034513965,0.033771146,-0.004101817,0.032959476,-0.04574323,-0.010218307,-0.0103052715,0.012247475,0.017682744,-0.013385259,0.040844243,0.024509445,0.0094718635,-0.03565537,-0.03548144,-0.0519177,0.0024513067,0.0072941324,-0.038525194,-0.02964034,-0.015726048,-0.015349203,0.0399746,-0.020219205,-0.0062251957,0.007515167,-0.017972626,-0.03597424,0.046033114,-0.013856315,0.029335964,0.01784218,-0.015117298,-0.021103341,0.023364414,-0.022465782,0.047540493,0.02595885,0.0006911852,-0.0064208657,-0.013044648,-0.024002152,0.04527942,0.0049171075,0.004043841,-0.01991483,-0.017682744,-0.014276642,0.0013651587,0.0263212,0.0068846755,0.06394777,-0.023016557,-0.042032756,0.0030908568,0.033800133,-0.0037358422,0.019175632,-0.010848799,8.549227e-05,-0.001444876,0.0077253305,-0.036206145,0.021349741,0.02732129,0.0059027034,-0.0020201087,-0.011370585,-0.022683194,0.018842269,-0.011051715,-0.0039278883,0.005315694,-0.009696522,-0.022233877,-0.016943548,0.017639263,0.048033293,-0.03353924,-0.013566434,0.020798966,0.016102893,-0.0013678763,-0.007855777,0.007051357,-0.06870181,0.010544424,-0.004065582,0.023596318,0.019624949,-0.04901889,0.0044532977,-0.028017005,0.02113233,-0.0080442,-0.0063121603,-0.029335964,0.003964124,0.013464975,-0.031510074,0.0042721224,0.022683194,-0.024552926,0.032988466,0.006159973,0.0399746,0.015175274,0.01874081,-0.033017453,0.0027593053,0.0147477,0.0107473405,0.026422659,-0.00041579816,0.01342874,0.023016557,-0.034379896,0.0006880146,0.0015100992,0.019103162,0.0027719878,-0.035916265,0.047569484,-0.0333943,-0.027234327,-0.032669596,-0.025321111,0.0048663784,0.00429024,-0.0035129962,0.009790733,0.02717635,-0.016813101,-0.02878519,-5.4749024e-05,-0.032727573,-0.02878519,-0.0070332396,-0.01623334,-0.021161318,0.008754408,-0.0155666135,0.027437244,-0.017189948,-0.029944714,0.012493874,-0.023219474,-0.0014747699,-0.0024513067,-0.040148526,-0.0015218756,0.024581915,-0.00034853668,0.032959476,-0.0074282023,0.12859124,-0.01355194,-0.034061026,0.019103162,0.00011583919,-0.015494143,0.030263584,-0.016508726,0.010058873,0.015465155,-0.024060128,-0.0012981236,0.0047468026,0.016813101,0.018262507,0.011087951,-0.015624589,-0.018349472,-0.015102804,0.006544065,0.00085967855,-0.014378101,-0.013769351,-0.005025813,-0.01501584,0.0017229806,-0.028451826,-0.011559008,0.008435539,-0.0175523,-0.003775701,-0.03553942,-0.01401575,-0.006902793,-0.010174826,0.04197478,-0.0051562595,-0.021233788,0.005880962,-0.020117747,-0.014240407,-0.019653937,0.05667175,-0.022538252,0.0263212,0.009935673,-0.0131750945,0.0074499436,-0.037452634,0.007899259,-0.04333722,0.006717994,0.017494323,0.010566165,-0.006232443,-0.03322037,-0.0065875473,0.0047250614,0.054555617,0.010848799,0.008536997,-0.002233896,-0.005460635,0.017958133,0.045076504,-0.02968382,0.011957594,-0.010196567,0.05180175,0.030060668,-0.010696611,0.007855777,0.019827865,-0.02349486,0.007631119,0.0029296104,0.008623961,-0.036959834,0.012791002,0.0465549,0.036814895,0.023987658,0.014581018,-0.040061563,-0.019653937,-0.034727752,0.013725868,0.009964662,-0.0030328806,-0.030089654,-0.007899259,0.016030423,0.010058873,0.010812564,0.018074084,-0.0022755663,0.0079644825,-0.01881328,-0.004870002,-0.0041271816,0.029828763,0.036814895,0.012457639,-0.010348754,-0.012030064,-0.011740183,-0.011095198,-0.003634384,0.006152726,-0.024089117,-0.0076673543,0.023393402,0.0008877608,0.012957684,0.012776508,-0.028770696,0.022146914,0.038467217,0.022610724,0.0024331892,-0.02793004,0.024799325,-0.005736022,0.0070622275,-0.012660556,0.0003655219,0.04823621,0.054236747,0.011131433,0.01213877,0.008826879,-0.031452097,0.024857301,-0.027654653,0.031741977,0.028886648,0.0147694405,-0.011885123,0.0058193626,-0.010471954,-0.035046622,0.007638366,0.0014077349,-0.0030365041,0.021320753,0.00831234,-0.009674781,-0.014182432,-0.028045993,0.012385169,0.03261162,-0.0038228065,0.004572874,-0.0144143365,-0.02671254,-0.0132113295,-0.030901322,-0.010595153,-0.009384899,0.009616804,-0.044003945,-0.0072035445,-0.02227736,0.023610814,-0.014653488,0.015407179,-0.049366746,-0.014588265,0.00960231,-0.024335515,0.027524207,0.029669328,0.014051985,-0.0005149918,-0.013008413,-0.019755395,0.0076673543,-0.002473048,0.0008732667,0.0151607795,0.01645075,0.013291047,-0.009616804,0.04527942,-0.0077035893,0.048265196,0.019291585,-0.030263584,-0.019682925,-0.01174743,0.025161676,-0.012044558,0.0141317025,0.008138411,0.025466051,0.015479649,-0.052903295,-0.032959476,-0.021625128,-0.016349291,0.022117926,0.008102176,-0.023915188,0.035046622,0.02066852,-0.016407268,0.03524954,-0.008363069,-0.007870271,-0.050816152,0.010319766,0.024871796,0.060701095,-0.00097200746,-0.018769799,0.058613952,0.008087682,0.015146286,0.019465514,0.010471954,0.028408345,-0.02488629,0.028379356,0.024828313,-0.0053374353,0.01335627,0.025335606,0.010174826,0.016871078,0.012863472,0.006754229,0.018045096,-0.005286706,-0.00945737,0.018972715,0.02456742,-0.0088341255,-0.024828313,-0.01805959,-0.017682744,-0.009841463,-0.00013123913,-0.023770247,0.00027674582,-0.016334798,-0.015610095,0.017059501,0.0006522324,0.02098739,-0.0021867903,0.00038024242,0.0008614903,-0.021943998,-0.00014641258,-0.0054751285,-0.018494412,0.00010989437,-0.0029259871,-0.005920821,-0.0016831219,-0.026002333,-0.010979245,-0.008326834,0.026234237,0.03571335,-0.010790823,0.0063701365,0.010363248,0.028205428,0.01801611,0.00332095,0.01769724,0.013791092,-0.03617716,-0.0023897071,-0.0049642134,0.006022279,-0.018769799,0.026669059,0.0039496296,-0.015639083,-0.0075369077,0.021277271,0.034959655,0.00076727895,0.014312877,-0.010703858,0.028582273,0.009312429,0.024654385,-0.010232802,0.0051961183,0.027306797,-0.0045583798,0.012725779,0.021972984,0.024784831,-0.037771504,-0.03246668,0.016987031,-0.023755753,-0.013378011,-0.009645793,-0.036467038,0.004851884,0.0020418498,-0.029741798,0.002844458,-0.016726138,0.0012501121,-0.01616087,0.0003827336,-0.03324936,0.0067650992,0.029133048,0.044032935,0.051106032,0.023639802,0.027669149,0.011000986,0.009073277,-0.019103162,-0.0061237374,-0.0059896675,0.011732936,0.008986313,0.015885482,0.017247923,-0.0038807828,-0.031162215,0.013588175,0.012660556,0.0043518394,-0.0012165946,0.022538252,-0.01240691,-0.037771504,0.0027520584,0.009674781,0.0018842269,0.006438983,0.044931564,0.0042684986,-0.0047685434,-0.027219832,0.06046919,-0.00476492,-0.030988285,0.02617626,-0.0069571454,-0.03400305,-0.015972447,-0.021291764,0.0023570955,-0.016189858,-0.0002873899,0.048960913,0.010769081,0.014856405,0.0105879055,0.027263314,-0.021567151,-0.009181983,0.015494143,-0.04620704,-0.006482465,0.0008343139,-0.035452455,0.01187063,0.01991483,-0.019972805,-0.01891474,-0.02610379,0.01201557,0.00987045,0.049076866,0.025480546,0.010674871,0.00838481,-0.027205339,0.00046969793,-0.028524296,0.005225106,0.0028045992,0.023973165,0.019639442,-0.05759937,-0.010022637,0.029060576]"}]
7.直接查询获取向量对象 PGobject
String sql = "select v from rumi_embedding where t=?";
PGobject pGobject = Db.queryFirst(sql, text);
if (pGobject != null) {
v = pGobject.getValue();
}