---
title: "Build a knowledge graph for a collection."
method: POST
path: "/graph/{collection_id}/build"
tags: ["GraphRAG"]
---

# Build a knowledge graph for a collection.

`POST /graph/{collection_id}/build`

## Request

- Base URL: `https://h2ogpte.genai.h2o.ai/api/v1`
- URL: `https://h2ogpte.genai.h2o.ai/api/v1/graph/{collection_id}/build`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/h2o/apis/h2ogpte-rest-api/docs/graph/:collection_id/build/post.ts> (a function with typed inputs; its response is checked against the schema)

Triggers an asynchronous job that extracts entities and relationships from document chunks to build a knowledge graph using LightRAG. Returns 409 Conflict if a build is already in progress.

## Path parameters

- `collection_id` string, uuid, required

## Request body

- object
  - `llm` union: LLM to use for entity extraction. Defaults to the system default.
    - string
    - integer
  - `force_rebuild` boolean: If true, removes any existing graph and rebuilds from scratch.
  - `name` string: Optional job name override.

## Response `201`

Graph build job created

- JobDetails
  - `id` string, required
  - `name` string, required
  - `overall_status` 'in progress' | 'completed' | 'failed' | 'canceled', required
  - `status` string
  - `passed_percentage` number, double, required
  - `failed_percentage` number, double, required
  - `progress` number, double, required
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `kind` string, required
  - `statuses` JobDetailsStatus[], required
    - `id` string, required
    - `status` string, required
  - `errors` string[], required
  - `duration` string, required
  - `duration_seconds` number, double, required
  - `canceled_by` string
  - `cancel_reason` string
  - `timeout` number, double
  - `start_time` number, double
  - `files_total` integer
  - `files_failed` integer

## Other responses

- `400`: Bad request
- `401`: Unauthorized - Invalid or missing API key
- `403`: Forbidden
- `409`: A graph build is already in progress for this collection.
- `default`: Unexpected error

---

[API](https://skmtc.dev/h2o/apis/h2ogpte-rest-api.md) - [All operations](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/revisions/a82a117320f4?raw)
