1.vanna官网
官方文档:
源码:
https://github.com/vanna-ai/vanna
2.文档笔记
官方文档-SQL Databases、LLMs、Vector Databases中选择需要的内容即可生成代码
所有可重写的方法可查官方文档-API Reference-The Base Class
3.安装注意
Ollama、Mysql需要额外安装
选择Qdrant会有模型下载问题需要先下载模型到缓存路径
选择ChromaDB可直接使用但存在中文支持问题
4.连接mysql
vn.connect_to_mysql(host="1.1.1.1", dbname=“数据库名称”, user="数据库名称", password="数据库密码", port="数据库端口号")
5.连接Ollama
vn = MyVanna(config={
# ollama地址
'ollama_host': “http://192.168.1.1:123”,
# llm模型
'model': "qwen2.5:7b-instruct",
# llm api参数配置dialect
'options': {
# token长度
'num_ctx': 8192
},
})
6.使用Qdrant
# 项目路径
project_path = os.path.dirname(os.path.abspath(__file__))
vn = MyVanna(config={
# qdrant地址
'client': QdrantClient(path=project_path + '/vector/db/xxxx'),
# 向量模型,需要科学上网或者镜像站:https://hf-mirror.com
'fastembed_model': "jinaai/jina-embeddings-v2-base-zh",
# 向量模型缓存路径,
'fastembed_model_cache_dir': project_path + '/vector/model',
# 向量检索结果数量
'n_results': 3,
})
向量模型:
链接: https://pan.baidu.com/s/1ubS0e6U787283bUlnfnyaQ?pwd=1111
提取码:1111
7.增加新的接口
需要重写src.vanna.flask