最近官方推出了免费试用365天的云数据库,版本也升级到了4.3.支持了向量功能.

官方推出了活动体验AI的动手实战活动, 教程中使用了docker单机版数据库,既然有免费的云数据库,就优先使用云数据库体验一下.

1. 云环境申请

在官网的主页有有一个大大的标题,OB Cloud 365天免费试用.经过简单的操作后,大约等5分钟,就创建了一个免费的数据库实例了.

点击右上方的"三个点",依次创建用户、创建数据库、获取连接串,就可以通过公网连接云上数据库了,要谨慎添加白名单,避免资源被非法连接.

进入实例控制台后,点击"参数管理",设置ob_vector_memory_limit_percentage,启用向量检索功能,将参数值设置为30.

2. 安装python

要求的python版本大于等于3.9,小于4.0.我使用的是3.9.6.

# yum install python39

3. CLONE项目

# git clone https://github.com/oceanbase-devhub/ai-workshop-2024.git

4. 安装poetry

poetry是python的依赖和包管理工具,安装包更简单也更方便.

# python3 -m pip install poetry
# cd ~/ai-workshop-2024
# poetry install

如果下载包比较慢,可以将官方源换为阿里源

# cd ai-workshop-2024
# vi pyproject.toml
// 删除下面的源信息
[[tool.poetry.source]]
name = "PyPI"
priority = "primary" [[tool.poetry.source]]
name = "tuna"
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
priority = "supplemental"
// 添加下面的源信息
[[tool.poetry.source]]
name = "ali"
url = "https://mirrors.aliyun.com/pypi/simple/"
priority = "primary" [[tool.poetry.source]]
name = "tuna"
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
priority = "supplemental" //使配置生效
# poetry lock

接下来配置环境变量

# cp .env.example .env
# vi .env API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # 替换https://open.bigmodel.cn/usercenter/apikeys 智谱AI的API KEY
LLM_MODEL="glm-4-flash"
LLM_BASE_URL="https://open.bigmodel.cn/api/paas/v4/" # BigModel (ZhipuAI)
# LLM_BASE_URL="https://api.openai.com/v1/" # OpenAI
# LLM_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1" # Dashscope (Alibaba) HF_ENDPOINT=https://hf-mirror.com
BGE_MODEL_PATH=BAAI/bge-m3 OLLAMA_URL=
OLLAMA_TOKEN= OPENAI_API_KEY=
OPENAI_BASE_URL=
OPENAI_EMBEDDING_MODEL= DB_HOST="127.0.0.1" # 数据库的IP或域名
DB_PORT="2881" # 数据库的端口
DB_USER="root@test" # 连接的用户名
DB_NAME="test" # 连接的数据库名
DB_PASSWORD="" # 连接的密码

5. 准备BGE-M3 模型

# poetry run python utils/prepare_bgem3.py

===================================
BGEM3FlagModel loaded successfully!
===================================
出现以上的输出,就成功了.

6. 准备文档数据

从github克隆文档数据

# cd doc_repos
# git config --global http.postBuffer 16000M // 增加修改buffer大小
# git config --global core.compression -1 // 启动压缩
# git clone --single-branch --branch V4.3.3 https://github.com/oceanbase/oceanbase-doc.git --depth 1 //如果git报错,添加后面的参数
# git clone --single-branch --branch V4.3.0 https://github.com/oceanbase/ocp-doc.git
# git clone --single-branch --branch V4.3.1 https://github.com/oceanbase/odc-doc.git
# git clone --single-branch --branch V4.2.5 https://github.com/oceanbase/oms-doc.git
# git clone --single-branch --branch V2.10.0 https://github.com/oceanbase/obd-doc.git
# git clone --single-branch --branch V4.3.0 https://github.com/oceanbase/oceanbase-proxy-doc.git
# cd ..

把文档的标题转换为标准的 markdown 格式

# poetry run python convert_headings.py \
doc_repos/oceanbase-doc/zh-CN \
doc_repos/ocp-doc/zh-CN \
doc_repos/odc-doc/zh-CN \
doc_repos/oms-doc/zh-CN \
doc_repos/obd-doc/zh-CN \
doc_repos/oceanbase-proxy-doc/zh-CN

生成文档向量和元数据,等待时间比较长,并且相当看硬件性能,是个不错的性能压测工具

# poetry run python embed_docs.py --doc_base doc_repos/oceanbase-doc/zh-CN
# poetry run python embed_docs.py --doc_base doc_repos/ocp-doc/zh-CN --component ocp
# poetry run python embed_docs.py --doc_base doc_repos/odc-doc/zh-CN --component odc
# poetry run python embed_docs.py --doc_base doc_repos/oms-doc/zh-CN --component oms
# poetry run python embed_docs.py --doc_base doc_repos/obd-doc/zh-CN --component obd
# poetry run python embed_docs.py --doc_base doc_repos/oceanbase-proxy-doc/zh-CN --component odp

