搜索文件
接口说明
按路径、标题、章节、Markdown 正文、元数据和可选文件关系查找当前可读取文件。使用结果内容前必须先读取返回的文件。
接口信息
| 字段 | 值 |
|---|---|
| 方法 | GET |
| 路径 | /openapi/v2/knowledge-bases/{knowledgeBaseId}/files/search |
| Operation ID | searchGeneratedFiles |
| 鉴权 | Bearer OpenAPI key |
入参
| 名称 | 位置 | 必填 | 类型 | 示例 | 说明 |
|---|---|---|---|---|---|
knowledgeBaseId | path | 是 | string | knowledge-base-11111111-1111-4111-8111-111111111111 | 知识库 API 返回的知识库标识。 |
query | query | 是 | string | How do I configure and verify the knowledge base deployment? | 一个完整独立的自然语言问题或搜索文本。Unicode 和空白规范化后必须包含 2 到 512 个字素簇、最多 2048 个 UTF-8 字节,并且不能包含不安全控制字符。结果是来源文件,使用其中内容作为证据前必须读取正文。 |
scope | query | 否 | all | path | metadata | all | 可用的证据字段范围。path 执行精确路径和有正文依据的标题检索,metadata 执行词法元数据检索,all 使用当前模式启用的全部证据类型。 |
fileKind | query | 否 | all | page | page | 可读取文件类型筛选。搜索只返回由上传文件生成且当前生效的 Markdown page 文件。all 会移除显式类型条件,但当前返回相同的 page 文件集合。 |
mode | query | 否 | file | graph | hybrid | hybrid | 搜索策略。file 搜索文件数据和语义相似内容,graph 沿文件关系和图语义信号查找,hybrid 合并两者。scope 用于缩小搜索字段范围。每条结果仍然是可读取的来源文件。 |
graphDepth | query | 否 | 0 | 1 | 2 | 1 | 图搜索和混合搜索结果返回的关系上下文深度。0 只返回起点图引用而不返回关系,1 包含直接关系,2 可以在 graphFanout 范围内包含第二层关系;超过部署上限时返回 422。 |
graphFanout | query | 否 | integer | 10 | 在请求的关系深度范围内,每个图搜索结果最多返回的关系记录总数。省略时使用当前部署配置;超过部署上限时返回 422。 |
okfStatus | query | 否 | draft | stable | deprecated | draft | 按规范化 OKF 文档状态筛选;显式提供无效状态的文件不会匹配。 |
okfTrustTier | query | 否 | unverified | machine-confirmed | human-reviewed | unverified | 按规范化 OKF 验证层级筛选;显式提供格式错误验证信息的文件不会匹配。 |
okfFreshness | query | 否 | fresh | stale | fresh | 按请求日期筛选新鲜或过期文件;缺少有效 stale_after 的文件不会匹配。 |
rerank | query | 否 | boolean | true | 本次搜索是否请求可选的来源候选重排。 |
rerankTopK | query | 否 | integer | 50 | 启用重排时参与处理的非精确候选数量。 |
rerankScoreThreshold | query | 否 | number | 0 | 启用重排时非精确候选需要达到的最低有效分数。 |
limit | query | 否 | integer | 10 | 本次请求实际采用的最大返回数量。 |
cursor | query | 否 | string | cursor_123 | 当前搜索返回的分页标记。只能在查询词、筛选条件、可读取知识库版本和排序设置不变时继续使用。 |
请求体
这个接口没有请求体。
请求示例
bash
curl -X GET "https://openapi.example.com/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/search?query=How+do+I+configure+and+verify+the+knowledge+base+deployment%3F&scope=all&fileKind=page&mode=hybrid&graphDepth=1&graphFanout=10&limit=10" \
-H "Authorization: Bearer <openapi-key>"成功响应
200
返回与查询匹配并按相关度排序的当前可读取文件。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
activeContentRevision | 是 | object | 当前可读取知识库内容的修订号。 |
query | 是 | object | 本次使用的查询词和选项。 |
items | 是 | array<FileSearchResult> | 当前分页中的记录。 |
nextCursor | 是 | string | null | 当前搜索接口返回的分页标记。只能在查询词、筛选条件和可读取知识库版本不变时继续使用;被拒绝时请移除 cursor 并重新搜索。 |
searchStatus | 是 | ok | no_candidates | ok 表示已返回搜索结果。no_candidates 表示当前查询没有匹配文件。依赖服务失败时使用文档中的 503 或 504 错误结构。 |
searchMode | 是 | file | graph | hybrid | 本次响应实际使用的搜索模式。 |
semanticStatus | 是 | object | 本次响应中可选语义搜索通道的可用状态和安全原因码。 |
evidenceStatus | 是 | object | 本次响应中已完成或降级的检索证据类型。 |
rerankerStatus | 是 | object | 可选重排是否已应用、跳过、不可用或降级。 |
graphStatus | 是 | available | index_unavailable | disabled_for_file_mode | 本次响应中的关系搜索可用状态。仅搜索文件时返回 disabled_for_file_mode。 |
graphSummary | 是 | object | 本次响应使用的文件关系摘要。 |
resultSummary | 是 | object | 当前结果的数量、分页情况和说明。 |
message | 否 | string | null | 没有匹配文件或搜索暂不可用时返回的状态说明。 |
nextActions | 否 | array<string> | 继续探索时建议执行的文件读取或关系查询。 |
成功响应示例
json
{
"activeContentRevision": 1,
"query": {
"query": "How do I configure and verify the knowledge base deployment?",
"normalizedQuery": "How do I configure and verify the knowledge base deployment?",
"scope": "all",
"fileKind": "page",
"mode": "hybrid",
"graphDepth": 1,
"graphFanout": 10,
"okfStatus": null,
"okfTrustTier": null,
"okfFreshness": null,
"rerank": false,
"rerankTopK": null,
"rerankScoreThreshold": null,
"limit": 10,
"cursorProvided": false
},
"items": [
{
"activeContentRevision": 1,
"fileId": "source-file-11111111-1111-4111-8111-111111111111",
"knowledgeBaseId": "knowledge-base-11111111-1111-4111-8111-111111111111",
"sourceFileId": "source-file-11111111-1111-4111-8111-111111111111",
"path": "pages/guide.md",
"fileKind": "page",
"title": "Verified guide",
"description": null,
"tags": [
"guide",
"policy"
],
"frontmatter": {
"okf_version": "0.2",
"type": "Guide",
"title": "Verified guide",
"tags": [
"guide",
"policy"
],
"sources": [
{
"id": "source-a",
"resource": "references/source-a.md"
}
],
"generated": {
"by": "publisher:example",
"at": "2026-06-17T00:00:00Z"
},
"verified": [
{
"by": "human:reviewer",
"at": "2026-06-17T01:00:00Z"
}
],
"status": "stable",
"stale_after": "2026-12-31"
},
"okfSignals": {
"effectiveStatus": "stable",
"trustTier": "human-reviewed",
"isStale": false,
"staleAfter": "2026-12-31",
"generatedAt": "2026-06-17T00:00:00.000Z",
"generatedAtSource": "generated",
"latestVerifiedAt": "2026-06-17T01:00:00.000Z",
"sourceCount": 1
},
"matchedFields": [
"content"
],
"evidenceTypes": [
"content"
],
"sourceExcerpt": "Configure the deployment, then verify service health and search readiness.",
"score": 9,
"contentAvailable": true,
"matchType": "file_direct",
"readActions": {
"fileDetailById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111",
"fileContentById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111/content",
"fileContentByPath": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/content?path=pages%2Fguide.md",
"relatedFilesById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111/related",
"graphExpansionByFileId": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/graph/expand?fileId=source-file-11111111-1111-4111-8111-111111111111",
"sourceFileStatusById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/source-files/source-file-11111111-1111-4111-8111-111111111111"
},
"graphContext": {
"graphRef": "_graph/by-file/handbook/guide.json",
"depth": 1,
"seedSourceFileId": "source-file-11111111-1111-4111-8111-111111111111",
"relationships": [
{
"activeContentRevision": 1,
"fileId": "source-file-22222222-2222-4222-8222-222222222222",
"sourceFileId": "source-file-22222222-2222-4222-8222-222222222222",
"path": "pages/reference.md",
"title": "Reference",
"relationType": "same_specific_subject",
"direction": "outgoing",
"fromFileId": "source-file-11111111-1111-4111-8111-111111111111",
"relationshipDepth": 1,
"reason": "Both files share body-derived subjects.",
"contentAvailable": true,
"readActions": {
"fileDetailById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-22222222-2222-4222-8222-222222222222",
"fileContentById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-22222222-2222-4222-8222-222222222222/content",
"fileContentByPath": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/content?path=pages%2Freference.md",
"relatedFilesById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-22222222-2222-4222-8222-222222222222/related",
"graphExpansionByFileId": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/graph/expand?fileId=source-file-22222222-2222-4222-8222-222222222222",
"sourceFileStatusById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/source-files/source-file-22222222-2222-4222-8222-222222222222"
}
}
],
"graphPaths": [
"_graph/by-file/handbook/guide.json",
"_graph/by-file/reference.json"
]
}
}
],
"nextCursor": null,
"searchStatus": "ok",
"searchMode": "hybrid",
"semanticStatus": {
"state": "ready",
"safeCode": null
},
"evidenceStatus": {
"completedFamilies": [
"exact_path",
"exact_title",
"lexical",
"jieba",
"content_vector",
"entity_vector",
"relationship_vector",
"community_vector",
"file_graph",
"file_relationship"
],
"degradedFamilies": []
},
"rerankerStatus": {
"state": "skipped",
"safeCode": "RERANKER_DISABLED"
},
"graphStatus": "available",
"graphSummary": {
"available": true,
"indexedDocumentCount": 24,
"indexedRelationshipCount": 86,
"depth": 1,
"fanout": 10
},
"resultSummary": {
"resultCount": 1,
"hasMore": false,
"sort": [
"relevance_desc",
"logical_path_asc",
"source_file_id_asc"
],
"meaning": "The query matched readable files. Read the returned files and related files before using their content."
}
}错误码
下表列出这个接口已声明的全部错误响应。
| HTTP 状态 | 错误码 | 说明 |
|---|---|---|
| 401 | UNAUTHORIZED | Bearer API key 缺失、格式错误、未知、已撤销或已删除。 |
| 404 | NOT_FOUND | 请求的资源不存在。 |
| 422 | VALIDATION_ERROR | 请求未通过校验。 |
| 429 | RATE_LIMITED | 请求超过当前配置的速率限制。 |
| 500 | INTERNAL_ERROR | API 遇到内部错误。 |
| 503 | DATABASE_REPOSITORY_UNAVAILABLE | 当前接口所需的数据暂时不可用。 |
| 503 | SEARCH_UNAVAILABLE | 搜索服务暂时不可用。 |
| 503 | SEARCH_OVERLOADED | 搜索服务当前负载过高。 |
| 504 | SEARCH_TIMEOUT | 搜索超过当前配置的响应时限。 |
校验详情码
收到 422 VALIDATION_ERROR 时,读取 error.details.code。此接口可能返回:
FILE_SEARCH_QUERY_REQUIREDFILE_SEARCH_QUERY_TOO_SHORTFILE_SEARCH_QUERY_TOO_LONGINVALID_FILE_SEARCH_QUERYINVALID_FILE_SEARCH_SCOPEINVALID_FILE_SEARCH_KINDINVALID_FILE_SEARCH_MODEINVALID_FILE_SEARCH_GRAPH_DEPTHINVALID_FILE_SEARCH_GRAPH_FANOUTINVALID_FILE_SEARCH_OKF_STATUSINVALID_FILE_SEARCH_OKF_TRUST_TIERINVALID_FILE_SEARCH_OKF_FRESHNESSINVALID_FILE_SEARCH_LIMITINVALID_FILE_SEARCH_RERANK_CONTROLS