This is the multi-page printable view of this section. .
HugeGraph-AI
- 1: HugeGraph-LLM
- 2: HugeGraph-ML
- 3: HugeGraph-LLM Workflow
- 4: Configuration Reference
- 5: HugeGraph-LLM REST API
hugegraph-ai provides Python clients for HugeGraph, graph machine learning tools, and LLM tools for knowledge graph construction and GraphRAG applications.
Apache License 2.0 · Ask DeepWiki
Modules
- hugegraph-llm: knowledge graph construction, GraphRAG, and natural-language graph queries.
- hugegraph-ml: reads graph data from HugeGraph and runs graph learning models.
- hugegraph-python-client: a Python SDK for managing schemas and graph data and running Gremlin queries.
- vermeer-python-client: a Python SDK for the Vermeer graph computing service.
The repository uses a uv workspace to manage the LLM and Python client packages. HugeGraph-ML is a path dependency rather than a workspace member.
Requirements
- HugeGraph-LLM: Python 3.10 or 3.11
- HugeGraph-ML and the Python clients: Python 3.10 or later
uv0.7 or later- HugeGraph Server 1.5 or later
Deploy with Docker Compose
The repository includes a Compose file that starts both HugeGraph Server and the RAG service:
Default addresses:
- HugeGraph Server:
http://localhost:8080 - RAG service and Web UI:
http://localhost:8001
Start the RAG Service from Source
uv sync creates .venv at the repository root. Do not create a separate environment under hugegraph-llm, because doing so can bypass the dependencies locked by the workspace.
Install ML Dependencies
Example scripts are under hugegraph-ml/src/hugegraph_ml/examples/.
Next Steps
1 - HugeGraph-LLM
HugeGraph-LLM connects graph databases with large language models for knowledge graph construction, GraphRAG, and natural-language graph queries. Its demo service hosts the Gradio UI and FastAPI endpoints in the same process and listens on port 8001 by default.
Requirements
AI-generated project documentation: Ask DeepWiki
- Python 3.10 or 3.11
uv0.7 or later- HugeGraph Server 1.5 or later
Deploy with Docker Compose
Prepare the environment files from the HugeGraph-AI repository root:
After startup, HugeGraph Server is available at http://localhost:8080, and the RAG service and Web UI are available at http://localhost:8001.
Start from Source
Install dependencies through the workspace at the repository root:
To use a custom address and port:
The service stores model, HugeGraph, and login settings in hugegraph-llm/.env. Prompts are stored separately in hugegraph-llm/src/hugegraph_llm/resources/demo/config_prompt.yaml. The configuration code creates missing files with default values.
Main Capabilities
Build RAG Indexes
The first Web UI tab splits text into a chunk vector index, extracts vertices and edges according to a schema, writes the graph to HugeGraph, and updates the vertex vector index. The schema can be inline JSON or the name of an existing graph. Through the REST API, a graph name requires a matching client_config.graph; inline JSON neither connects to HugeGraph nor accepts client_config.
GraphRAG
The query pipeline can combine direct LLM answers, chunk-vector retrieval, and graph retrieval. Graph retrieval first extracts keywords and matches vertices, then attempts Text2Gremlin. If generation or execution fails, it can fall back to predefined graph traversals. Request parameters control result limits, vector distance thresholds, template counts, and reranking.

