---
title: "查询知识图谱"
method: POST
path: "/knowledge-bases/{id}/graph-search"
tags: ["知识库"]
---

# 查询知识图谱

`POST /knowledge-bases/{id}/graph-search`

## Request

- Base URL: `/api/v1` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/v1/knowledge-bases/{id}/graph-search`
- Auth: one of:
  - API key in header `Authorization`
  - API key in header `X-API-Key`

对单个授权知识库按实体名进行区分大小写的子串查询，返回实体、定向关系及仍然有效的来源分块。不调用模型，不影响默认检索。0 表示使用默认上限。

## Path parameters

- `id` string, required

## Query parameters

- `agent_id` string
- `agent_source_tenant_id` integer

## Request body

- GithubComTencentWeKnoraInternalTypesGraphSearchRequest
  - `max_nodes` integer
  - `max_relations` integer
  - `max_source_chunks` integer
  - `query` string, required

## Response `200`

OK

- object
  - `data` GithubComTencentWeKnoraInternalTypesGraphSearchResult
    - `entities` GithubComTencentWeKnoraInternalTypesGraphSearchEntity[]
      - `attributes` string[]
      - `id` string
      - `knowledge_id` string
      - `name` string
      - `source_chunk_ids` string[]
    - `knowledge_base_id` string
    - `meta` GithubComTencentWeKnoraInternalTypesGraphSearchMeta
      - `max_nodes` integer
      - `max_relations` integer
      - `max_source_chunks` integer
      - `truncated` boolean
      - `truncation_reasons` string[]
    - `query` string
    - `relationships` GithubComTencentWeKnoraInternalTypesGraphSearchRelation[]
      - `id` string
      - `source_chunk_ids` string[]
      - `source_id` string
      - `target_id` string
      - `type` string
    - `source_chunks` GithubComTencentWeKnoraInternalTypesGraphSearchSourceChunk[]
      - `chunk_index` integer
      - `content` string
      - `content_truncated` boolean
      - `end_at` integer
      - `id` string
      - `knowledge_id` string
      - `start_at` integer
      - `title` string
      - `title_truncated` boolean
  - `success` boolean

## Other responses

- `400`: 参数错误
- `401`: 未登录
- `403`: 无权访问知识库
- `404`: 知识库不存在
- `409`: 知识图谱未启用
- `500`: 来源校验失败
- `503`: 图谱服务不可用

## Changes

- **2026-10-17** `25db7e594c73`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/tencentblueking/apis/weknora-api/changes/knowledge-bases/:id/graph-search/post.md)

---

[API](https://skmtc.dev/tencentblueking/apis/weknora-api.md) - [All operations](https://skmtc.dev/tencentblueking/apis/weknora-api/llms.txt) - [OpenAPI document](https://skmtc.dev/tencentblueking/apis/weknora-api/revisions/685d1f9fce30?raw)
