dwqs / dwqs/blog

基于大模型的本地知识库搭建

Open
#80 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.8k
Forks
443
PR merge metrics
No merged PRs in 30d

Description

本篇文章将介绍基于大模型来搭建本地知识库的流程。
开源工具:[MaxKB](https://maxkb.cn/) + [Ollama](https://ollama.com/)
## 安装docker
在[官网](https://www.docker.com/)按需选择桌面版本,安装之后在docker中搜索maxkb的镜像:

![搜索maxkb](https://image-static.segmentfault.com/242/022/2420226528-674fc1b33b3d0)

点击 `Run`,等镜像下载完成之后,配置参数:

![配置container](https://image-static.segmentfault.com/128/925/1289253628-674fc4a9677fa)

在 `Volumes` 这里,需要配置两个 `Host path` 来映射容器的固定目录:

```
# host path是本机目录,可以随意
/host/path1 ==> /var/lib/postgresql/data
/host/path2 ==> /opt/maxkb/app/sandbox/python-packages
```

配置好之后,点击 `Run`,浏览器打开 `localhost:8080`,就能访问了:

![登录页面](https://image-static.segmentfault.com/171/233/1712336322-674fc603503f1_fix732)

输入默认的用户名和密码登录即可:`admin` / `MaxKB@123..`

除了可视化配置之外,也可在 Terminal 运行命令启动:

```sh
docker run -d --name=maxkb --restart=always -p 5432:8080 \n
-v ~/.maxkb:/var/lib/postgresql/data \n
-v ~/.python-packages:/opt/maxkb/app/sandbox/python-packages \n
cr2.fit2cloud.com/1panel/maxkb
```

## 创建知识库
登录之后,点击知识库 --> 创建知识库:

![创建知识库](https://image-static.segmentfault.com/180/347/1803470116-675106260a782_fix732)

然后选择 `Markdown` 格式的文档上传:

![上传文件](https://image-static.segmentfault.com/413/002/41300209-674fc9f6d5b2e_fix732)

示例的 `README.md` 是介绍组件 `QueryTable`组件的使用。
可以把需要上传的文档放在同一个目录一起上传,待文件上传完成之后,就完成了知识库的创建。

## 添加Ollama
物料上传之后,去系统管理 --> 模型设置,配置本地私有模型:

![模型设置](https://image-static.segmentfault.com/724/954/724954470-674fcb3364695_fix732)

maxkb 不仅支持常见的公有模型,也支持Ollama等私有模型。对于非敏感数据,也可以选择线上的公有模型。私有模型我们选择 [ollama](https://ollama.com/) 进行配置。

先去官网下载 `ollama`,安装之后可以跑一下中文模型 [qwen2.5](https://qwen.readthedocs.io/zh-cn/latest/run_locally/ollama.html):

![qwen2.5](https://image-static.segmentfault.com/412/191/4121911805-6751120a4814d_fix732)

因为物料都是中文,所以MaxKB也选择中文开源模型 `qwen2.5`:

![添加Ollama](https://image-static.segmentfault.com/836/304/836304673-674fd8f0dede7_fix732)

API域名用 `http://host.docker.internal:11434`,`host.docker.internal` 这个特殊的DNS名称来解析宿主机IP(类似主机 `localhost` 的别名), `11434` 是 `ollama` 模型的默认端口,API Key 随便填一个就行,最后点「添加」:

![创建本地模型](https://image-static.segmentfault.com/358/621/3586215552-674fd9a718b46_fix732)

> 如果是线上模型,域名和key就用模型对应的域名和key

## 创建应用
知识库和本地模型都配置完成之后,就需要创建一个应用将**知识库**和**本地模型**关联起来:

![创建应用](https://image-static.segmentfault.com/180/347/1803470116-675106260a782_fix732)

「AI模型」选择刚创建好的**本地模型**。应用创建好之后,会有一个本地访问连接:

![应用界面](https://image-static.segmentfault.com/380/871/3808715137-674fdc3e3691e_fix732)

打开这个链接,输入问题:QueryTable组件怎么用。可以看到其回复中会引用知识库 `component` 中的内容:

![结果测试](https://image-static.segmentfault.com/269/007/2690070462-675107c7d464a_fix732)

至此,我们已完成基于本地大模型的知识库搭建。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The payload names README.md, Docker, MaxKB, and Ollama, but no repository article path or test. Start by locating the blog source entry for this article and verify the documented Docker, Ollama, and localhost:8080 steps. Done means the article is placed in the expected location and its links, images, and commands render correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, ollama
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.