Files
knowledge-graph-agent/backend/docs/swagger.yaml
T

534 lines
12 KiB
YAML
Raw Normal View History

2026-04-13 16:16:39 +08:00
basePath: /
definitions:
2026-04-15 15:19:39 +08:00
model.CreateEdgeRequest:
2026-04-15 14:24:39 +08:00
properties:
id:
example: edge_123
type: string
label:
example: 包含
type: string
properties:
additionalProperties: true
type: object
source:
example: node_1
type: string
target:
example: node_2
type: string
type:
example: CONTAINS
type: string
required:
- id
- label
- source
- target
type: object
2026-04-15 15:19:39 +08:00
model.CreateNodeRequest:
2026-04-15 14:24:39 +08:00
properties:
id:
example: node_123
type: string
label:
example: 人工智能
type: string
properties:
additionalProperties: true
type: object
type:
example: 概念
type: string
x:
example: 100
type: number
"y":
example: 200
type: number
required:
- id
- label
- type
type: object
2026-04-15 15:19:39 +08:00
model.DeleteResponse:
2026-04-15 14:24:39 +08:00
properties:
id:
example: node_123
type: string
message:
example: 节点已成功删除
type: string
success:
example: true
type: boolean
type: object
2026-04-15 15:19:39 +08:00
model.Edge:
2026-04-13 16:16:39 +08:00
properties:
id:
type: string
label:
type: string
properties:
additionalProperties: true
type: object
source:
type: string
style:
additionalProperties: true
type: object
target:
type: string
type:
type: string
type: object
2026-04-15 15:19:39 +08:00
model.EdgeResponse:
2026-04-15 14:24:39 +08:00
properties:
id:
example: edge_123
type: string
label:
example: 包含
type: string
properties:
additionalProperties: true
type: object
source:
example: node_1
type: string
target:
example: node_2
type: string
type:
example: CONTAINS
type: string
type: object
2026-04-15 15:19:39 +08:00
model.ErrorResponse:
2026-04-13 16:16:39 +08:00
properties:
error:
type: string
message:
type: string
type: object
2026-04-15 15:19:39 +08:00
model.GraphData:
2026-04-13 16:16:39 +08:00
properties:
edges:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Edge'
2026-04-13 16:16:39 +08:00
type: array
nodes:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Node'
2026-04-13 16:16:39 +08:00
type: array
type: object
2026-04-15 15:19:39 +08:00
model.NeighborResponse:
2026-04-13 16:16:39 +08:00
properties:
edges:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Edge'
2026-04-13 16:16:39 +08:00
type: array
nodes:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Node'
2026-04-13 16:16:39 +08:00
type: array
type: object
2026-04-15 15:19:39 +08:00
model.Node:
2026-04-13 16:16:39 +08:00
properties:
id:
type: string
label:
type: string
properties:
additionalProperties: true
type: object
style:
additionalProperties: true
type: object
type:
type: string
x:
type: number
"y":
type: number
type: object
2026-04-15 15:19:39 +08:00
model.NodeResponse:
2026-04-13 16:16:39 +08:00
properties:
id:
type: string
label:
type: string
2026-04-15 15:19:39 +08:00
neighbors:
items:
$ref: '#/definitions/model.Node'
type: array
2026-04-13 16:16:39 +08:00
properties:
additionalProperties: true
type: object
2026-04-15 15:19:39 +08:00
style:
additionalProperties: true
type: object
2026-04-13 16:16:39 +08:00
type:
type: string
2026-04-15 15:19:39 +08:00
x:
type: number
"y":
type: number
2026-04-13 16:16:39 +08:00
type: object
2026-04-15 15:19:39 +08:00
model.SearchResponse:
2026-04-13 16:16:39 +08:00
properties:
count:
type: integer
2026-04-15 15:19:39 +08:00
nodes:
2026-04-13 16:16:39 +08:00
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Node'
2026-04-13 16:16:39 +08:00
type: array
2026-04-15 15:19:39 +08:00
query:
type: string
2026-04-13 16:16:39 +08:00
type: object
2026-04-15 15:19:39 +08:00
model.SimpleEdge:
2026-04-15 14:52:33 +08:00
properties:
label:
example: 包含
type: string
source:
example: "1"
type: string
target:
example: "2"
type: string
type:
example: CONTAINS
type: string
type: object
2026-04-15 15:19:39 +08:00
model.SimpleGraphData:
2026-04-15 14:52:33 +08:00
properties:
edges:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.SimpleEdge'
2026-04-15 14:52:33 +08:00
type: array
nodes:
items:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.SimpleNode'
2026-04-15 14:52:33 +08:00
type: array
type: object
2026-04-15 15:19:39 +08:00
model.SimpleNode:
2026-04-15 14:52:33 +08:00
properties:
id:
example: "1"
type: string
label:
example: 人工智能
type: string
type:
example: 概念
type: string
type: object
2026-04-15 15:19:39 +08:00
model.UpdateNodeRequest:
2026-04-15 14:24:39 +08:00
properties:
label:
example: 机器学习
type: string
properties:
additionalProperties: true
type: object
type:
example: 工具
type: string
x:
example: 150
type: number
"y":
example: 250
type: number
type: object
2026-04-13 16:24:25 +08:00
host: localhost:3001
2026-04-13 16:16:39 +08:00
info:
contact: {}
description: 知识图谱后端服务,提供图数据查询、节点搜索等功能
title: 知识图谱 API
version: 1.0.0
paths:
2026-04-15 14:24:39 +08:00
/api/edges:
post:
consumes:
- application/json
description: 在知识图谱中创建一个新边(关系)
parameters:
- description: 边创建请求
in: body
name: request
required: true
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.CreateEdgeRequest'
2026-04-15 14:24:39 +08:00
produces:
- application/json
responses:
"200":
description: 创建成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.EdgeResponse'
2026-04-15 14:24:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"404":
description: 源节点或目标节点未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"409":
description: 边已存在
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
summary: 创建边
/api/edges/{id}:
delete:
description: 从知识图谱中删除指定的边
parameters:
- description: 边ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 删除成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.DeleteResponse'
2026-04-15 14:24:39 +08:00
"404":
description: 边未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
summary: 删除边
2026-04-13 16:16:39 +08:00
/api/graph:
get:
description: 获取知识图谱的全部节点和边数据
produces:
2026-04-15 14:24:39 +08:00
- application/json
2026-04-13 16:16:39 +08:00
responses:
"200":
description: 成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.GraphData'
2026-04-13 16:16:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
summary: 获取图数据
2026-04-15 14:52:33 +08:00
/api/graph/simpleJson:
get:
description: 获取知识图谱的全部节点和边数据(仅保留核心信息,适合LLM处理)
produces:
- application/json
responses:
"200":
description: 成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.SimpleGraphData'
2026-04-15 14:52:33 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:52:33 +08:00
summary: 获取简化图数据
2026-04-13 16:16:39 +08:00
/api/graph/stats:
get:
description: 获取知识图谱的节点数、边数等统计信息
produces:
2026-04-15 14:24:39 +08:00
- application/json
2026-04-13 16:16:39 +08:00
responses:
"200":
description: 成功
schema:
additionalProperties: true
type: object
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
summary: 获取图统计信息
2026-04-15 14:24:39 +08:00
/api/nodes:
post:
consumes:
- application/json
description: 在知识图谱中创建一个新节点
parameters:
- description: 节点创建请求
in: body
name: request
required: true
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.CreateNodeRequest'
2026-04-15 14:24:39 +08:00
produces:
- application/json
responses:
"200":
description: 创建成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Node'
2026-04-15 14:24:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"409":
description: 节点已存在
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
summary: 创建节点
2026-04-13 16:16:39 +08:00
/api/nodes/{id}:
2026-04-15 14:24:39 +08:00
delete:
description: 从知识图谱中删除指定节点及其相关的所有边
parameters:
- description: 节点ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 删除成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.DeleteResponse'
2026-04-15 14:24:39 +08:00
"404":
description: 节点未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
summary: 删除节点
2026-04-13 16:16:39 +08:00
get:
description: 根据节点 ID 获取知识图谱中的节点详细信息
parameters:
2026-04-15 14:24:39 +08:00
- description: 节点 ID
in: path
name: id
required: true
type: string
2026-04-13 16:16:39 +08:00
produces:
2026-04-15 14:24:39 +08:00
- application/json
2026-04-13 16:16:39 +08:00
responses:
"200":
description: 成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.NodeResponse'
2026-04-13 16:16:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
"404":
description: 节点未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
summary: 获取节点详情
2026-04-15 14:24:39 +08:00
put:
consumes:
- application/json
description: 更新知识图谱中指定节点的信息
parameters:
- description: 节点ID
in: path
name: id
required: true
type: string
- description: 节点更新请求
in: body
name: request
required: true
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.UpdateNodeRequest'
2026-04-15 14:24:39 +08:00
produces:
- application/json
responses:
"200":
description: 更新成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.Node'
2026-04-15 14:24:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"404":
description: 节点未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-15 14:24:39 +08:00
summary: 更新节点
2026-04-13 16:16:39 +08:00
/api/nodes/{id}/neighbors:
get:
description: 根据节点 ID 获取其所有邻居节点及关联边
parameters:
2026-04-15 14:24:39 +08:00
- description: 节点 ID
in: path
name: id
required: true
type: string
2026-04-13 16:16:39 +08:00
produces:
2026-04-15 14:24:39 +08:00
- application/json
2026-04-13 16:16:39 +08:00
responses:
"200":
description: 成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.NeighborResponse'
2026-04-13 16:16:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
"404":
description: 节点未找到
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
summary: 获取节点邻居
/api/search:
get:
description: 根据关键词搜索知识图谱中的节点
parameters:
2026-04-15 14:24:39 +08:00
- description: 搜索关键词
in: query
name: q
required: true
type: string
2026-04-13 16:16:39 +08:00
produces:
2026-04-15 14:24:39 +08:00
- application/json
2026-04-13 16:16:39 +08:00
responses:
"200":
description: 成功
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.SearchResponse'
2026-04-13 16:16:39 +08:00
"400":
description: 请求错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
"500":
description: 内部错误
schema:
2026-04-15 15:19:39 +08:00
$ref: '#/definitions/model.ErrorResponse'
2026-04-13 16:16:39 +08:00
summary: 搜索节点
swagger: "2.0"