Skip to main content

KnowledgeGraph API

Knowledge Graph API

import { CodeBoltClient } from '@codebolt/clientsdk';

const client = new CodeBoltClient();

Quick Reference

MethodDescription
createEdgeCreates a new edge (relationship) in a knowledge graph instance.
createInstanceCreates a new knowledge graph instance.
createInstanceTemplateCreates a new knowledge graph instance template.
createRecordCreates a new record (node) in a knowledge graph instance.
createViewCreates a new view for querying a knowledge graph.
createViewTemplateCreates a new view template for knowledge graphs.
deleteEdgeDeletes an edge from a knowledge graph instance.
deleteInstanceDeletes a knowledge graph instance and all its data.
deleteInstanceTemplateDeletes a knowledge graph instance template.
deleteRecordDeletes a record from a knowledge graph instance.
deleteViewDeletes a view.
deleteViewTemplateDeletes a view template.
executeViewExecutes a view and returns the query results.
expandNodeExpands a node to reveal its immediate connections.
getInstanceRetrieves a specific knowledge graph instance by its ID.
getInstanceTemplateRetrieves a specific knowledge graph instance template by its ID.
getRecordRetrieves a specific record from a knowledge graph instance.
getSubgraphRetrieves a subgraph of a knowledge graph instance.
getViewTemplateRetrieves a specific view template by its ID.
listEdgesLists all edges in a knowledge graph instance.
listInstancesLists all knowledge graph instances.
listInstanceTemplatesLists all knowledge graph instance templates.
listRecordsLists all records in a knowledge graph instance.
listViewsLists all knowledge graph views.
listViewTemplatesLists all knowledge graph view templates.
updateInstanceTemplateUpdates a knowledge graph instance template.
updateRecordUpdates a record in a knowledge graph instance.
updateViewTemplateUpdates a view template.

Methods


createEdge

client.knowledgeGraph.createEdge(id: string, data: CreateKGEdgeRequest): Promise<KGEdge>

Creates a new edge (relationship) in a knowledge graph instance.

Edges connect two records with a typed relationship, forming the graph structure. Each edge has a source record, target record, and relationship type.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
dataCreateKGEdgeRequestYesEdge creation payload including source, target, and relationship type

Returns: Promise<KGEdge> — A promise that resolves to the newly created

Full reference →


createInstance

client.knowledgeGraph.createInstance(data: CreateKGInstanceRequest): Promise<KGInstance>

Creates a new knowledge graph instance.

Provisions an empty graph that can be populated with records and edges. Optionally created from a template to inherit schema constraints.

ParameterTypeRequiredDescription
dataCreateKGInstanceRequestYesInstance creation payload including name and optional template reference

Returns: Promise<KGInstance> — A promise that resolves to the newly created

Full reference →


createInstanceTemplate

client.knowledgeGraph.createInstanceTemplate(data: CreateKGInstanceTemplateRequest): Promise<KGInstanceTemplate>

Creates a new knowledge graph instance template.

Templates define the schema and structure for knowledge graph instances. Use templates to enforce consistent node types and edge patterns across multiple graph instances.

ParameterTypeRequiredDescription
dataCreateKGInstanceTemplateRequestYesTemplate creation payload including schema definition

Returns: Promise<KGInstanceTemplate> — A promise that resolves to the newly created

Full reference →


createRecord

client.knowledgeGraph.createRecord(id: string, data: CreateKGRecordRequest): Promise<KGRecord>

Creates a new record (node) in a knowledge graph instance.

Records represent entities or concepts in the graph. Each record has a type, properties, and can be connected to other records through edges.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
dataCreateKGRecordRequestYesRecord creation payload including type and properties

Returns: Promise<KGRecord> — A promise that resolves to the newly created

Full reference →


createView

client.knowledgeGraph.createView(data: CreateKGViewRequest): Promise<KGView>

Creates a new view for querying a knowledge graph.

Views are saved queries that extract specific subsets of graph data. They can be created from a template or with a custom query definition.

ParameterTypeRequiredDescription
dataCreateKGViewRequestYesView creation payload including query definition and target instance

Returns: Promise<KGView> — A promise that resolves to the newly created

