GO源从零开始的RAG系统,追求极致的简单和强大,不超过1万行代码,无需安装,双击启动.
GO源码从零开始的RAG系统,追求极致的简单和强大,不超过1万行代码,无需安装,双击启动.介绍是从零开始的RAG系统,追求极致的简单和强大,不超过1万行代码,无需安装,双击启动.使用FTS5实现BM25全文检索,使用Vec实现向量检索,实现了 MarkdownConverter、DocumentSplitter、OpenAIDocumentEmbedder、SQLiteVecDocumentStore、OpenAITextEmbedder、VecEmbeddingRetriever、FtsKeywordRetriever、DocumentChunkReranker、PromptBuilder、OpenAIChatMemory、OpenAIChatGenerator、ChatMessageLogStore、Pipeline等组件,支持流水线设置和扩展.AI平台默认是 Gitee AI,每日有100次的免费调用额度
[*]OpenAITextEmbedder 默认使用 bge-m3 模型
[*]DocumentChunkReranker 默认使用 bge-reranker-v2-m3 模型
[*]OpenAIChatGenerator 默认使用 DeepSeek-V3 模型
开发环境fts5使用了 https://github.com/wangfenjin/simple 作为FTS5的全文检索扩展,编译好的libsimple文件放到 datadir/extensions 目录下,如果启动报错连不上数据库,请检查libsimple文件是否正确,如果需要重新编译libsimple,请参考 https://github.com/wangfenjin/simple.默认端口738,后台管理地址 http://127.0.0.1:738/admin/login
需要先解压datadir/dict.zip
运行 go run --tags "fts5" .
打包: go build --tags "fts5" -ldflags "-w -s"开发环境需要配置CGO编译,设置set CGO_ENABLED=1,下载mingw64和cmake,并把bin配置到环境变量,注意把mingw64/bin/mingw32-make.exe 改名为 make.exe
注意修改vscode的launch.json,增加 ,"buildFlags": "--tags=fts5" 用于调试fts5
test需要手动测试:go test -v -count=1 -timeout 30s --tags "fts5" -run ^TestVecQuery$ gitee.com//
打包: go build --tags "fts5" -ldflags "-w -s"
重新编译simple时,建议使用https://github.com/wangfenjin/simple编译好的.
注意修改widnows编译脚本,去掉 mingw64 编译依赖的libgcc_s_seh-1.dll和libstdc++-6.dll,同时关闭BUILD_TEST_EXAMPLE,有冲突rmdir /q /s buildmkdir build && cd buildcmake .. -G "Unix Makefiles" -DBUILD_TEST_EXAMPLE=OFF -DCMAKE_INSTALL_PREFIX=release -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic"make && make install
sqlite_vec参考:https://alexgarcia.xyz/sqlite-vec/compiling.html
把mingw64/bin/gcc.exe 复制为 cc.exe#git clone https://github.com/asg017/sqlite-vec.gitgit clone https://gitee.com//sqlite-vec.git###windows上用git bash 打开目录并执行命令,cmd不支持cd sqlite-vec./scripts/vendor.shmake loadable## dist/vec0.dll
后台管理支持英文后台管理目前支持中英双语,支持扩展其他语言,语言文件在 datadir/locales,初始化安装默认使用的中文(zh-CN),如果需要英文,可以在安装前把datadir/install_config.json中的"locale":"zh-CN"修改为"locale":"en-US".也可以在安装成功之后,在设置中修改语言为English,并重启生效.表结构ID默认使用时间戳(23位)+随机数(9位),全局唯一.
建表语句datadir/.sql配置(表名:config)安装时会读取datadir/install_config.json
columnName类型说明备注
idstring主键_config
basePathstring基础路径默认 /
jwtSecretstringjwt密钥随机生成
jwttokenKeystringjwt的key默认 jwttoken
serverPortstringIP:端口默认 :738
timeoutintjwt超时时间秒默认 7200
maxRequestBodySizeint最大请求默认 20M
localestring语言包默认 zh-CN,en-US
proxystringhttp代理地址
createTimestring创建时间2006-01-02 15:04:05
updateTimestring更新时间2006-01-02 15:04:05
createUserstring创建人初始化 system
sortNoint排序倒序
statusint状态禁用(0),可用(1)
用户(表名:user)后台只有一个用户.
columnName类型说明备注
idstring主键_admin
accountstring登录名称默认admin
passWordstring密码-
userNamestring说明-
createTimestring创建时间2006-01-02 15:04:05
updateTimestring更新时间2006-01-02 15:04:05
createUserstring创建人初始化 system
sortNoint排序倒序
statusint状态禁用(0),可用(1)
站点信息(表名:site)站点的信息,例如 title,logo,keywords,description等
columnName类型说明备注
idstring主键_site
titlestring站点名称-
keywordstring关键字-
descriptionstring站点描述-
themestring默认主题默认使用default
themePCstringPC主题先从cookie获取,如果没有从Header头取值,写入cookie,默认使用default
themeWAPstring手机主题先从cookie获取,如果没有从Header头取值,写入cookie,默认使用default
themeWXstring微信主题先从cookie获取,如果没有从Header头取值,写入cookie,默认使用default
logostringlogo-
faviconstringFavicon-
createTimestring创建时间2006-01-02 15:04:05
updateTimestring更新时间2006-01-02 15:04:05
createUserstring创建人初始化 system
sortNoint排序倒序
statusint状态禁用(0),可用(1)
知识库(表名:knowledgeBase)
columnName类型说明备注
idstring主键URL路径,用/隔开,例如/web/
namestring知识库名称-
pidstring父知识库ID父知识库ID
knowledgeBaseTypeint知识库类型-
createTimestring创建时间2006-01-02 15:04:05
updateTimestring更新时间2006-01-02 15:04:05
createUserstring创建人初始化 system
sortNoint排序倒序
statusint状态禁用(0),可用(1)
文档(表名:document)
columnName类型说明是否分词备注
idstring主键否URL路径,用/隔开,例如/web/nginx-use-hsts
namestring文档名称否-
knowledgeBaseIDstring知识库ID否-
knowledgeBaseNamestring知识库名称否-
tocstring目录否-
summarystring摘要否-
markdownstringMarkdown内容否-
filePathstring文件路径否
fileSizeint文件大小否
fileExtstring文件扩展名否
createTimestring创建时间-2006-01-02 15:04:05
updateTimestring更新时间-2006-01-02 15:04:05
createUserstring创建人-初始化 system
sortNoint排序-倒序
statusint状态-禁用(0),可用(1),处理中(2),处理失败(3)
文档拆分(表名:document_chunk)
columnName类型说明是否分词备注
idstring主键否-
documentIDstring文档ID否-
knowledgeBaseIDstring知识库ID否-
knowledgeBaseNamestring知识库名称否-
markdownstringMarkdown内容是使用 jieba 分词器
createTimestring创建时间-2006-01-02 15:04:05
updateTimestring更新时间-2006-01-02 15:04:05
createUserstring创建人-初始化 system
sortNoint排序-倒序
statusint状态-禁用(0),可用(1),处理中(2),处理失败(3)
组件(表名:component)
columnName类型说明是否分词备注
idstring主键否-
componentTypestring组件类型否-
parameterstring组件参数否-
createTimestring创建时间-2006-01-02 15:04:05
updateTimestring更新时间-2006-01-02 15:04:05
createUserstring创建人-初始化 system
sortNoint排序-倒序
statusint状态-禁用(0),可用(1)
智能体(表名:agent)
columnName类型说明是否分词备注
idstring主键否-
namestring智能体名称否-
knowledgeBaseIDstring知识库ID否-
pipelineIDstring流水线ID否-
defaultReplystring默认回复否-
agentTypeint智能体类型否-
agentPromptstring智能体提示词否-
avatarstring智能体头像否-
welcomestring欢迎语否-
toolsstring调用的函数否-
memoryLengthint上下文记忆长度否-
createTimestring创建时间-2006-01-02 15:04:05
updateTimestring更新时间-2006-01-02 15:04:05
createUserstring创建人-初始化 system
sortNoint排序-倒序
statusint状态-禁用(0),可用(1)
聊天室(表名:chat_room)
columnName类型说明是否分词备注
idstring主键否-
namestring名称否-
agentIDstring智能体ID否-
pipelineIDstring流水线ID否-
knowledgeBaseIDstring知识库ID否-
userIDstring用户ID否-
createTimestring创建时间-2006-01-02 15:04:05
消息日志(表名:message_log)
columnName类型说明是否分词备注
idstring主键否-
agentIDstring智能体ID否-
roomIDstring聊天室ID否-
pipelineIDstring流水线ID否-
knowledgeBaseIDstring知识库ID否-
userMessagestring用户的消息否-
aiMessagestringAI回复的消息否-
userIDstring用户ID否-
createTimestring创建时间-2006-01-02 15:04:05
static/image/hrline/1.gif
链接:https://pan.quark.cn/s/745671dd5758
提取码下载:
页:
[1]