保存加载数据

# poetry run python utils/extract.py --output_file ~/my-data.json

加载预处理的文档数据

# poetry run python utils/load.py --source_file ~/my-data.json

7. 验证数据库和数据

进入.env配置文件中的数据库,会有一个新表,表名是corpus,表结构中的embedding列的数据类型是VECTOR(1024),这个类型就是向量类型,

mysql> desc corpus;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| id | varchar(4096) | NO | PRI | NULL | |
| embedding | VECTOR(1024) | YES | | NULL | |
| document | longtext | YES | | NULL | |
| metadata | json | YES | | NULL | |
| component_code | int(11) | NO | PRI | NULL | |
+----------------+---------------+------+-----+---------+-------+
5 rows in set (0.04 sec) mysql> select count(*) from corpus;
+----------+
| count(*) |
+----------+
| 6500 |
+----------+
1 row in set (0.05 sec)

8.启动web界面

上面的准备工作已经全部完成,接下来就是激动人心的时刻了,原神启动!!!(走错片场了),启动web界面

# poetry run streamlit run --server.runOnSave false chat_ui.py

    You can now view your Streamlit app in your browser.

	Local URL: http://localhost:8501
Network URL: http://172.xxx.xxx.xxx:8501
External URL: http://xxx.xxx.xxx.xxx:8501 # 这是您可以从浏览器访问的 URL

刚好streamlit提供服务的IP都不是对外的,修改.streamlit/config.toml,指定对外服务的IP和端口

[server]
port = 8501
enableCORS = false [browser]
serverAddress = "192.168.56.110"
gatherUsageStats = false

重启后,IP被绑定到了192.168.56.110上.

试着提问个问题

9.将tidb的文档存入数据库中

首先,在github上我找到了tidb的中文文档,把clone的文件保存到doc_repos目录中

git clone https://github.com/pingcap/docs-cn.git --depth 1

替换文档标题

poetry run python convert_headings.py doc_repos/docs-cn-release-7.6
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/tiup
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/tiproxy
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/tiflash
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/tidb-lightning
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/tidb-binlog
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/ticdc
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/templates
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/sync-diff-inspector
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/storage-engine
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/sql-statements
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/scripts
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/resources
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/releases
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/performance-schema
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/media
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/information-schema
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/functions-and-operators
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/faq
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/dm
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/develop
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/dashboard
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/config-templates
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/clinic
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/br
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/best-practices
poetry run python convert_headings.py doc_repos/docs-cn-release-7.6/benchmark

生成向量文档和元数据,保存到数据库中

poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/tiup
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/tiproxy
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/tiflash
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/tidb-lightning
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/tidb-binlog
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/ticdc
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/templates
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/sync-diff-inspector
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/storage-engine
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/sql-statements
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/scripts
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/resources
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/releases
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/performance-schema
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/media
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/information-schema
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/functions-and-operators
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/faq
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/dm
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/develop
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/dashboard
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/config-templates
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/clinic
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/br
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/best-practices
poetry run python embed_docs.py --doc_base doc_repos/docs-cn-release-7.6/benchmark

10. 效果展示

在web页面中关掉"仅限oceanbase相关问题"

先问个关于tidb的问题,使用到了下面的几个本地文档.

接下来请两位打擂台

总体来说搭建比较简单,解析向量数据需要足够的计算资源,并且等待时间比较长.


参考文档:

【创意工坊】试用 OceanBase 4.3.3 构建《黑神话:悟空》智能游戏助手

https://github.com/oceanbase-devhub/ai-workshop-2024/blob/main/README_zh.md

https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001579715

免费使用OceanBase Cloud搭建RAG聊天机器人