Full reference →


createViewTemplate

client.knowledgeGraph.createViewTemplate(data: CreateKGViewTemplateRequest): Promise<KGViewTemplate>

Creates a new view template for knowledge graphs.

View templates define reusable query patterns for extracting specific subsets of graph data. They act as saved queries that can be instantiated with different parameters.

ParameterTypeRequiredDescription
dataCreateKGViewTemplateRequestYesView template creation payload including query definition

Returns: Promise<KGViewTemplate> — A promise that resolves to the newly created

Full reference →


deleteEdge

client.knowledgeGraph.deleteEdge(id: string, edgeId: string): Promise<unknown>

Deletes an edge from a knowledge graph instance.

Removes the relationship between two records. The records themselves are not affected.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
edgeIdstringYesThe unique identifier of the edge to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


deleteInstance

client.knowledgeGraph.deleteInstance(id: string): Promise<unknown>

Deletes a knowledge graph instance and all its data.

Permanently removes the instance including all records, edges, and associated views. This action cannot be undone.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the instance to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


deleteInstanceTemplate

client.knowledgeGraph.deleteInstanceTemplate(id: string): Promise<unknown>

Deletes a knowledge graph instance template.

Removes the template definition. Instances created from this template continue to exist but can no longer reference the deleted template.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the template to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


deleteRecord

client.knowledgeGraph.deleteRecord(id: string, recordId: string): Promise<unknown>

Deletes a record from a knowledge graph instance.

Removes the node and any edges connected to it. This may affect the connectivity of the graph.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
recordIdstringYesThe unique identifier of the record to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


deleteView

client.knowledgeGraph.deleteView(id: string): Promise<unknown>

Deletes a view.

Removes the saved query. The underlying graph data is not affected.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the view to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


deleteViewTemplate

client.knowledgeGraph.deleteViewTemplate(id: string): Promise<unknown>

Deletes a view template.

Removes the template definition. Views created from this template continue to exist independently.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the view template to delete

Returns: Promise<unknown> — A promise that resolves when deletion is complete

Full reference →


executeView

client.knowledgeGraph.executeView(id: string, params?: Record<string, unknown>): Promise<unknown>

Executes a view and returns the query results.

Runs the view's query against its associated graph instance and returns the matching records and edges. This is the primary way to extract data from a knowledge graph.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the view to execute
paramsRecord<string, unknown>NoOptional runtime parameters to pass to the view query

Returns: Promise<unknown> — A promise that resolves to the query results (records and edges)

Full reference →


expandNode

client.knowledgeGraph.expandNode(id: string, data: ExpandNodeRequest): Promise<unknown>

Expands a node to reveal its immediate connections.

Starting from a specific record, returns all directly connected records and the edges linking them. Useful for interactive graph exploration where users progressively reveal the graph structure.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
dataExpandNodeRequestYesExpansion parameters specifying which node to expand and direction

Returns: Promise<unknown> — A promise that resolves to the connected records and edges

Full reference →


getInstance

client.knowledgeGraph.getInstance(id: string): Promise<KGInstance>

Retrieves a specific knowledge graph instance by its ID.

Returns the full details of a graph instance including its metadata, template reference, and statistics.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance

Returns: Promise<KGInstance> — A promise that resolves to the

Full reference →


getInstanceTemplate

client.knowledgeGraph.getInstanceTemplate(id: string): Promise<KGInstanceTemplate>

Retrieves a specific knowledge graph instance template by its ID.

Returns the full template definition including its schema, node types, and edge constraints.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the instance template

Returns: Promise<KGInstanceTemplate> — A promise that resolves to the

Full reference →


getRecord

client.knowledgeGraph.getRecord(id: string, recordId: string): Promise<KGRecord>

Retrieves a specific record from a knowledge graph instance.

Returns the full record including all its properties and type information.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
recordIdstringYesThe unique identifier of the record within the instance

Returns: Promise<KGRecord> — A promise that resolves to the

Full reference →


getSubgraph

client.knowledgeGraph.getSubgraph(id: string, params?: KGSubgraphParams): Promise<unknown>

Retrieves a subgraph of a knowledge graph instance.

