@accordproject/concerto-graph • Docs
@accordproject/concerto-graph / GraphModel
Provides typed-access to Neo4J graph database with the nodes and relationships for the graph defined using a Concerto model.
new GraphModel(
graphModels
,options
):GraphModel
Creates a new instance of GraphModel
Parameter | Type | Description |
---|---|---|
graphModels |
undefined | string [] |
an array of strings in Concerto CTO format |
options |
GraphModelOptions |
the options used to configure the instance |
Property | Type | Default value |
---|---|---|
defaultNamespace |
undefined | string |
undefined |
driver |
undefined | Driver |
undefined |
modelManager |
ModelManager |
undefined |
options |
GraphModelOptions |
undefined |
chatWithData(
text
):Promise
<object
[]>
Converts the incoming natural language query to Cypher and then runs the Cypher query.
Parameter | Type | Description |
---|---|---|
text |
string |
the input text |
Promise
<object
[]>
the query results
closeSession(
context
):Promise
<void
>
Closes a database context.
Parameter | Type | Description |
---|---|---|
context |
Context |
the database context |
Promise
<void
>
connect():
Promise
<void
>
Connects to Neo4J
Promise
<void
>
createConstraints():
Promise
<void
>
Create Neo4J constraints for the model
Promise
<void
>
createFullTextIndexes():
Promise
<void
>
Create fulltext indexes for the model
Promise
<void
>
createIndexes():
Promise
<void
>
Creates all constraints, full-text and vector indexes for the model
Promise
<void
>
createVectorIndexes():
Promise
<void
>
Create vector indexes for the model
Promise
<void
>
deleteGraph():
Promise
<void
>
Delete all nodes/edges in the graph
Promise
<void
>
deleteNode(
transaction
,typeName
,identifier
):Promise
<QueryResult
<RecordShape
>>
Deletes a node and any relationships attached to the node (DETACH DELETE)
Parameter | Type | Description |
---|---|---|
transaction |
ManagedTransaction |
the transaction |
typeName |
string |
the name of the type |
identifier |
string |
the identifier for the node |
Promise
<QueryResult
<RecordShape
>>
the result
dropIndexes():
Promise
<void
>
Drop all Neo4J indexes for the model.
Promise
<void
>
fullTextQuery(
typeName
,searchText
,count
):Promise
<object
[]>
Uses the full text index for a type to perform a full text search
Parameter | Type | Description |
---|---|---|
typeName |
string |
the type to search |
searchText |
string |
the query text |
count |
number |
the number of items to return |
Promise
<object
[]>
the items
getConcertoModels():
string
Returns the Concerto models as a string
string
the concerto models as a string
getDescription(
ns
?):undefined
|string
Returns a description of the GraphModel. The description is suppied using the '@description' decorator on the defaultNamespace
Parameter | Type | Description |
---|---|---|
ns ? |
string |
the namespace to use, defaults to the namespace of the last model file added |
undefined
| string
the description of this domain model or undefined if it is not specified
getFullTextIndexes(
notools
?):FullTextIndex
[]
Get all the full text indexes for the model
Parameter | Type | Description |
---|---|---|
notools ? |
boolean |
filter out indexes for declarations with |
decorator
getQuestions():
string
[]
Retrieves an array of questions for the graph nodes in the model. Questions are specified using the '@questions' decorator on GraphNodes.
string
[]
an array of the questions associated with all the graph nodes
getTools(
options
):RunnableToolFunction
<any
>[]
Creates OpenAI tools for the model
Parameter | Type |
---|---|
options |
ToolOptions |
RunnableToolFunction
<any
>[]
an array of OpenAI tool definitions
getVectorIndexes(
notools
?):VectorIndex
[]
Get all the vector indexes for the model
Parameter | Type | Description |
---|---|---|
notools ? |
boolean |
filter out indexes for declarations with |
decorator
loadConcertoModels():
Promise
<void
>
Clears the models in the ModelManager and then loads the models from the graph and populates the ModelManager
Promise
<void
>
mergeConcertoModels():
Promise
<void
>
Stores the Concerto Models in the graph
Promise
<void
>
promise to indicate the operation is complete
mergeNode(
transaction
,typeName
,properties
):Promise
<QueryResult
<RecordShape
>>
Merges Nodes into the graph. Note that this merges nodes based on identifier. I.e. if a node with a given identifier already exists then its properties are SET. If the node does not exist then a new node is created.
Parameter | Type | Description |
---|---|---|
transaction |
ManagedTransaction |
the transaction |
typeName |
string |
the name of the type |
properties |
PropertyBag |
the properties for the node |
Promise
<QueryResult
<RecordShape
>>
the graph node
mergeRelationship(
transaction
,sourceType
,sourceIdentifier
,targetType
,targetIdentifier
,sourcePropertyName
):Promise
<QueryResult
<RecordShape
>>
Merges a relationship into the graph
Parameter | Type | Description |
---|---|---|
transaction |
ManagedTransaction |
the transaction |
sourceType |
string |
the source node type of the relationship |
sourceIdentifier |
string |
the source identifier for the relationship |
targetType |
string |
the target node type |
targetIdentifier |
string |
the target identifier |
sourcePropertyName |
string |
the source property name |
Promise
<QueryResult
<RecordShape
>>
the source node
mergeSamplesToGraph():
Promise
<void
>
Adds sample instances of all types to the graph and creates relationships between them. Useful for visualizing the model as a graph.
Promise
<void
>
nodeExists(
type
,identifier
):Promise
<boolean
>
Checks whether a node of a given type and with a given identifier exists in the graph
Parameter | Type | Description |
---|---|---|
type |
string |
the type identifier |
identifier |
string |
the identifier of the node |
Promise
<boolean
>
true if the node exists
openSession(
database
):Promise
<Context
>
Opens a new database session. Call 'closeSession' to free resources.
Parameter | Type | Default value | Description |
---|---|---|---|
database |
string |
'neo4j' |
the name of the database. Defaults to 'neo4j'. |
Promise
<Context
>
a promise to a Context for the database.
queryConcertoModels():
Promise
<undefined
|string
[]>
Reads the concerto model from the graph. To write it use the mergeConcertoModels method.
Promise
<undefined
| string
[]>
returns the concerto model from the graph
readQuery(
cypher
,parameters
?,tx
?):Promise
<QueryResult
<RecordShape
>>
Runs a Cypher read query
Parameter | Type | Description |
---|---|---|
cypher |
string |
the Cypher query to execute |
parameters ? |
PropertyBag |
any parameters for the query |
tx ? |
ManagedTransaction |
the transaction |
Promise
<QueryResult
<RecordShape
>>
the query results
similarityQuery(
typeName
,propertyName
,searchText
,count
):Promise
<SimilarityResult
[]>
Searches for similar nodes, using a vector similarity search
Parameter | Type | Description |
---|---|---|
typeName |
string |
the name of the type |
propertyName |
string |
the property to search over |
searchText |
string |
the search text |
count |
number |
the number of items to return |
Promise
<SimilarityResult
[]>
an array of similar nodes, up to the count limit
similarityQueryFromEmbedding(
typeName
,propertyName
,embedding
,count
):Promise
<SimilarityResult
[]>
Performs a similarity search on nodes with text content
Parameter | Type | Description |
---|---|---|
typeName |
string |
the name of the type E.g. 'Clause' |
propertyName |
string |
the name of the property to search. E.g. 'content'. |
embedding |
number [] |
the embeddings for the text to search for |
count |
number |
the number of similar nodes to return |
Promise
<SimilarityResult
[]>
textToCypher(
text
):Promise
<null
|string
>
Converts a natural language query string to a Cypher query (without running it)
Parameter | Type | Description |
---|---|---|
text |
string |
the input text |
Promise
<null
| string
>
the Cypher query
writeQuery(
cypher
,parameters
?,tx
?):Promise
<QueryResult
<RecordShape
>>
Runs a Cypher write query
Parameter | Type | Description |
---|---|---|
cypher |
string |
the Cypher query to execute |
parameters ? |
PropertyBag |
any parameters for the query |
tx ? |
ManagedTransaction |
the transaction |
Promise
<QueryResult
<RecordShape
>>
the query results