Text2Gremlin
POST /text2gremlin generates Gremlin from natural language, the graph schema, and optional examples. A custom prompt must retain {query}, {schema}, {example}, and {vertices}.
Models and Vector Backends
Chat, information extraction, and Text2Gremlin can independently use an OpenAI-compatible endpoint, Ollama, or LiteLLM. The embedding model is configured separately. FAISS is the default vector index; Milvus or Qdrant are available after installing the optional dependencies:
See the configuration reference and REST API for details.
Development Checks
2 - HugeGraph-ML
HugeGraph-ML reads graph data from HugeGraph and converts it to DGL graphs for tasks such as node embedding, node classification, and graph classification. Model implementations are under hugegraph-ml/src/hugegraph_ml/models/.
Requirements
- Python 3.10 or later
- HugeGraph Server 1.0 or later; 1.5 or later is recommended
uv0.7 or later
Installation
HugeGraph-ML is a path dependency of the root project but is not a uv workspace member. Select the ml extra at the repository root instead of creating another lock file in the subdirectory.
Implemented Models
The current README lists these models:
| Models | Main purpose |
|---|---|
| AGNN, APPNP, ARMA, Cluster-GCN, DAGNN, DeeperGCN, GRAND, JKNet | Node classification |
| BGNN, CARE-GNN | Fraud detection |
| BGRL, DGI, GRACE | Representation learning |
| DiffPool | Graph classification |
| GATNE, P-GNN, SEAL | Link prediction or network embedding |
| C&S | Correction and smoothing of predictions |
The source also includes GIN for graph classification and MLPClassifier for downstream classification. The model count changes between versions; use src/hugegraph_ml/models/ as the authoritative list.
DGI Node Embedding Example
First import DGL’s Cora dataset into HugeGraph:
Read the graph and train DGI:
The complete script is hugegraph-ml/src/hugegraph_ml/examples/dgi_example.py.
GRAND Node Classification Example
The complete script is hugegraph-ml/src/hugegraph_ml/examples/grand_example.py.
Troubleshooting
- Connection failures: check the HugeGraph Server address, port, and credentials.
- Schema mismatches: the examples use
CORA_vertexandCORA_edge; pass the actual labels for your own data. - DGL or PyTorch import failures: rerun
uv sync --extra mlfrom the repository root and confirm that Python comes from the root.venv.
3 - HugeGraph-LLM Workflow
This page explains the processing flow in the HugeGraph-LLM Web UI. See HugeGraph-LLM for startup instructions.
1. Build RAG Indexes
The first tab splits documents into a chunk vector index. It also extracts vertices and edges according to a schema, writes them to HugeGraph, and maintains a vertex vector index.
flowchart TD
A[Input document] --> B[Split text]
B --> C[Generate chunk vectors]
C --> D[Write vector index]
B --> E[LLM extracts vertices and edges from schema]
E --> F[Write to HugeGraph]
F --> G[Update vertex vector index]Common operations are Import into Vector, Extract Graph Data, Load into GraphDB, and Update Vid Embedding. The page can also inspect or clear chunk indexes, vertex indexes, and graph data. Clearing removes existing data, so first confirm that the current graph and indexes are not still used by other queries.
2. GraphRAG Queries
The second tab can answer directly with the LLM, use only chunk-vector retrieval, use only graph retrieval, or combine graph and vector retrieval.
flowchart TD
Q[Question] --> V[Query chunk vector index]
Q --> K[Extract keywords]
K --> M[Match graph vertices]
M --> T[Generate and execute Gremlin]
T -->|Failure| B[Fallback to BFS graph traversal]
T --> R[Prepare graph results]
B --> R
V --> S[Merge and rerank]
R --> S
S --> A[Generate answer]Graph retrieval first matches HugeGraph vertices exactly by keyword and then uses vector similarity if no exact match exists. The matched vertices are passed to Text2Gremlin. If generation or execution fails, the pipeline can fall back to a predefined traversal.
Template Num controls how many examples Text2Gremlin uses. A value less than or equal to zero supplies no templates; a positive value retrieves that many similar examples.
3. Text2Gremlin
The third tab reads the graph schema, retrieves similar natural-language and Gremlin examples, fills the prompt with the question, schema, examples, and matched vertices, then generates Gremlin and optionally executes it.

A custom prompt must contain {query}, {schema}, {example}, and {vertices}. The REST API rejects a request if any placeholder is missing.
4. Graph and Administration Tools
Graph Tools runs graph operations directly. Admin Tools provides functions such as log access. When login is enabled, the UI and APIs require USER_TOKEN; the log endpoint additionally requires a separately configured, secure ADMIN_TOKEN.

