-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilSQLite_test.go
155 lines (140 loc) · 4.99 KB
/
utilSQLite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) 2025 minRAG Authors.
//
// This file is part of minRAG.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses>.
package main
import (
"context"
"fmt"
"testing"
"gitee.com/chunanyong/zorm"
)
func TestVecLikeQuery(t *testing.T) {
finder := zorm.NewSelectFinder(tableVecDocumentChunkName).Append("WHERE knowledgeBaseID like ? LIMIT 5", "%")
list, _ := zorm.QueryMap(context.Background(), finder, nil)
fmt.Println(len(list))
fmt.Println(list)
}
func TestVecQuery(t *testing.T) {
ctx := context.Background()
embedder := componentMap["OpenAITextEmbedder"]
input := map[string]interface{}{"query": "I am a technical developer from China, primarily using Java, Go, and Python as my development languages."}
err := embedder.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
//需要使用bge-m3模型进行embedding
embedding := input["embedding"].([]float64)
query, _ := vecSerializeFloat64(embedding)
finder := zorm.NewSelectFinder(tableVecDocumentChunkName, "rowid,distance as score,*").Append("WHERE embedding MATCH ? ORDER BY score LIMIT 5", query)
datas := make([]DocumentChunk, 0)
zorm.Query(ctx, finder, &datas, nil)
for i := 0; i < len(datas); i++ {
data := datas[i]
fmt.Println(data.DocumentID, data.Score)
}
}
func TestDocumentSplitter(t *testing.T) {
ctx := context.Background()
documentSplitter := componentMap["DocumentSplitter"]
input := make(map[string]interface{}, 0)
input["document"] = &Document{Markdown: "我是中国人,我爱中国。圣诞节,了大家安康金发傲娇考虑实际得分拉萨放假啊十六分是。1。2。3。"}
err := documentSplitter.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
ds := input["documentChunks"]
documentChunks := ds.([]DocumentChunk)
for i := 0; i < len(documentChunks); i++ {
documentChunk := documentChunks[i]
fmt.Println(documentChunk.Markdown)
}
}
func TestFtsKeywordRetriever(t *testing.T) {
ctx := context.Background()
ftsKeywordRetriever := componentMap["FtsKeywordRetriever"]
input := make(map[string]interface{}, 0)
input["query"] = "马斯克"
err := ftsKeywordRetriever.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
ds := input["documentChunks"]
documentChunks := ds.([]DocumentChunk)
for i := 0; i < len(documentChunks); i++ {
documentChunk := documentChunks[i]
fmt.Println(documentChunk)
}
}
func TestDocumentChunkReranker(t *testing.T) {
ctx := context.Background()
documentChunkReranker := componentMap["DocumentChunkReranker"]
input := make(map[string]interface{}, 0)
input["query"] = "你在哪里?"
documentChunks := make([]DocumentChunk, 3)
documentChunks[0] = DocumentChunk{Markdown: "我在郑州"}
documentChunks[1] = DocumentChunk{Markdown: "今天晴天"}
documentChunks[2] = DocumentChunk{Markdown: "我明天去旅游"}
input["documentChunks"] = documentChunks
err := documentChunkReranker.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
ds := input["documentChunks"]
documentChunks = ds.([]DocumentChunk)
for i := 0; i < len(documentChunks); i++ {
documentChunk := documentChunks[i]
fmt.Println(documentChunk)
}
}
func TestPromptBuilder(t *testing.T) {
ctx := context.Background()
promptBuilder := componentMap["PromptBuilder"]
input := make(map[string]interface{}, 0)
input["query"] = "你在哪里?"
documentChunks := make([]DocumentChunk, 3)
documentChunks[0] = DocumentChunk{Markdown: "我在郑州"}
documentChunks[1] = DocumentChunk{Markdown: "今天晴天"}
documentChunks[2] = DocumentChunk{Markdown: "我明天去旅游"}
input["documentChunks"] = documentChunks
err := promptBuilder.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
fmt.Println(input["prompt"])
openAIChatMemory := componentMap["OpenAIChatMemory"]
openAIChatMemory.Run(ctx, input)
openAIChatGenerator := componentMap["OpenAIChatGenerator"]
openAIChatGenerator.Run(ctx, input)
choice := input["choice"]
fmt.Println(choice)
}
func TestPipline(t *testing.T) {
ctx := context.Background()
defaultPipline := componentMap["default"]
input := make(map[string]interface{}, 0)
input["query"] = "你在哪里?"
documentChunks := make([]DocumentChunk, 3)
documentChunks[0] = DocumentChunk{Markdown: "我在郑州"}
documentChunks[1] = DocumentChunk{Markdown: "今天晴天"}
documentChunks[2] = DocumentChunk{Markdown: "我明天去旅游"}
input["documentChunks"] = documentChunks
err := defaultPipline.Run(ctx, input)
if err != nil {
t.Fatal(err)
}
choice := input["choice"]
fmt.Println(choice)
}