WeKnora制造企业知识库建设实践-基础配置

卷 1 · 从零配置 WeKnora(手把手教程)
目标:一个从没接触过 WeKnora 的人,照着这一卷能配到"能建库、能导入、能问答、能开图"。 每一步都写清楚:点哪里、填什么、为什么这么填、填错了会怎样。 所有字段名、默认值均为实测值(来自本项目 DB 与源码)。
1.0 配置全景(先建立地图)
flowchart TB
A[”① 部署启动docker compose up”] --> B[”② 配模型Embedding/Rerank/LLM/视觉”]
B --> C[”③ 配 Agent绑定 rerank/LLM + 参数”]
C --> D[”④ 建知识库分块参数 + 绑 embedding”]
D --> E[”⑤ 导数据文件/manual”]
E --> F[”⑥ 打标签/元数据”]
F --> G[”⑦ 开 GraphRAG(可选)”]
G --> H[”⑧ 拿 API key 调接口”]
B -.->|”模型连不通”| ERR[”1.11 报错速查”]
D -.->|”分块/检索调错”| ERR
E -.->|”解析卡住”| ERR
顺序很重要:模型必须先在「模型管理」里配好并连通,才能在建库时选择它、在 Agent 里绑定它。跳过模型直接建库会卡在"没有可用模型"。
1.1 部署与启动
1.1.1 容器清单(本项目实测)
| 容器名 | 镜像 | 端口映射 | 作用 |
| WeKnora-frontend | wechatopenai/weknora-ui:latest | 80→80 | 前端 UI |
| WeKnora-app | wechatopenai/weknora-app:latest | 8080→8080 | 后端 API |
| WeKnora-postgres | paradedb/paradedb:v0.22.2-pg17 | 5432 | 数据库(pgvector + BM25) |
| WeKnora-docreader | wechatopenai/weknora-docreader:latest | 50051 | 文档解析服务 |
| WeKnora-redis | redis:7.0-alpine | 6379 | 缓存/任务队列 |
| WeKnora-neo4j | neo4j:2025.10.1 | 7474/7687 | 图数据库 |
1.1.2 启动
cd /Users/enzo.s/WeKnora-main/WeKnora-main
docker compose up -d
docker ps
确认 6 个容器都 Up
1.1.3 首次访问
- 前端:http://localhost:80
- 后端 API:http://localhost:8080
- Neo4j Browser:http://localhost:7474(认证 neo4j/password)
首次打开前端会要求初始化(创建管理员账号 + 工作区)。本项目的租户是 Enzo_S's Workspace(tenant_id=10000)。
1.2 模型配置(★ 最关键,最多人卡这里)
1.2.1 模型供应商怎么选
| 供应商 | 适用场景 | 优点 | 缺点 | 是否需外网 |
| 阿里云百炼 / DashScope(通义千问) | 国内企业、中文场景(本项目用它) | 中文强、合规、便宜 | 需实名开通 | 是 |
| OpenAI 兼容 API | 通用、接各种中转 | 生态广 | 价格、合规 | 是 |
| 自建 vLLM / Ollama | 内网、数据不出域 | 免费、可控 | 要显卡、要自己运维 | 否 |
| DeepSeek 等 | 高性价比推理 | 便宜 | — | 是 |
本项目选型结论:全部用阿里云百炼(DashScope),embedding 用 text-embedding-v4、rerank 用 qwen3-rerank、对话用 qwen-max、视觉用 qwen-vl-max。理由详见卷 2。
1.2.2 API key 怎么申请(以阿里云百炼为例)
- 注册并登录阿里云账号
- 开通「阿里云百炼」服务(DashScope)
- 控制台 → API-KEY 管理 → 创建 API-KEY
- 得到 开头的 key(本项目实测格式:)
- 安全存放:key 等同密码,写进 并加 ,不要提交到仓库、不要截图外发
1.2.3 各供应商的 base_url 格式(实测)
| 用途 | base_url |
| OpenAI 兼容(通义 embedding/LLM/视觉) | https://dashscope.aliyuncs.com/compatible-mode/v1 |
| DashScope 原生 rerank | https://dashscope.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank |
注意 rerank 的坑:rerank 走的是 DashScope 原生端点,不是
compatible-mode。填错端点会 404。
1.2.4 四个模型的完整配置(本项目实测,来自 models 表)
| 模型 | type | model_id(DB 主键) | base_url | 关键参数 |
| text-embedding-v4 | Embedding | 3fb4a0d4-d7a7-4c5f-8620-c758c1a1ddd6 | compatible-mode | dimension=1024,supports_dimension_override=false |
| qwen-max | KnowledgeQA(LLM) | 908846a7-7e89-4054-94a0-674966096f70 | compatible-mode | thinking_control=enable_thinking,supports_vision=true,is_default |
| qwen3-rerank | Rerank | c2dee776-328f-46e7-bcf4-32722bfd2317 | rerank 原生端点 | — |
| qwen-vl-max | VLLM(视觉) | 5762137a-7609-49e8-9151-ee0e91596aa7 | compatible-mode | supports_vision=true |
1.2.5 UI 配置步骤(模型管理页)
对每个模型,依次填以下字段:
| 字段 | 填什么(以 embedding 为例) | 说明 |
| 模型名称 | text-embedding-v4 | 展示名 |
| 模型类型 | Embedding | 决定用途 |
| 供应商 | 阿里云百炼(provider=aliyun) | — |
| API 端点 base_url | https://dashscope.aliyuncs.com/compatible-mode/v1 | 见 1.2.3 |
| API Key | sk-ws-H.**** | 申请见 1.2.2 |
| 维度 dimension | 1024 | embedding 必填,与向量库索引一致 |
配置完点「测试连接」,连通即成功。
1.2.6 连通性验证(命令行快速验证)
# 验证 embedding(OpenAI 兼容)
curl -s https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings \
-H ”Authorization: Bearer sk-ws-H.****” \
-H ”Content-Type: application/json” \
-d '{”model”:”text-embedding-v4”,”input”:”测试”,”dimensions”:1024}'
常见报错与含义(详见 1.11):
| 现象 | 原因 |
401 Unauthorized | key 错 / 未开通 / 欠费 |
404 Not Found | 端点拼错 / 模型名错 |
| 维度不匹配 | embedding 维度与向量索引不一致 |
1.3 Agent 配置
1.3.1 内置 Agent
WeKnora 自带一个内置 Agent(名称「快速问答」,id=builtin-quick-answer)。本项目直接用内置 Agent,关键是要给它绑定 rerank 和 LLM 模型并调好参数。
1.3.2 本项目 Agent 实测参数(来自 custom_agents 表)
| 字段 | 实测值 | 含义 |
| model_id | 908846a7(qwen-max) | 对话模型 |
| rerank_model_id | c2dee776(qwen3-rerank) | 精排模型 |
| temperature | 0.7 | 生成温度 |
| max_completion_tokens | 2048 | 最大输出 token |
| history_turns | 5 | 携带历史轮数 |
| max_iterations | 1 | 多跳迭代次数 |
| thinking | true | 开启思考(enable_thinking) |
| agent_mode | quick-answer | 快速问答模式 |
| kb_selection_mode | all | 检索全部已选知识库 |
| rerank_top_k | 10 | rerank 后取 top10 |
| rerank_threshold | 0.3 | rerank 分数阈值 |
| embedding_top_k | 10 | 向量召回 top10 |
| faq_direct_answer_threshold | 0.9 | FAQ 直接回答阈值 |
| faq_score_boost | 1.2 | FAQ 分数加权 |
| citation_enabled | true | 启用引用溯源 |
| enable_query_expansion | true | 启用查询扩展 |
Agent 级参数会覆盖租户级检索配置:例如租户
embedding_top_k=50,但 Agent 里是10,实际按 Agent 的 10 走。调参优先看 Agent。
1.3.3 配置步骤
- 进入「智能体 / Agent」页面
- 打开内置 Agent「快速问答」(或新建自定义 Agent)
- 绑定对话模型(qwen-max)、Rerank 模型(qwen3-rerank)
- 调整上表参数(temperature、top_k、阈值等)
- 勾选要检索的知识库(kb_selection_mode=all 则全选)
1.4 创建知识库
1.4.1 6 库分块参数(本项目实测)
| KB | 类型 | chunk_size | chunk_overlap | parent_size | child_size |
| KB-A 权威事实库 | document | 512 | 80 | 4096 | 384 |
| KB-B 解决方案库 | document | 1024 | 100 | 4096 | 384 |
| KB-C 经验库 | document | 1024 | 100 | 4096 | 384 |
| KB-D 银弹卡库 | document | 1200 | 80 | 4096 | 384 |
| KB-E 产出物库 | document | 512 | 80 | 4096 | 384 |
| KB-F 术语库 | faq | 512 | 50 | 4096 | 384 |
默认分块配置(DB 默认值):{"chunk_size": 512, "chunk_overlap": 50, "split_markers": ["\n\n", "\n", "。"], "keep_separator": true}
分块策略选择:
1.4.2 创建步骤
- 「知识库」→「新建」
- 填名称(如 )、类型(document / faq)
- 绑定 Embedding 模型(必须选 text-embedding-v4,且 5 个文档库要同模型)
- 设分块参数(chunk_size / overlap / 父子分块)
- 绑定 Summary 模型(qwen-max)
- 保存
1.4.3 检索配置(租户级,实测)
来自 tenants.retrieval_config:
| 字段 | 实测值 | 含义 |
| rrf_k | 60 | RRF 融合参数 |
| embedding_top_k | 50 | 向量召回 top50 |
| rerank_top_k | 10 | rerank 后 top10 |
| rerank_threshold | 0.2 | rerank 阈值 |
| vector_threshold | 0.15 | 向量阈值 |
| keyword_threshold | 0.3 | 关键词阈值 |
| rrf_vector_weight | 0.7 | 向量权重 |
| rrf_keyword_weight | 0.3 | 关键词权重 |
| rerank_model_id | c2dee776 | rerank 模型 |
1.5 数据导入
1.5.1 两种方式
| 方式 | 适用 | 接口 |
| 文件导入 | PDF/DOCX/MD 等文件 | POST /knowledge-bases/:id/knowledge/file |
| manual 手动导入 | 纯文本内容(本项目用) | POST /knowledge-bases/:id/knowledge/manual |
1.5.2 manual 导入(本项目实测 payload)
{
”title”: ”GBT25485 标准条款”,
”content”: ”标准正文……”,
”status”: ”publish”
}
踩坑:manual 接口没有 metadata 字段。业务属性要单独用 PUT /knowledge/:id 写 custom_metadata(见 1.6)。status 必须为 publish,draft 不触发解析。
1.5.3 观察解析状态
导入后知识进入解析队列,parse_status 流转:
pending → processing → completed(成功)
→ failed(失败,看 error_message)
# 查解析状态
curl -H ”X-API-Key: $(cat pipeline/.api_key)” \
http://localhost:8080/api/v1/knowledge/:id
1.6 标签与元数据
1.6.1 标签(类型维度)
本项目 13 个实体类型标签(knowledge_tags 表实测):
industry standard kpi system function process method case project deliverable silver_card data_entity term
附 grade 标签
grade-brief/grade-ok和系统内置「未分类」。
1.6.2 custom_metadata(属性维度)
写业务元数据用 PUT /knowledge/:id:
{
”custom_metadata”: {
”entity_type”: ”standard”,
”entity_id”: ”02-标准条款库/xxx”,
”domain”: ”general”,
”grade”: ”🟡”
}
}
硬约束:custom_metadata ≤20 字段、key ≤64 字符、value ≤1000 字符、值限 string/number/bool/null。
1.7 开启 GraphRAG(图抽取)
1.7.1 抽取配置字段(extract_config)
| 字段 | 含义 |
| text | 抽取指令示例(给 LLM 的 few-shot) |
| tags | 允许抽取的实体类型标签 |
| nodes | 节点 schema(要抽取哪些实体) |
| relations | 关系 schema(要抽取哪些关系) |
| CustomInstructions | 领域自定义指令 |
校验规则:
enabled=true时,text/tags/nodes/relations 全必填,缺一不可。
1.7.2 开启方式
- 创建时:POST 创建知识库 body 里带 extract_config(仅创建接口暴露)
- 运行时:PUT 不暴露 extract_config,需直接改 DB:
UPDATE knowledge_bases SET extract_config='{...}', indexing_strategy='{...,”graph_enabled”:true}' WHERE id='...';
图谱抽取是富化子任务:主解析完成后向量已可检索(
parse_status=finalizing),摘要/问题/图谱在后台继续跑。
1.8 API 认证
1.8.1 Bootstrap key 生成原理(本项目实测)
- token 格式:sk- + base64url(32 字节随机)
- key_hash = sha256(token)
- 认证只看 key_hash(api_key 列仅 UI 显示)
- bootstrap key 存在 pipeline/.api_key,full_access,tenant_id=10000
1.8.2 调用示例
curl -H ”X-API-Key: sk-****” \
http://localhost:8080/api/v1/knowledge-bases
1.9 环境与依赖
- Python 3.x + requests(脚本只用了 requests)
- Neo4j 认证:neo4j/password
- Postgres 认证:postgres/postgres123!@#
- 配置文件:pipeline/.api_key(key)、pipeline/kb_ids.json(6 库 ID)
1.10 配置自检清单
- 6 容器全部 Up
- 4 个模型都「测试连接」通过
- Agent 绑定了对话模型 + rerank 模型
- 知识库绑定了 embedding 模型(且文档库同模型)
- 导入的 knowledge parse_status=completed
- 标签已建、custom_metadata 已写
- 检索能返回结果(不是空)
1.11 常见报错速查表(★ 一键排错)
| 报错现象 | 原因 | 解决 |
401 Unauthorized | API key 错/未开通/欠费 | 检查 key、开通服务、充值 |
404 Not Found | base_url 拼错 / 模型名错 | 对照 1.2.3 端点;rerank 用原生端点 |
400 Bad Request | 字段缺失/格式错 | 对照接口 schema 补字段 |
422 Unprocessable | 参数校验失败(如 custom_metadata 超限) | 缩减字段/值长度 |
| 维度不匹配 | embedding 维度与向量索引不一致 | 统一用 1024 维,重建索引 |
| 一直 pending / 解析卡住 | docreader 异常 / 资源不足 | 看 error_message,重启 docreader |
| 连接超时 | base_url 不通 / 防火墙 / 代理 | 检查网络、内网需自建 vLLM |
| 检索结果为空 | rerank 没配 / 阈值过高 / 没绑模型 | 检查 Agent 的 rerank_model_id、调低阈值 |

前段时间在研究obsidian知识库已经实现软件的应用,近些项目在做企业级的知识库,选用腾讯开源的weknora做验证,内容比obsidian要专业和复杂一些,一次发布内容太大,分几卷发布,欢迎交流!最近token真是肉疼啊!