HugeGraph-LLM SDK Quick Start
hugegraph-llm-sdk is a lightweight, standalone Python SDK for programmatically designing schemas, extracting property graphs from unstructured text,
validating schemas against HugeGraph rules, and performing iterative model review and bounded repair.
Unlike the full hugegraph-llm application, the SDK is completely headless and does not require HugeGraph Server, Gradio Web UI, FastAPI, or a vector
database. Its core runtime depends only on pydantic>=2.14,<3.
Apache License 2.0 · Ask DeepWiki
Requirements and Installation
- Python:
>=3.12(tested and supported on Python 3.12, 3.13, and 3.14). - Package name:
hugegraph-llm-sdk - Import name:
hugegraph_llm_sdk
Install from source or a local wheel
The SDK is currently provided by the hugegraph-ai source tree and has not yet been published to a public package index. Install it from a checkout or a locally built wheel.
Provider Extras
Install provider extras from the same checkout:
Quick Start: Minimal Example
Here is a complete example demonstrating schema design, schema validation, and reviewed graph extraction using a custom model function:
Core API Capabilities
| Function | Signature | Description |
|---|---|---|
design_schema | (texts, *, model, questions=(), example_schema=None, prompt=None) -> SchemaDraft | Generates a candidate schema (SchemaDraft(schema, issues)) from texts and domain queries. |
adesign_schema | (texts, *, model, questions=(), example_schema=None, prompt=None) -> SchemaDraft | Asynchronous schema design variant. |
validate_schema | (schema) -> list[Issue] | Validates schema structure against HugeGraph property graph constraints without mutating the input. |
extract_graph | (texts, *, schema, model=None, model_factory=None, review=True, options=None, prompts=None, validators=()) -> ExtractionResult | Executes chunked graph extraction, validation, and review/repair loops. |
aextract_graph | (texts, *, schema, model=None, model_factory=None, review=True, options=None, prompts=None, validators=()) -> ExtractionResult | Asynchronous graph extraction variant. |
Schema Validation Rules
validate_schemainspects vertex labels, edge labels, ID strategies (DEFAULT,AUTOMATIC,PRIMARY_KEY,CUSTOMIZE_STRING,CUSTOMIZE_NUMBER,CUSTOMIZE_UUID), and property declarations.- When
propertykeysis omitted, global property definitions are not strictly checked. When a label omitsproperties, its property set is unconstrained. - An explicit empty
properties: []indicates that no properties are allowed for that label. - For edge labels,
sort_keyscannot be members ofnullable_keys. WhenfrequencyisSINGLEorDEFAULT, sort keys are disallowed;MULTIPLErequires non-empty sort keys.
Model Adapters
The SDK includes standard model adapters under hugegraph_llm_sdk.providers:
FunctionModel: Wraps any custom functiongenerate(prompt: str) -> stror asyncagenerate(prompt: str) -> str.OpenAIClient: Adapter for OpenAI and OpenAI-compatible endpoints (supportsclose()andawait aclose()).OllamaClient: Adapter for local Ollama instances.LiteLLMClient: Adapter using LiteLLM connection routing.ThreadedModel: Wraps a synchronous model so calls execute inside worker threads during async execution without blocking the event loop.
Review and Bounded Repair
By default, extraction executes an iterative review and bounded repair loop:
Review options are configured via ExtractionOptions:
Chunk and Result Statuses
- Chunk status:
final: Graph passed structural validation and model review. Onlyfinalchunks are merged intoresult.graph.candidate: Validation passed, but review budget was exhausted or review could not conclude.blocked: Graph could not pass validation within the repair budget or was explicitly rejected by review.failed: An exception or unrecoverable error occurred during execution.
- Aggregate status:
succeeded: All chunks achievedfinalstatus.partial: At least one chunk isfinal, but one or more chunks failed or remain candidate/blocked.failed: No chunk reachedfinalstatus.
Concurrency and Async Processing
When setting max_workers > 1, you must pass a stateless model_factory callable instead of a single model instance. This ensures thread-safety and
isolated model state per worker:
The SDK automatically manages the lifecycle of models created by model_factory, disposing of them when each worker batch finishes.
Relationship with HugeGraph-LLM
hugegraph-llm-sdk and hugegraph-llm reside in the same repository under separate modules:
hugegraph-llm-sdk: Embeddable library for Python pipelines, LLM agent toolchains, and data transformation scripts requiring schema design and graph extraction.hugegraph-llm: Production application service providing Web UI, REST endpoints (POST /graph/extract,POST /rag), vector index persistence, and automated ingestion into HugeGraph Server.