CREATE_KNOWLEDGE_GRAPH

Use the DBMS_AI_GRAPHRAG.CREATE_KNOWLEDGE_GRAPH procedure to create a knowledge graph from a source and configures graph extraction and retrieval.

Purpose

This procedure processes the source text, extracts graph components, and creates the data used for retrieval.

Syntax

DBMS_AI_GRAPHRAG.CREATE_KNOWLEDGE_GRAPH (
    kg_name               IN VARCHAR2,
    source_name           IN VARCHAR2,
    source_column         IN VARCHAR2,
    graph_type            IN VARCHAR2,
    params                IN JSON,
    dml_maintenance       IN BOOLEAN DEFAULT FALSE,
    model_failure_policy  IN VARCHAR2 DEFAULT 'ABORT',
    resume                IN BOOLEAN DEFAULT FALSE
);

Parameters

Parameter Description
kg_name Name of the knowledge graph.
source_name Name of the source. The source can be a table or a view. DML maintenance is supported only for tables; for views, dml_maintenance must be FALSE.
source_column Name of the column that contains the source text.
graph_type Graph type. Valid values are TEXTUAL and NON_TEXTUAL. The default is NON_TEXTUAL. Textual graphs include generated descriptions for graph components; non-textual graphs do not.
params JSON object that configures LLM generation, embeddings, chunking, vector indexing, and related options.
dml_maintenance Enables DML-based graph maintenance. The default is FALSE.
model_failure_policy Specifies how to handle model call failures during graph creation:
- 'ABORT' (default): Stops graph creation and reports an error when a model call fails after applicable retries. Previously completed work is retained. After resolving the cause, call CREATE_KNOWLEDGE_GRAPH with resume => TRUE to resume creation.
- 'CONTINUE': Records the failure and continues processing other graph items.
resume Specifies whether to resume a previous knowledge graph creation attempt (TRUE) or create a new knowledge graph (FALSE, the default). The operation fails if a graph with the specified name already exists.

The params object supports the following fields:

Field Description
llm_generate_params (Required) LLM configuration for extraction and summarization, using the UTL_TO_GENERATE_TEXT parameter format.
embedding_params (Required) Embedding configuration, using the UTL_TO_EMBEDDINGS parameter format.
chunk_params (Optional) Chunking configuration, using the UTL_TO_CHUNKS parameter format.
vector_index_params (Optional) Vector index configuration. If omitted, HNSW is used with default parameters.
language (Optional) Language value included in the extraction prompt.
prompt_language (Optional) Language for the prompt.
entity_type_list (Optional) List of entity types to guide extraction.
llm_request_params (Optional) LLM request settings:
- max_concurrent_requests: Maximum parallel LLM calls. Default: 15.
- max_retries: Maximum number of retries for failed LLM calls. Default: 5.
- rate_per_minute: Maximum requests per minute. Default: NULL.
- use_llm_cache: Whether to save outputs to an LLM cache table for later use. Default: FALSE.
dml_repeat_interval (Optional) Interval for the asynchronous DML worker.
summary_character_limit (Optional) Character limit for summaries. The default is 2000. For textual graphs, content that exceeds the limit is summarized with an LLM.
summary_prompt_character_limit (Optional) Character limit for the prompt sent to the LLM for summarization. The default is 2000.

Example

This example creates a textual knowledge graph from the BOOKS table using OCI Generative AI for text generation and embeddings.

BEGIN
    DBMS_AI_GRAPHRAG.CREATE_KNOWLEDGE_GRAPH(
        kg_name       => 'BOOKS_KG',
        source_name   => 'BOOKS',
        source_column => 'CONTENT',
        graph_type    => 'TEXTUAL',
        params        => JSON('{
            "chunk_params": {
                "by": "words",
                "max": "300",
                "overlap": "0",
                "split": "recursively",
                "normalize": "all"
            },
            "llm_generate_params": {
                "provider": "ocigenai",
                "credential_name": "OCI_CRED",
                "url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat",
                "model": "meta.llama-3.3-70b-instruct"
            },
            "embedding_params": {
                "provider": "ocigenai",
                "credential_name": "OCI_CRED",
                "url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/embedText",
                "model": "cohere.embed-v4.0"
            }
        }')
    );
END;
/