@@ -40,12 +40,18 @@ public static void main(String[] args) {
40
40
quickStart ();
41
41
fitStart ();
42
42
userDict ();
43
+ cutAll ();
44
+ stopWord ();
43
45
}
44
46
public static void quickStart () {
45
47
SparseVectorBm25Encoder encoder = SparseVectorBm25Encoder .getBm25Encoder ("zh" );
46
48
List <String > texts = Arrays .asList ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ,
47
49
"作为专门为处理输入向量查询而设计的数据库,它支持多种索引类型和相似度计算方法,单索引支持10亿级向量规模,高达百万级 QPS 及毫秒级查询延迟。" ,
48
50
"不仅能为大模型提供外部知识库,提高大模型回答的准确性,还可广泛应用于推荐系统、NLP 服务、计算机视觉、智能客服等 AI 领域。" );
51
+ System .out .println ("cut all:" + encoder .getTokenizer ().getCutAll ());
52
+ System .out .println ("encode texts: " + encoder .encodeTexts (texts ));
53
+ encoder .setCutAll (true );
54
+ System .out .println ("cut all:" + encoder .getTokenizer ().getCutAll ());
49
55
System .out .println ("encode texts: " + encoder .encodeTexts (texts ));
50
56
51
57
System .out .println ("encode multiple quires: " + encoder .encodeQueries (Arrays .asList ("什么是腾讯云向量数据库?" , "腾讯云向量数据库有什么优势?" , "腾讯云向量数据库能做些什么?" )));
@@ -63,7 +69,6 @@ public static void fitStart() {
63
69
}
64
70
public static void userDict (){
65
71
JiebaTokenizer tokenizer = new JiebaTokenizer ();
66
- tokenizer .setEnableStopWords (true );
67
72
String projectPath = example .class .getProtectionDomain ().getCodeSource ().getLocation ().getPath ();
68
73
69
74
// 创建一个 File 对象来表示工程路径
@@ -74,6 +79,7 @@ public static void userDict(){
74
79
String path = projectAbsolutePath .replace ("target/classes" , "" ) +
75
80
"src/main/resources/data/user_dict/userdict_example.txt" ;
76
81
System .out .println (tokenizer .tokenize ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ));
82
+
77
83
tokenizer .loadDict (path );
78
84
System .out .println (tokenizer .tokenize ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ));
79
85
@@ -83,4 +89,34 @@ public static void userDict(){
83
89
System .out .println (tokenizer .tokenize ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ));
84
90
85
91
}
92
+
93
+
94
+ public static void cutAll (){
95
+ SparseVectorBm25Encoder encoder = SparseVectorBm25Encoder .getBm25Encoder ("zh" );
96
+ System .out .println ("cut all : " + encoder .getTokenizer ().getCutAll ());
97
+ System .out .println (encoder .getTokenizer ().tokenize ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ));
98
+
99
+ encoder .setCutAll (true );
100
+ System .out .println ("cut all: " + encoder .getTokenizer ().getCutAll ());
101
+ System .out .println (encoder .getTokenizer ().tokenize ("腾讯云向量数据库(Tencent Cloud VectorDB)是一款全托管的自研企业级分布式数据库服务,专用于存储、索引、检索、管理由深度神经网络或其他机器学习模型生成的大量多维嵌入向量。" ));
102
+ }
103
+
104
+ public static void stopWord (){
105
+ SparseVectorBm25Encoder encoder = SparseVectorBm25Encoder .getBm25Encoder ("zh" );
106
+ System .out .println (encoder .getTokenizer ().tokenize ("什么是腾讯云向量数据库。" ));
107
+
108
+ encoder .setEnableStopWords (false );
109
+ System .out .println (encoder .getTokenizer ().tokenize ("什么是腾讯云向量数据库。" ));
110
+ String projectPath = example .class .getProtectionDomain ().getCodeSource ().getLocation ().getPath ();
111
+
112
+ // 创建一个 File 对象来表示工程路径
113
+ File projectDirectory = new File (projectPath );
114
+ String projectAbsolutePath = projectDirectory .getAbsolutePath ();
115
+ String path = projectAbsolutePath .replace ("target/classes" , "" ) +
116
+ "src/main/resources/data/user_stopwords.txt" ;
117
+ encoder .setStopWords (path );
118
+ encoder .setEnableStopWords (true );
119
+ System .out .println (encoder .getTokenizer ().tokenize ("什么是腾讯云向量数据库。" ));
120
+
121
+ }
86
122
}
0 commit comments