Alibaba Cloud Bailian knowledge base retrieval tool. Compiled binary, runs with zero dependencies, returns structured JSON.
Security Warning
config.json Contains Alibaba Cloud AK/SK keys.
Prerequisites
config.json Configured (in the skill directory):
{
"alibaba_cloud_access_key_id": "your_key",
"alibaba_cloud_access_key_secret": "your_secret",
"workspace_id": "your_workspace",
"knowledge_index_id": "your_index",
"endpoint": "bailian.cn-beijing.aliyuncs.com"
}
Usage
Choose the binary according to the operating system:
| OS | Binary |
|---|---|
| macOS | bailian-query-mac |
| Linux amd64 | bailian-query-linux |
| Windows amd64 | bailian-query-win64.exe |
SKILL_DIR=$(dirname "$0")
# macOS
$SKILL_DIR/bin/bailian-query-mac -config $SKILL_DIR/config.json "初诊患者怎么随访"
# Linux
$SKILL_DIR/bin/bailian-query-linux -config $SKILL_DIR/config.json "初诊患者怎么随访"
Parameters
| Parameter | Description | Required |
|---|---|---|
-config |
config.json path | Yes (defaults to config.json) |
<query> |
Retrieval query statement | Yes |
[workspace_id] |
Override the workspace_id in the configuration | No |
[index_id] |
Override the knowledge_index_id in the configuration | No |
Examples
# 基本查询
bailian-query-mac -config config.json "初诊患者怎么随访"
# 覆盖 workspace 和 index
bailian-query-mac -config config.json "吸入过敏原" custom_workspace custom_index
Output Structure
Returns JSON, with core fields:
{
"Code": "Success", // 状态码: Success / 错误码
"Data": {
"Nodes": [ // 匹配文档片段列表,按相关性降序
{
"Score": 0.854, // 相关性评分 (0-1),>0.7 为高相关
"Text": "...", // 匹配的文档内容片段
"Metadata": {
"doc_name": "...", // 来源文档名
"title": "...", // 文档层级标题
"hier_title": "...", // 层级路径 (如 "哮喘照护 > 初诊 > 随访")
"page_number": [1], // 来源页码
"doc_url": "..." // 文档下载链接 (带过期时间)
}
}
]
},
"RequestId": "...",
"Success": true
}
Result Filtering — Confidence filtering rules (must be followed)
Core principle: only return high-confidence results; low-confidence results must all be discarded, and never fabricate or speculate.
| Score range | Handling method |
|---|---|
| ≥ 0.7 | High confidence — return normally to the user, safe to cite |
| 0.4 ~ 0.7 | Medium confidence — use only as auxiliary reference, must clearly label "moderate relevance, for reference only" |
| < 0.4 | Low confidence — must be discarded, not returned to the user |
Execution flow:
- After the query returns JSON, check the
Nodeslist - If
Nodesis empty or all Nodes have Score < 0.4 → directly tell the user: "No relevant content found in the knowledge base", do not guess or fabricate - Filter out Nodes with Score < 0.4, keeping only results ≥ 0.4
- Label the confidence level for results from 0.4 to 0.7, and present results ≥ 0.7 normally
- It is absolutely forbidden to add information not present in the knowledge base, specifically including:
- Do not infer missing fields: if a field in the original data is empty (such as category, title, etc.), it must be presented as empty truthfully, and must not be inferred or filled in based on code prefixes, name meanings, common sense, etc. An empty field is an empty field, present it truthfully
- Do not supplement based on common sense: do not use your own knowledge to supplement content not covered by the knowledge base (such as operation steps, definition explanations, background knowledge, etc.)
- Do not piece together a complete answer: do not use low-confidence fragments to piece together an apparently complete answer
- Do not force associations: do not force irrelevant content to be associated with the user's question
- One-sentence principle: only present content that exists in the original text of the knowledge base; do not add a single word that is not in the original text
- It is absolutely forbidden to expose the internal processing process to the user: no description of any internal logic such as Score thresholds, number of filtered items, number of retained items, highest/lowest Score, discarded/retained, etc. may appear in the output. The user only sees the final conclusion, not the intermediate process. Violating this rule is equivalent to leaking internal system information to the user
Output Format — Output format rules (must be followed)
When presenting retrieval results to the user,the information source must be indicated at the end of the answer:
- Answer body: organize and present the filtered high/medium confidence results,without including any Score values or descriptions of the filtering process
- Append source attribution at the end, in the following format:
---
**信息来源:**
- 《文档名1》
- 《文档名2》 (仅供参考)
- Source attribution rules:
- From each retained Node's
Metadata.doc_nameextract the document name - List each document name only once (deduplicate)
- For high confidence (≥0.7), list only the document name
- For medium confidence (0.4~0.7), additionally mark "for reference only"
- If there is page number information (
page_number), append the page number, e.g.:《文档名》第2页 - Score values must not appear in the source annotation
- From each retained Node's
- When no relevant content is found in the knowledge base, the source annotation is:
**信息来源:** 知识库中无匹配文档
Error Handling
| Exit Code | Meaning | Fix |
|---|---|---|
| 1 | Missing query argument | Provide query string as first positional arg |
| 1 | Config file read error | Check -config path and file permissions |
| 1 | Config parse error | Validate JSON format in config.json |
| 1 | Client creation failed | Check AK/SK correctness |
| 1 | Retrieve API failed | Check workspace_id / knowledge_index_id validity |
Build
To recompile:
cd scripts
go mod tidy
# macOS
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o ../bin/bailian-query-mac .
# Linux amd64 (交叉编译)
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o ../bin/bailian-query-linux .
# Windows amd64 (交叉编译)
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o ../bin/bailian-query-win64.exe .