Returns a portion of the graph centered around specified nodes or matching certain criteria. Useful for visualizing local neighborhoods without loading the entire graph.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
paramsKGSubgraphParamsNoOptional parameters controlling subgraph scope (e.g., center node, depth)

Returns: Promise<unknown> — A promise that resolves to the subgraph data including records and edges

Full reference →


getViewTemplate

client.knowledgeGraph.getViewTemplate(id: string): Promise<KGViewTemplate>

Retrieves a specific view template by its ID.

Returns the full template definition including its query pattern and configurable parameters.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the view template

Returns: Promise<KGViewTemplate> — A promise that resolves to the

Full reference →


listEdges

client.knowledgeGraph.listEdges(id: string, params?: Record<string, unknown>): Promise<KGEdge[]>

Lists all edges in a knowledge graph instance.

Returns the relationships between records with their types and endpoint references. Use optional parameters to filter by type.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGEdge[]> — A promise that resolves to an array of objects

Full reference →


listInstances

client.knowledgeGraph.listInstances(params?: Record<string, unknown>): Promise<KGInstance[]>

Lists all knowledge graph instances.

Returns every graph instance in the system with their metadata and record/edge counts.

ParameterTypeRequiredDescription
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGInstance[]> — A promise that resolves to an array of objects

Full reference →


listInstanceTemplates

client.knowledgeGraph.listInstanceTemplates(params?: Record<string, unknown>): Promise<KGInstanceTemplate[]>

Lists all knowledge graph instance templates.

Returns every template in the system with their schema definitions and metadata.

ParameterTypeRequiredDescription
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGInstanceTemplate[]> — A promise that resolves to an array of objects

Full reference →


listRecords

client.knowledgeGraph.listRecords(id: string, params?: Record<string, unknown>): Promise<KGRecord[]>

Lists all records in a knowledge graph instance.

Returns the nodes in the graph with their types and properties. Use optional parameters to filter by type or paginate results.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGRecord[]> — A promise that resolves to an array of objects

Full reference →


listViews

client.knowledgeGraph.listViews(params?: Record<string, unknown>): Promise<KGView[]>

Lists all knowledge graph views.

Returns every view with their query definitions and associated graph instances.

ParameterTypeRequiredDescription
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGView[]> — A promise that resolves to an array of objects

Full reference →


listViewTemplates

client.knowledgeGraph.listViewTemplates(params?: Record<string, unknown>): Promise<KGViewTemplate[]>

Lists all knowledge graph view templates.

Returns every view template with their query definitions and metadata.

ParameterTypeRequiredDescription
paramsRecord<string, unknown>NoOptional query parameters for filtering or pagination

Returns: Promise<KGViewTemplate[]> — A promise that resolves to an array of objects

Full reference →


updateInstanceTemplate

client.knowledgeGraph.updateInstanceTemplate(id: string, data: UpdateKGInstanceTemplateRequest): Promise<KGInstanceTemplate>

Updates a knowledge graph instance template.

Modifies the template's schema or metadata. Existing instances created from this template are not automatically updated.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the template to update
dataUpdateKGInstanceTemplateRequestYesThe fields to update

Returns: Promise<KGInstanceTemplate> — A promise that resolves to the updated

Full reference →


updateRecord

client.knowledgeGraph.updateRecord(id: string, recordId: string, data: UpdateKGRecordRequest): Promise<KGRecord>

Updates a record in a knowledge graph instance.

Modifies the record's properties or type. Only the fields provided in the request body are updated.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the graph instance
recordIdstringYesThe unique identifier of the record to update
dataUpdateKGRecordRequestYesThe fields to update on the record

Returns: Promise<KGRecord> — A promise that resolves to the updated

Full reference →


updateViewTemplate

client.knowledgeGraph.updateViewTemplate(id: string, data: UpdateKGViewTemplateRequest): Promise<KGViewTemplate>

Updates a view template.

Modifies the template's query definition or metadata. Existing views created from this template are not automatically updated.

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the view template to update
dataUpdateKGViewTemplateRequestYesThe fields to update

Returns: Promise<KGViewTemplate> — A promise that resolves to the updated

Full reference →