GraphRAGApi
Method |
HTTP request |
Description |
|---|---|---|
POST /graph/{collection-id}/build |
Build a knowledge graph for a collection. |
|
DELETE /graph/{collection-id} |
Delete the knowledge graph for a collection. |
|
GET /graph/{collection-id} |
Read a renderable subgraph of a collection& |
|
GET /graph/{collection-id}/node |
Get full detail for one knowledge-graph node. |
|
GET /graph/{collection-id}/status |
Get graph build status for a collection. |
|
GET /graph/config |
Get GraphRAG configuration. |
|
GET /graph/{collection-id}/labels |
Search entity names in a collection& |
build_collection_graph
JobDetails build_collection_graph(collection_id, build_collection_graph_request=build_collection_graph_request)
Build a knowledge graph for a collection.
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.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.build_collection_graph_request import BuildCollectionGraphRequest
from h2ogpte.rest_async.models.job_details import JobDetails
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection ID to build the graph for.
build_collection_graph_request = h2ogpte.rest_async.BuildCollectionGraphRequest() # BuildCollectionGraphRequest | (optional)
try:
# Build a knowledge graph for a collection.
api_response = await api_instance.build_collection_graph(collection_id, build_collection_graph_request=build_collection_graph_request)
print("The response of GraphRAGApi->build_collection_graph:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->build_collection_graph: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection ID to build the graph for. |
|
build_collection_graph_request |
[optional] |
Return type
HTTP request headers
Content-Type: application/json
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
201 |
Graph build job created |
- |
400 |
Bad request |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
409 |
A graph build is already in progress for this collection. |
- |
delete_collection_graph
delete_collection_graph(collection_id)
Delete the knowledge graph for a collection.
Tears down the collection’s knowledge graph: removes the stored tarball from object storage, drops the in-memory per-collection lock and event loop, removes the local LightRAG cache directory, and resets graph_status to ‘none’. The collection itself is unaffected. Auto-RAG selection will revert to normal RAG until a new graph is built.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection whose graph should be deleted.
try:
# Delete the knowledge graph for a collection.
await api_instance.delete_collection_graph(collection_id)
except Exception as e:
print("Exception when calling GraphRAGApi->delete_collection_graph: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection whose graph should be deleted. |
Return type
void (empty response body)
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
204 |
Graph deleted successfully. |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
get_collection_graph
KnowledgeGraphData get_collection_graph(collection_id, label=label, max_depth=max_depth, max_nodes=max_nodes)
Read a renderable subgraph of a collection’s knowledge graph.
Returns nodes and edges of the knowledge graph for visualization (issue #11529). With label “*” (the default) returns the whole-graph view, degree-ranked and capped at max_nodes with is_truncated set; with a specific entity name returns the BFS neighborhood around that node (used by the viewer’s expand-on-click). Read-only; node ids (entity names) and edge (source, target) pairs are the stable addresses a future edit API will target.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.knowledge_graph_data import KnowledgeGraphData
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection whose graph to read.
label = '*' # str | Entity name to center the subgraph on, or \"*\" for the whole-graph view. (optional) (default to '*')
max_depth = 3 # int | BFS depth when label is a specific entity. (optional) (default to 3)
max_nodes = 1000 # int | Node cap for the returned subgraph (server clamps to its limit). (optional) (default to 1000)
try:
# Read a renderable subgraph of a collection's knowledge graph.
api_response = await api_instance.get_collection_graph(collection_id, label=label, max_depth=max_depth, max_nodes=max_nodes)
print("The response of GraphRAGApi->get_collection_graph:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->get_collection_graph: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection whose graph to read. |
|
label |
str |
Entity name to center the subgraph on, or "*" for the whole-graph view. |
[optional] [default to ‘*’] |
max_depth |
int |
BFS depth when label is a specific entity. |
[optional] [default to 3] |
max_nodes |
int |
Node cap for the returned subgraph (server clamps to its limit). |
[optional] [default to 1000] |
Return type
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
200 |
Successful operation |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
404 |
No knowledge graph exists for this collection. |
- |
get_collection_graph_node
KnowledgeGraphNodeDetail get_collection_graph_node(collection_id, name)
Get full detail for one knowledge-graph node.
Returns a node’s properties, its incident edges, and the source chunks (text and origin filename) that produced it, for the graph viewer’s detail panel. Source chunks are the graph’s own provenance records captured at build time.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.knowledge_graph_node_detail import KnowledgeGraphNodeDetail
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection whose graph to read.
name = 'name_example' # str | The entity name (node id) to fetch.
try:
# Get full detail for one knowledge-graph node.
api_response = await api_instance.get_collection_graph_node(collection_id, name)
print("The response of GraphRAGApi->get_collection_graph_node:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->get_collection_graph_node: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection whose graph to read. |
|
name |
str |
The entity name (node id) to fetch. |
Return type
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
200 |
Successful operation |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
404 |
No knowledge graph exists for this collection, or the node was not found. |
- |
get_collection_graph_status
GetCollectionGraphStatus200Response get_collection_graph_status(collection_id)
Get graph build status for a collection.
Returns the current knowledge graph build status and metadata.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.get_collection_graph_status200_response import GetCollectionGraphStatus200Response
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection ID to check.
try:
# Get graph build status for a collection.
api_response = await api_instance.get_collection_graph_status(collection_id)
print("The response of GraphRAGApi->get_collection_graph_status:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->get_collection_graph_status: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection ID to check. |
Return type
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
200 |
Successful operation |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
get_graph_config
GetGraphConfig200Response get_graph_config()
Get GraphRAG configuration.
Returns GraphRAG configuration including allowed LLM models for graph building.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.get_graph_config200_response import GetGraphConfig200Response
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
try:
# Get GraphRAG configuration.
api_response = await api_instance.get_graph_config()
print("The response of GraphRAGApi->get_graph_config:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->get_graph_config: %s\n" % e)
Parameters
This endpoint does not need any parameter.
Return type
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
200 |
Successful operation |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
search_collection_graph_labels
SearchCollectionGraphLabels200Response search_collection_graph_labels(collection_id, q=q, limit=limit)
Search entity names in a collection’s knowledge graph.
Fuzzy-searches entity names (node labels) for the graph viewer’s entity search. Without a query, returns the most-connected entities.
Example
Bearer Authentication (bearerAuth):
import h2ogpte.rest_async
from h2ogpte.rest_async.models.search_collection_graph_labels200_response import SearchCollectionGraphLabels200Response
from h2ogpte.rest_async.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://h2ogpte.genai.h2o.ai/api/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = h2ogpte.rest_async.Configuration(
host = "https://h2ogpte.genai.h2o.ai/api/v1"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: bearerAuth
configuration = h2ogpte.rest_async.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
# Enter a context with an instance of the API client
async with h2ogpte.rest_async.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = h2ogpte.rest_async.GraphRAGApi(api_client)
collection_id = 'collection_id_example' # str | The collection whose graph to search.
q = 'q_example' # str | Search text; empty returns the most-connected entities. (optional)
limit = 100 # int | Maximum number of labels to return. (optional) (default to 100)
try:
# Search entity names in a collection's knowledge graph.
api_response = await api_instance.search_collection_graph_labels(collection_id, q=q, limit=limit)
print("The response of GraphRAGApi->search_collection_graph_labels:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling GraphRAGApi->search_collection_graph_labels: %s\n" % e)
Parameters
Name |
Type |
Description |
Notes |
|---|---|---|---|
collection_id |
str |
The collection whose graph to search. |
|
q |
str |
Search text; empty returns the most-connected entities. |
[optional] |
limit |
int |
Maximum number of labels to return. |
[optional] [default to 100] |
Return type
HTTP request headers
Content-Type: Not defined
Accept: application/json
HTTP response details
Status code |
Description |
Response headers |
|---|---|---|
200 |
Successful operation |
- |
401 |
Unauthorized - Invalid or missing API key |
- |
403 |
Forbidden |
- |
404 |
No knowledge graph exists for this collection. |
- |