5. Prompt Language
Set LANGUAGE=EN or LANGUAGE=CN in hugegraph-llm/.env, then restart the service. This selects the language of built-in prompts; it does not translate input documents and is not a field in the /rag request body.
6. REST Calls
The Web UI and REST API use the same pipeline. For application integration, use /rag, /rag/graph, /graph/extract, and /text2gremlin; see the REST API for request formats.
4 - Configuration Reference
HugeGraph-LLM reads runtime settings from hugegraph-llm/.env. Prompts are stored separately in hugegraph-llm/src/hugegraph_llm/resources/demo/config_prompt.yaml and are not written to .env.
Create or update the files from configuration-class defaults with:
.env contains keys and passwords. Do not commit it to version control.
Basic Options
| Setting | Default | Description |
|---|---|---|
LANGUAGE | EN | Prompt language: EN or CN |
CHAT_LLM_TYPE | openai | Answer model: openai, litellm, or ollama/local |
EXTRACT_LLM_TYPE | openai | Information extraction model; same choices as above |
TEXT2GQL_LLM_TYPE | openai | Text2Gremlin model; same choices as above |
EMBEDDING_TYPE | openai | Embedding model; same choices as above, or empty |
RERANKER_TYPE | empty | cohere or siliconflow |
KEYWORD_EXTRACT_TYPE | llm | llm, textrank, or hybrid |
WINDOW_SIZE | 3 | TextRank window size, from 1 to 10 |
HYBRID_LLM_WEIGHTS | 0.5 | Weight of LLM results in hybrid mode, from 0 to 1 |
OpenAI-Compatible APIs
Chat, extraction, and Text2Gremlin can use different endpoints, keys, and models.
| Purpose | API base | Key | Model | Default maximum tokens |
|---|---|---|---|---|
| Answer | OPENAI_CHAT_API_BASE | OPENAI_CHAT_API_KEY | OPENAI_CHAT_LANGUAGE_MODEL | OPENAI_CHAT_TOKENS=8192 |
| Extraction | OPENAI_EXTRACT_API_BASE | OPENAI_EXTRACT_API_KEY | OPENAI_EXTRACT_LANGUAGE_MODEL | OPENAI_EXTRACT_TOKENS=256 |
| Text2Gremlin | OPENAI_TEXT2GQL_API_BASE | OPENAI_TEXT2GQL_API_KEY | OPENAI_TEXT2GQL_LANGUAGE_MODEL | OPENAI_TEXT2GQL_TOKENS=4096 |
| Embedding | OPENAI_EMBEDDING_API_BASE | OPENAI_EMBEDDING_API_KEY | OPENAI_EMBEDDING_MODEL | Not applicable |
The default API base is https://api.openai.com/v1. The default language model for all three tasks is gpt-4.1-mini, and the default embedding model is text-embedding-3-small.
OPENAI_BASE_URL and OPENAI_API_KEY provide general fallback values. Embeddings also support OPENAI_EMBEDDING_BASE_URL and OPENAI_EMBEDDING_API_KEY as fallback values.
LiteLLM
| Purpose | API base | Key | Model | Default maximum tokens |
|---|---|---|---|---|
| Answer | LITELLM_CHAT_API_BASE | LITELLM_CHAT_API_KEY | LITELLM_CHAT_LANGUAGE_MODEL | LITELLM_CHAT_TOKENS=8192 |
| Extraction | LITELLM_EXTRACT_API_BASE | LITELLM_EXTRACT_API_KEY | LITELLM_EXTRACT_LANGUAGE_MODEL | LITELLM_EXTRACT_TOKENS=256 |
| Text2Gremlin | LITELLM_TEXT2GQL_API_BASE | LITELLM_TEXT2GQL_API_KEY | LITELLM_TEXT2GQL_LANGUAGE_MODEL | LITELLM_TEXT2GQL_TOKENS=4096 |
| Embedding | LITELLM_EMBEDDING_API_BASE | LITELLM_EMBEDDING_API_KEY | LITELLM_EMBEDDING_MODEL | Not applicable |
The default language model is openai/gpt-4.1-mini, and the default embedding model is openai/text-embedding-3-small. Model names generally use the provider/model form; supported values depend on the LiteLLM service.
Ollama
| Purpose | Host | Port | Model |
|---|---|---|---|
| Answer | OLLAMA_CHAT_HOST | OLLAMA_CHAT_PORT | OLLAMA_CHAT_LANGUAGE_MODEL |
| Extraction | OLLAMA_EXTRACT_HOST | OLLAMA_EXTRACT_PORT | OLLAMA_EXTRACT_LANGUAGE_MODEL |
| Text2Gremlin | OLLAMA_TEXT2GQL_HOST | OLLAMA_TEXT2GQL_PORT | OLLAMA_TEXT2GQL_LANGUAGE_MODEL |
| Embedding | OLLAMA_EMBEDDING_HOST | OLLAMA_EMBEDDING_PORT | OLLAMA_EMBEDDING_MODEL |
The default host is 127.0.0.1 and the default port is 11434. Model names have no defaults; pull the required models in Ollama before use.
Reranking
| Setting | Default | Description |
|---|---|---|
COHERE_BASE_URL | https://api.cohere.com/v1/rerank | Cohere rerank endpoint; CO_API_URL is a fallback |
RERANKER_API_KEY | empty | Cohere or SiliconFlow key |
RERANKER_MODEL | empty | Model name supported by the service |
HugeGraph Connection and Retrieval Limits
| Setting | Default | Description |
|---|---|---|
GRAPH_URL | 127.0.0.1:8080 | HugeGraph address; it is not split into IP and port |
GRAPH_NAME | hugegraph | Graph name |
GRAPH_USER | admin | User name |
GRAPH_PWD | xxx | Password |
GRAPH_SPACE | empty | GraphSpace name |
LIMIT_PROPERTY | False | Whether to limit returned properties; read as a string by the configuration class |
MAX_GRAPH_PATH | 10 | Maximum graph path length |
MAX_GRAPH_ITEMS | 30 | Maximum number of graph retrieval items |
EDGE_LIMIT_PRE_LABEL | 8 | Result limit for each edge label |
VECTOR_DIS_THRESHOLD | 0.9 | Results beyond this vector-distance threshold are ignored |
TOPK_PER_KEYWORD | 1 | Candidates per keyword |
TOPK_RETURN_RESULTS | 20 | Results returned after reranking |
External Vector Databases
The default implementation can use local FAISS. After enabling optional dependencies, the following settings are also available:
| Setting | Default |
|---|---|
QDRANT_HOST | empty |
QDRANT_PORT | 6333 |
QDRANT_API_KEY | empty |
MILVUS_HOST | empty |
MILVUS_PORT | 19530 |
MILVUS_USER | empty |
MILVUS_PASSWORD | empty |
Login and Log API
| Setting | Default | Description |
|---|---|---|
ENABLE_LOGIN | False | Whether to require a Bearer token; read as a string by the configuration class |
USER_TOKEN | 4321 | Token for the Web UI and regular APIs |
ADMIN_TOKEN | xxxx | Administrator token used by /logs |
/logs returns 403 when ADMIN_TOKEN is empty or still set to xxxx. Replace both the user and administrator tokens in production.
Minimal OpenAI Configuration
Configuration Loading
Configuration classes supply code defaults and then apply overrides from .env and the process environment. The Web UI and configuration APIs can update current settings at runtime and write supported fields back to .env. Restart the service after editing .env manually; prompt YAML can be refreshed by the page-loading logic.
Configuration definitions are in:
hugegraph-llm/src/hugegraph_llm/config/llm_config.pyhugegraph-llm/src/hugegraph_llm/config/hugegraph_config.pyhugegraph-llm/src/hugegraph_llm/config/admin_config.pyhugegraph-llm/src/hugegraph_llm/config/prompt_config.py
5 - HugeGraph-LLM REST API
The HugeGraph-LLM demo process serves both the Web UI and REST API. The default address is http://localhost:8001:
Authentication
Enable login in .env:
Requests then require a Bearer token:
RAG
POST /rag
Returns one or more answer types according to the switches. When none is explicitly selected, only graph_only is enabled.
The response contains only enabled answer fields:
Other optional parameters include graph_ratio, rerank_method (bleu or reranker), near_neighbor_first, custom_priority_info, and three custom prompt fields.
POST /rag/graph
Runs graph retrieval without generating a final natural-language answer:
graph_recall in the response can contain keywords, match_vids, gremlin, graph_result, and vertex_degree_list. Set get_vertex_only=true to return immediately after vertex matching.
Graph Extraction
POST /graph/extract
An inline schema does not connect to HugeGraph:
texts can be a string or an array of strings. language accepts zh or en; split_type accepts document, paragraph, or sentence.
When schema is an existing graph name, also pass client_config, and make client_config.graph match that name:
A successful response always contains status, result.vertices, result.edges, warnings, and meta.
Text2Gremlin
POST /text2gremlin
output_types can contain:
match_resulttemplate_gremlinraw_gremlintemplate_execution_resultraw_execution_result
If omitted, only template_gremlin is returned by default. An empty array lets the implementation return all outputs. A custom gremlin_prompt must contain {query}, {schema}, {example}, and {vertices}.
Runtime Configuration
POST /config/graph
POST /config/llm and POST /config/embedding
Both endpoints use the same request model. OpenAI or LiteLLM example:
Ollama requests still require the common fields; api_key and api_base can be empty strings:
POST /config/rerank
reranker_type accepts cohere or siliconflow. Cohere also accepts cohere_base_url.
These endpoints change the process’s active configuration and may write values back to .env. client_config in /rag, /rag/graph, and /text2gremlin overrides the HugeGraph connection for one request. The current implementation still changes process-global settings temporarily, so do not issue long-running requests with different connections concurrently.
Logs
POST /logs
This endpoint requires ADMIN_TOKEN in .env to be changed to a secure value. Example request body:
log_file must be a file name under logs/ and cannot contain path separators.