【整活向】把tidb的文档塞给了基于oceanbase的RAG机器人的更多相关文章

  1. tidb 记录文档

    ansible-playbook stop.yml   / start.yml 重启集群,在ansible目录下执行 SHOW STATS_META; 查看统计信息 重启集群:ansible-play ...

  2. 常用PDF文档开发库

    C++库: 1,PDF类库 PoDoFo   http://podofo.sourceforge.net/  PoDoFo 是一个用来操作 PDF 文件格式的 C++ 类库.它还包含一些小工具用来解析 ...

  3. ASP.NET WebApi 文档Swagger深度优化

    本文版权归博客园和作者吴双本人共同所有,转载和爬虫请注明博客园蜗牛原文地址,cnblogs.com/tdws   写在前面 请原谅我这个标题党,写到了第100篇随笔,说是深度优化,其实也并没有什么深度 ...

  4. 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览

    在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...

  5. JS文档生成工具:JSDoc 介绍

    JSDoc是一个根据javascript文件中注释的信息,生成API文档的工具.生成的文档是html文件.类似JavaDoc和PHPDoc. 用法 /** 一坨注释之类的 */JSDoc会从/**开头 ...

  6. PowerDesigner(九)-模型文档编辑器(生成项目文档)(转)

    模型文档编辑器 PowerDesigner的模型文档(Model  Report)是基于模型的,面向项目的概览文档,提供了灵活,丰富的模型文档编辑界面,实现了设计,修改和输出模型文档的全过程. 模型文 ...

  7. [置顶] stax解析xml文档的6种方式

    原文链接:http://blog.csdn.net/u011593278/article/details/9745271 stax解析xml文档的方式: 基于光标的查询: 基于迭代模型的查找: 基于过 ...

  8. ES 父子文档查询

    父子文档的特点 1. 父/子文档是完全独立的. 2. 父文档更新不会影响子文档. 3. 子文档更新不会影响父文档或者其它子文档. 父子文档的映射与索引 1. 父子关系 type 的建立必须在索引新建或 ...

  9. Java 处理word文档后在前端展示

    最新新开发的这个项目需要使用word文档并要求能在前端页面上带格式展示,由于项目不是内部使用,所以不考虑插件类的处理模式,都必须要本地处理完成,前端不需要做什么更新或者说安装就能直接访问,类似于百度文 ...

  10. 基于WPF系统框架设计(5)-Ribbon整合Avalondock 2.0实现多文档界面设计(二)

    AvalonDock 是一个.NET库,用于在停靠模式布局(docking)中排列一系列WPF/WinForm控件.最新发布的版本原生支持MVVM框架.Aero Snap特效并具有更好的性能. Ava ...

随机推荐

  1. 开源 - Ideal库 - Excel帮助类,设计思路(一)

    今天开始和大家分享关于Excel最长常用操作封装. 01.起因 市面上有很多Excel操作库,这些库设计之初的目标是提供对Excel的各种操作功能,包括数据.样式.公式.图表等等.而对于我们平时开发来 ...

  2. qiankun 的 CSS 沙箱隔离机制

    为什么需要CSS沙箱 在 qiankun 微前端框架中,由于每个子应用的开发和部署都是独立的,将主/子应用的资源整合到一起时,容易出现样式冲突的问题 因此,需要 CSS 沙箱来解决样式冲突问题,实现主 ...

  3. docker 批量删除镜像

    删除虚悬镜像 列出REPOSITORY和TAG均为<none>的虚悬镜像: $ docker images --filter dangling=true REPOSITORY TAG IM ...

  4. 为什么你用的 MyBatis 慢?一行配置让它性能翻倍!

    为什么你用的 MyBatis 慢?一行配置让它性能翻倍! 在 Java 后端开发的江湖里,MyBatis 堪称一员大将,凭借着灵活的 SQL 编写.方便的数据库对接能力,深受广大开发者的喜爱.但不少小 ...

  5. 前端每日一知之你需要知道的JSON.stringify

    脑图在线链接 本文内容依据[web开发]公众号精彩文章总结而来

  6. 中电金信:“人工智能+”首次写入政府工作报告,各大企业何以破局AI模型挑战

    ​2024年全球新一轮技术变革加速来临,大模型作为人工智能发展的核心引擎,正引发一场全新的工业革命.今年全国两会期间,人工智能成为最热话题之一."人工智能+"首次被写入政府工作报告 ...

  7. 关于Jetson nano (B02)如何部署Yolov8以及一些必要的知识点

    一.前言 记录一个简单的安装和部署过程,尽管笔者也是按照教程来的,但奈何参考了很多教程,虽然写的都非常好,但是却很散,因此笔者这里想把这些教程的精华提炼出来,汇总并且写在正文处.还是老规矩,笔者也在学 ...

  8. Vue3使用Vuex 教程(这才是真正的小白教程!)

    我的项目是vue3+element-plus 我是个菜鸡,我不懂前端.想做一个tags的导航标签页.但是点击标签页之后页面仍然是会重新请求.感觉这不就跟没做一样吗? 遂百度GPT,第一种方式采用的就是 ...

  9. Python 潮流周刊#83:uv 的使用技巧(摘要)

    本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...

  10. 不为人知的网络编程(十二):彻底搞懂TCP协议层的KeepAlive保活机制

    文中引用了参考资料中的部分内容,本文参考资料详见文末"参考资料"一节,感谢资料分享者. 1.引言 对于IM开发者而言,网络保活这件事再熟悉不过了,比如这是我最近一篇有关网络保活话题 ...