Graph Class
The .NET client for a Curiosity Workspace. A Graph opens an authenticated
connection, queues node and edge writes locally, and flushes them to the server
on commit. Obtain an instance with one of the Connect factory methods and wrap
it in using so pending work flushes and the connection closes cleanly.
public partial class GraphRepresents a connection to a remote graph database.
- Namespace
- Curiosity.Library
Methods
| Name | Description |
|---|---|
| Connect | Connects to the graph database using the specified endpoint, token, and connector name. |
| WithLoggingFactory | Sets the logging factory for the graph instance. |
| WithTimeout | Sets the timeout for the graph instance. |
| WithDryRun | Sets the dry run mode for the graph instance. |
| InitializeAccessControlAsync | Initializes access control asynchronously. |
| CacheAccessControlAsync | Caches access control asynchronously. |
| ListenToWebSocketMessages | Listens to WebSocket messages. |
| SetAutoCommitCost | Sets the auto-commit cost for the graph instance. |
| CommitPendingAsync | Commits any pending operations asynchronously. |
| Close | Closes the graph instance. |
| Dispose | Disposes the graph instance. |
| PauseIndexing | Pauses indexing asynchronously. Useful for large data ingestions. |
| ResumeIndexing | Resumes indexing asynchronously. |
| CreateEdgeSchemaAsync | Creates one or more edges types asynchronously. |
| CreateNodeSchemaAsync<T> | Creates a node schema asynchronously based on a class definition. |
| GetNodeSchemaAsync | Creates a node schema asynchronously. |
| AddOrUpdate | Adds or updates a node. |
| TryAdd | Tries to add a node if it doesn't exist yet. |
| Update | Updates a node. |
| Delete | Deletes a node. |
| ToNode<T> | Resolves a strongly-typed node instance to its Node key representation using the registered schema mapping. |
| AddOrUpdateWithOwnership | Adds or updates a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| TryAddWithOwnership | Attempts to add a node if it doesn't exist yet, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| Link | Creates a relationship (edge) between two nodes in the graph using the specified edge type. |
| Unlink | Removes an edge of the specified type from one node to another in the graph. |
| UnlinkExcept | Removes all edges of the specified type originating from the source node (`from`) except those connecting to the `except` node. |
| AddAlias | Adds an alias to a node in the graph database for the specified language. |
| RemoveAlias | Removes a single alias from a node in the graph database for the specified language. |
| ClearAliases | Clears all aliases associated with the specified node in the graph. |
| FetchFolderContentAsync | Fetches the content of a folder from the graph database based on the provided folder name, source name, and URI. |
| CreateUserAsync | Asynchronously creates a new user node in the graph database with the specified details. |
| CreateTeamAsync | Creates a new team in the graph database with the specified name and optional description. |
| CreateFolderAsync | Creates a folder node in the graph database with specified properties. |
| CreateContact | Creates a new contact node with the specified email, first name, and last name. |
| CreateOrganization | Creates a new organization node in the graph database using the given domain as a unique identifier. |
| CreateWebPage | Creates a web page node in the graph with the provided attributes. |
| CheckPermissionsChanged | Checks whether the permissions of the specified file have been changed. |
| MapPermissionsAsync | Maps file access permissions in the graph database for the specified file path and file node. |
| UploadFileAndPermissionsAsync | Uploads a file to the graph database and sets up permissions by mapping it to a graph node. |
| UploadFileAsync | Uploads a file to the graph database and associates it with the specified source. Retries the operation until successful or the defined timeout elapses. |
| UploadFileWithIdentifierAsync | Uploads a file to the graph database with a unique identifier, associating metadata such as filename and source. |
| UploadFileToFolderAsync | Uploads a file to a specified folder in the graph database. |
| GetFileHash | Compute a SHA256 hash for a given input stream file. The stream will be rewinded before and after computing the hash. |
| TryGetFileNodeAsync | Try getting the file node after checking if it exists in the graph, and optionally checking if the SHA256 hash is the same |
| DeleteFileAsync | Deletes a file from the specified source in the graph database. |
| DeleteFolderAsync | Deletes a folder from the graph database using the specified path and source name. |
| MarkFileAsPrivate | Marks the specified file node as private by removing the public access edge. |
| MarkFolderAsPrivate | Marks a folder node as private by removing its association with the public access group. |
| AddUserToTeam | Adds a user node to a team node by creating a unique membership relationship between them. |
| AddAdminToTeam | Adds a user as an admin to a specified team, creating appropriate edges in the graph database. |
| RemoveAdminFromTeam | Removes a user's admin rights on a team by removing the admin edges, while leaving the user's membership intact. |
| RemoveUserFromTeam | Removes a user from a team by removing all relevant edges between the user node and team node. |
| RestrictAccessToTeam | Restricts access to a specific node by associating it with a team access group node. |
| RemoveAccessFromTeam | Removes a team access group as an owner of the specified node, revoking the access previously granted by RestrictAccessToTeam. |
| RestrictAccessToUser | Restricts access to the specified node by associating it with a user node as its owner. Creates a bidirectional ownership relationship between the node and the user node. |
| RemoveAccessFromUser | Removes a user as an owner of the specified node, revoking the access previously granted by RestrictAccessToUser. |
| ClearPermissions | Clears the permissions of the specified node, with an optional exception for specific owner nodes. |
| LogAsync | Logs a message asynchronously to the graph's logging system. |
| LogManyAsync | Logs a message asynchronously to the graph's logging system. |
| MapAsync | Retrieves a mapping of nodes to a specified field value for a given node type in the graph database, paged asynchronously. |
| UploadNewApplicationInterfaceAsync | Uploads a new application interface to the system from the specified folder contents. |
| QueryAsync | Executes a query against the graph database asynchronously. |
| ClearEmbeddingsIndexAsync | Clears the embeddings index for the specified index UID in the graph database. |
| AddEmbeddingsToIndexAsync | Adds a collection of node embeddings to the specified index in batches. |
| ExportWorkspaceDefinitionAsync | Exports workspace configuration |
| ImportWorkspaceDefinitionsAsync | Imports workspace configuration |
| Overload | |
|---|---|
| Connect(string, string, string, HttpClientHandler) | Connects to the graph database using the specified endpoint, token, and connector name. |
| Connect(string, X509Certificate, string, HttpClientHandler) | Connects to the graph database using the specified endpoint, token, and connector name. |
Connect(string, string, string, HttpClientHandler)
public static Graph Connect(string endpoint, string token, string connectorName, HttpClientHandler clientHandler = null)Connects to the graph database using the specified endpoint, token, and connector name.
Parameters
- endpoint string
- The endpoint URL of the graph database.
- token string
- The authentication token.
- connectorName string
- The name of the connector.
- clientHandler HttpClientHandler
- Optional HTTP client handler.
Returns
A new instance of the Graph class.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
Connect(string, X509Certificate, string, HttpClientHandler)
public static Graph Connect(string endpoint, X509Certificate clientCertificate, string connectorName, HttpClientHandler clientHandler = null)Connects to the graph database using the specified endpoint, token, and connector name.
Parameters
- endpoint string
- The endpoint URL of the graph database.
- clientCertificate X509Certificate
- connectorName string
- The name of the connector.
- clientHandler HttpClientHandler
- Optional HTTP client handler.
Returns
A new instance of the Graph class.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
public Graph WithLoggingFactory(ILoggerFactory loggerFactory)Sets the logging factory for the graph instance.
Parameters
- loggerFactory
- The logger factory.
Returns
The current Graph instance.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector")
.WithLoggingFactory(loggerFactory);
public Graph WithTimeout(TimeSpan timeout)Sets the timeout for the graph instance.
Parameters
- timeout
- The timeout duration.
Returns
The current Graph instance.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector")
.WithTimeout(TimeSpan.FromSeconds(30));
public Graph WithDryRun(bool dryRun = true)Sets the dry run mode for the graph instance.
Parameters
- dryRun
- Whether to enable dry run mode.
Returns
The current Graph instance.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector")
.WithDryRun(true);
public async Task InitializeAccessControlAsync(string cachePath)Initializes access control asynchronously.
Parameters
- cachePath
- The path to the cache file.
Returns
A task representing the asynchronous operation.
Examples
await graph.InitializeAccessControlAsync("path/to/cache");
public async Task CacheAccessControlAsync()Caches access control asynchronously.
Returns
A task representing the asynchronous operation.
Examples
await graph.CacheAccessControlAsync();
public void ListenToWebSocketMessages(Func<string, Task<string>> handleMessage, Action<ClientWebSocket> configureClient = null, CancellationToken cancellationToken = default)Listens to WebSocket messages.
Parameters
- handleMessage
- The function to handle incoming messages.
- cancellationToken
- Optional cancellation token.
Examples
graph.ListenToWebSocketMessages(async message => {
// Handle the message
return "response";
});
public Graph SetAutoCommitCost(int everyNodes, int everyEdges = 0)Sets the auto-commit cost for the graph instance.
Parameters
- everyNodes
- The number of nodes after which to auto-commit.
- everyEdges
- The number of edges after which to auto-commit.
Returns
The current Graph instance.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector")
.SetAutoCommitCost(100, 50);
public async Task CommitPendingAsync()Commits any pending operations asynchronously.
Returns
A task representing the asynchronous operation.
Examples
await graph.CommitPendingAsync();
public async Task PauseIndexing(string pauseName)Pauses indexing asynchronously. Useful for large data ingestions.
Parameters
- pauseName
- The name of the pause.
Returns
A task representing the asynchronous operation.
Examples
await graph.PauseIndexing("pause1");
public async Task ResumeIndexing(string pauseName)Resumes indexing asynchronously.
Parameters
- pauseName
- The name of the pause.
Returns
A task representing the asynchronous operation.
Examples
await graph.ResumeIndexing("pause1");
| Overload | |
|---|---|
| CreateEdgeSchemaAsync(string[]) | Creates one or more edges types asynchronously. |
| CreateEdgeSchemaAsync(Type) | Asynchronously creates an edge schema based on the provided static class containing edge type definitions. |
CreateEdgeSchemaAsync(string[])
public async Task CreateEdgeSchemaAsync(params string[] edges)Creates one or more edges types asynchronously.
Parameters
- edges string[]
- The names of the edges to create.
Returns
A task representing the asynchronous operation.
Examples
await graph.CreateEdgeSchemaAsync("HasAuthor", "AuthorOf");
CreateEdgeSchemaAsync(Type)
public async Task CreateEdgeSchemaAsync(Type staticEdgesClass)Asynchronously creates an edge schema based on the provided static class containing edge type definitions.
Parameters
- staticEdgesClass Type
- The static class containing public constant string fields representing edge types.
Returns
A task that represents the asynchronous operation.
Exceptions
- ArgumentNullException
- Thrown when
staticEdgesClassis null. - ArgumentException
- Thrown when
staticEdgesClassis not a static class.
Remarks
This method extracts all public constant string fields from the specified static class and uses them as edge type definitions. If no valid edge types are found, no schema is created.
Examples
public static class Edges
{
public const string HasPart = nameof(HasPart);
public const string PartOf = nameof(PartOf);
}
//Call with:
await graph.CreateEdgeSchemaAsync(typeof(Edges));
public Task CreateNodeSchemaAsync<T>(bool overwrite = false) where T : classCreates a node schema asynchronously based on a class definition.
Type Parameters
- T
- The type of the node.
Parameters
- overwrite
- Whether to overwrite the existing schema.
Returns
A task representing the asynchronous operation.
Examples
[Node]
public class Author
{
[Key] public string Name { get; set; }
}
await graph.CreateNodeSchemaAsync
public async Task<NodeSchema> GetNodeSchemaAsync(string nodeType)Creates a node schema asynchronously.
Parameters
- schema
- The schema to create.
- overwrite
- Whether to overwrite the existing schema.
Returns
A task representing the asynchronous operation.
Examples
var schema = new Schema { /* schema definition */ };
await graph.CreateNodeSchemaAsync(schema, overwrite: true);
| Overload | |
|---|---|
| AddOrUpdate<T>(T) | Adds or updates a node. |
| AddOrUpdate<T>(IEnumerable<T>) | Adds or updates a sequence of nodes. |
| AddOrUpdate(Node, object) | Adds or updates a node with the specified content. |
| AddOrUpdate(Node) | Adds or updates a node. |
| AddOrUpdate(Node, Action<NodeOperation>) | Adds a new node or updates an existing node in the graph using a specified operation. |
AddOrUpdate<T>(T)
public Node AddOrUpdate<T>(T node) where T : classAdds or updates a node.
Parameters
- node T
- The node to add or update.
Type Parameters
- T
- The type of the node.
Returns
The added or updated node.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
var node = graph.AddOrUpdate(author);
AddOrUpdate<T>(IEnumerable<T>)
public Node[] AddOrUpdate<T>(IEnumerable<T> nodes) where T : classAdds or updates a sequence of nodes.
Parameters
- nodes IEnumerable<T>
- The nodes to add or update.
Type Parameters
- T
- The type of the nodes.
Returns
The added or updated nodes, in the same order as nodes.
AddOrUpdate(Node, object)
public Node AddOrUpdate(Node node, object content)Adds or updates a node with the specified content.
Parameters
- node Node
- The node to add or update.
- content object
- The content of the node.
Returns
The added or updated node.
Examples
var node = Node.FromKey("Author", "john-doe");
var content = new { Name = "John Doe", Country = "USA" };
graph.AddOrUpdate(node, content);
AddOrUpdate(Node)
public Node AddOrUpdate(Node node)Adds or updates a node.
Parameters
- node Node
- The node to add or update.
Returns
The added or updated node.
Examples
var node = Node.FromKey("Author", "john-doe");
graph.AddOrUpdate(node);
AddOrUpdate(Node, Action<NodeOperation>)
public Node AddOrUpdate(Node node, Action<NodeOperation> operation)Adds a new node or updates an existing node in the graph using a specified operation.
Parameters
- node Node
- The node to be added or updated in the graph.
- operation Action<NodeOperation>
- The operation to modify the node during the add or update process.
Returns
The added or updated node.
| Overload | |
|---|---|
| TryAdd<T>(T) | Tries to add a node if it doesn't exist yet. |
| TryAdd<T>(IEnumerable<T>) | Tries to add a sequence of nodes, skipping any that already exist. |
| TryAdd(Node) | Attempts to add a new node to the graph. Does not override existing nodes with similar properties. |
| TryAdd(Node, Action<NodeOperation>) | Attempts to add a new node to the graph with the specified operation. If the node already exists, no changes will be made. |
| TryAdd(Node, object) | Attempts to add a node to the graph, associating it with the specified content, without overwriting an existing node if it already exists. |
TryAdd<T>(T)
public Node TryAdd<T>(T node) where T : classTries to add a node if it doesn't exist yet.
Parameters
- node T
- The node to add.
Type Parameters
- T
- The type of the node.
Returns
The added node.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
var node = graph.TryAdd(author);
TryAdd<T>(IEnumerable<T>)
public Node[] TryAdd<T>(IEnumerable<T> nodes) where T : classTries to add a sequence of nodes, skipping any that already exist.
Parameters
- nodes IEnumerable<T>
- The nodes to add.
Type Parameters
- T
- The type of the nodes.
Returns
The added nodes, in the same order as nodes.
TryAdd(Node)
public Node TryAdd(Node node)Attempts to add a new node to the graph. Does not override existing nodes with similar properties.
Parameters
- node Node
- The node to be added to the graph.
Returns
The newly added node, or the existing node if it already exists in the graph.
TryAdd(Node, Action<NodeOperation>)
public Node TryAdd(Node node, Action<NodeOperation> operation)Attempts to add a new node to the graph with the specified operation. If the node already exists, no changes will be made.
Parameters
- node Node
- The node to add to the graph.
- operation Action<NodeOperation>
- The action to configure the node operation.
Returns
The node that was provided, regardless of whether it was added.
TryAdd(Node, object)
public Node TryAdd(Node node, object content)Attempts to add a node to the graph, associating it with the specified content, without overwriting an existing node if it already exists.
Parameters
- node Node
- The node to be added to the graph.
- content object
- The content associated with the node.
Returns
The node that was attempted to be added.
| Overload | |
|---|---|
| Update<T>(T) | Updates a node. |
| Update<T>(IEnumerable<T>) | Updates a sequence of nodes. |
| Update(Node, Action<NodeOperation>) | Updates the specified node in the graph using the defined operation. |
| Update(Node, object) | Updates the content of an existing node in the graph. |
Update<T>(T)
public Node Update<T>(T node) where T : classUpdates a node.
Parameters
- node T
- The node to update.
Type Parameters
- T
- The type of the node.
Returns
The updated node.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
var node = graph.Update(author);
Update<T>(IEnumerable<T>)
public Node[] Update<T>(IEnumerable<T> nodes) where T : classUpdates a sequence of nodes.
Parameters
- nodes IEnumerable<T>
- The nodes to update.
Type Parameters
- T
- The type of the nodes.
Returns
The updated nodes, in the same order as nodes.
Update(Node, Action<NodeOperation>)
public Node Update(Node node, Action<NodeOperation> operation)Updates the specified node in the graph using the defined operation.
Parameters
- node Node
- The node to be updated in the graph.
- operation Action<NodeOperation>
- An action defining the update operation to be applied to the node.
Returns
The updated node instance.
Update(Node, object)
public Node Update(Node node, object content)Updates the content of an existing node in the graph.
Parameters
- node Node
- The node to update.
- content object
- The new content to be set for the node.
Returns
The updated node instance.
Examples
var bookNode = Node.FromKey("Book", "book-123");
graph.Update(bookNode, new { Title = "New Title", Year = 2023 });
| Overload | |
|---|---|
| Delete<T>(T) | Deletes a node. |
| Delete<T>(IEnumerable<T>) | Deletes a sequence of nodes. |
| Delete(Node) | Deletes the specified node from the graph database. |
Delete<T>(T)
public void Delete<T>(T node) where T : classDeletes a node.
Parameters
- node T
- The node to delete.
Type Parameters
- T
- The type of the node.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
graph.Delete(author);
public Node ToNode<T>(T node) where T : classResolves a strongly-typed node instance to its Node key representation using the registered schema mapping.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute, unless it already is aNode.
Parameters
- node
- The strongly-typed node (or an existing
Node, which is returned unchanged).
Returns
A Node identified by the mapped node type and key.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
var node = graph.ToNode(author);
graph.Link(node, otherNode, "Knows");
| Overload | |
|---|---|
| AddOrUpdateWithOwnership<T>(T, Node[]) | Adds or updates a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| AddOrUpdateWithOwnership(Node, object, Node[]) | Adds or updates a node with the specified content, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| AddOrUpdateWithOwnership(Node, Node[]) | Adds or updates a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| AddOrUpdateWithOwnership(Node, Action<NodeOperation>, Node[]) | Adds or updates a node using the specified node operation, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
AddOrUpdateWithOwnership<T>(T, Node[])
public Node AddOrUpdateWithOwnership<T>(T node, params Node[] owners) where T : classAdds or updates a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node T
- The node to add or update.
- owners Node[]
- The nodes that should own the newly added or updated node.
Type Parameters
- T
- The type of the node.
Returns
The added or updated node.
Remarks
There is intentionally no UpdateWithOwnership variant: ownership is asserted by adding _OwnedBy edges, which is inherently an upsert, so use AddOrUpdateWithOwnership{T} to (re)assert ownership on an existing node. Use ClearPermissions first if you need to replace the existing owners rather than add to them.
AddOrUpdateWithOwnership(Node, object, Node[])
public Node AddOrUpdateWithOwnership(Node node, object content, params Node[] owners)Adds or updates a node with the specified content, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add or update.
- content object
- The content of the node.
- owners Node[]
- The nodes that should own the node.
Returns
The added or updated node.
AddOrUpdateWithOwnership(Node, Node[])
public Node AddOrUpdateWithOwnership(Node node, params Node[] owners)Adds or updates a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add or update.
- owners Node[]
- The nodes that should own the node.
Returns
The added or updated node.
AddOrUpdateWithOwnership(Node, Action<NodeOperation>, Node[])
public Node AddOrUpdateWithOwnership(Node node, Action<NodeOperation> operation, params Node[] owners)Adds or updates a node using the specified node operation, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add or update.
- operation Action<NodeOperation>
- The operation that configures the node content.
- owners Node[]
- The nodes that should own the node.
Returns
The added or updated node.
| Overload | |
|---|---|
| TryAddWithOwnership<T>(T, Node[]) | Attempts to add a node if it doesn't exist yet, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| TryAddWithOwnership(Node, Node[]) | Attempts to add a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| TryAddWithOwnership(Node, Action<NodeOperation>, Node[]) | Attempts to add a node using the specified node operation, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
| TryAddWithOwnership(Node, object, Node[]) | Attempts to add a node with the specified content, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations. |
TryAddWithOwnership<T>(T, Node[])
public Node TryAddWithOwnership<T>(T node, params Node[] owners) where T : classAttempts to add a node if it doesn't exist yet, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node T
- The node to add.
- owners Node[]
- The nodes that should own the newly added node.
Type Parameters
- T
- The type of the node.
Returns
The added node.
TryAddWithOwnership(Node, Node[])
public Node TryAddWithOwnership(Node node, params Node[] owners)Attempts to add a node, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add.
- owners Node[]
- The nodes that should own the node.
Returns
The node passed in.
TryAddWithOwnership(Node, Action<NodeOperation>, Node[])
public Node TryAddWithOwnership(Node node, Action<NodeOperation> operation, params Node[] owners)Attempts to add a node using the specified node operation, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add.
- operation Action<NodeOperation>
- The operation that configures the node content.
- owners Node[]
- The nodes that should own the node.
Returns
The node passed in.
TryAddWithOwnership(Node, object, Node[])
public Node TryAddWithOwnership(Node node, object content, params Node[] owners)Attempts to add a node with the specified content, atomically linking it to the supplied owner nodes via _OwnedBy edges as part of the same locking operation. The reverse _Owns edges from each owner back to the node are queued and processed as regular batched edge operations.
Parameters
- node Node
- The node to add.
- content object
- The content of the node.
- owners Node[]
- The nodes that should own the node.
Returns
The node passed in.
| Overload | |
|---|---|
| Link(Node, Node, string, bool, bool, DateTimeOffset?) | Creates a relationship (edge) between two nodes in the graph using the specified edge type. |
| Link(Node, Node, string, string, bool, bool, DateTimeOffset?) | Establishes a bidirectional link between two nodes using the specified edge types. |
| Link<TFrom, TTo>(TFrom, TTo, string, bool, bool, DateTimeOffset?) | Establishes a link between two strongly-typed nodes using the specified edge type. |
| Link<TA, TB>(TA, TB, string, string, bool, bool, DateTimeOffset?) | Establishes a bidirectional link between two strongly-typed nodes using the specified edge types. |
Link(Node, Node, string, bool, bool, DateTimeOffset?)
public void Link(Node from, Node to, string edgeType, bool unique = true, bool ignoreMissingNodes = false, DateTimeOffset? edgeTimestamp = null)Creates a relationship (edge) between two nodes in the graph using the specified edge type.
Parameters
- from Node
- The source node of the edge.
- to Node
- The target node of the edge.
- edgeType string
- The type of the edge (e.g., "HasAuthor", "AuthorOf").
- unique bool
- Specifies whether the edge should be unique or not. Default is true.
- ignoreMissingNodes bool
- Indicates whether to ignore missing nodes. If true, the relationship is only created if both nodes exist in the graph. Default is false.
- edgeTimestamp DateTimeOffset?
Examples
var authorNode = Node.FromKey("Author", "author-123");
var bookNode = Node.FromKey("Book", "book-456");
graph.Link(authorNode, bookNode, "AuthorOf");
var publisherNode = Node.FromKey("Publisher", "publisher-789");
graph.Link(bookNode, publisherNode, "HasPublisher", unique: false);
Link(Node, Node, string, string, bool, bool, DateTimeOffset?)
public void Link(Node a, Node b, string edgeTypeAtoB, string edgeTypeBtoA, bool unique = true, bool ignoreMissingNodes = false, DateTimeOffset? edgeTimestamp = null)Establishes a bidirectional link between two nodes using the specified edge types.
Parameters
- a Node
- The first node to connect.
- b Node
- The second node to connect.
- edgeTypeAtoB string
- The edge type from node
ato nodeb. - edgeTypeBtoA string
- The edge type from node
bto nodea. - unique bool
- If true, ensures the edge is uniquely established; otherwise, allows multiple edges of the same type.
- ignoreMissingNodes bool
- If true, skips adding the edge when a node is missing; otherwise, throws an error for missing nodes.
- edgeTimestamp DateTimeOffset?
Examples
var authorNode = Node.FromKey("Author", "JohnDoe");
var bookNode = Node.FromKey("Book", "GraphDB-In-Action");
graph.Link(authorNode, bookNode, "AuthorOf", "HasAuthor");
var publisherNode = Node.FromKey("Publisher", "TechBooksInc");
graph.Link(bookNode, publisherNode, "HasPublisher", "PublisherOf", unique: true, ignoreMissingNodes: true);
Link<TFrom, TTo>(TFrom, TTo, string, bool, bool, DateTimeOffset?)
public void Link<TFrom, TTo>(TFrom from, TTo to, string edgeType, bool unique = true, bool ignoreMissingNodes = false, DateTimeOffset? edgeTimestamp = null) where TFrom : class where TTo : classEstablishes a link between two strongly-typed nodes using the specified edge type.
Parameters
- from TFrom
- The source node to connect from.
- to TTo
- The target node to connect to.
- edgeType string
- The type of the edge connecting the two nodes.
- unique bool
- If true, ensures the edge is uniquely established; otherwise, allows multiple edges of the same type.
- ignoreMissingNodes bool
- If true, skips adding the edge when a node is missing; otherwise, throws an error for missing nodes.
- edgeTimestamp DateTimeOffset?
- An optional timestamp to associate with the edge.
Type Parameters
- TFrom
- The type of the source node.
- TTo
- The type of the target node.
Examples
var author = new Author { Name = "John Doe" };
var book = new Book { Title = "GraphDB-In-Action" };
graph.Link(author, book, "AuthorOf");
Link<TA, TB>(TA, TB, string, string, bool, bool, DateTimeOffset?)
public void Link<TA, TB>(TA a, TB b, string edgeTypeAtoB, string edgeTypeBtoA, bool unique = true, bool ignoreMissingNodes = false, DateTimeOffset? edgeTimestamp = null) where TA : class where TB : classEstablishes a bidirectional link between two strongly-typed nodes using the specified edge types.
Parameters
- a TA
- The first node to connect.
- b TB
- The second node to connect.
- edgeTypeAtoB string
- The edge type from node
ato nodeb. - edgeTypeBtoA string
- The edge type from node
bto nodea. - unique bool
- If true, ensures the edge is uniquely established; otherwise, allows multiple edges of the same type.
- ignoreMissingNodes bool
- If true, skips adding the edge when a node is missing; otherwise, throws an error for missing nodes.
- edgeTimestamp DateTimeOffset?
- An optional timestamp to associate with the edges.
Type Parameters
- TA
- The type of the first node.
- TB
- The type of the second node.
Examples
var author = new Author { Name = "John Doe" };
var book = new Book { Title = "GraphDB-In-Action" };
graph.Link(author, book, "AuthorOf", "HasAuthor");
| Overload | |
|---|---|
| Unlink(Node, Node, string, bool) | Removes an edge of the specified type from one node to another in the graph. |
| Unlink(Node, Node, string, string, bool) | Removes the edges of specified types between two nodes in the graph. |
| Unlink<TFrom, TTo>(TFrom, TTo, string, bool) | Removes an edge of the specified type between two strongly-typed nodes. |
| Unlink<TA, TB>(TA, TB, string, string, bool) | Removes the edges of the specified types between two strongly-typed nodes. |
Unlink(Node, Node, string, bool)
public void Unlink(Node from, Node to, string edgeType, bool unique = true)Removes an edge of the specified type from one node to another in the graph.
Parameters
- from Node
- The source node of the edge to be removed.
- to Node
- The target node of the edge to be removed.
- edgeType string
- The type of the edge to be removed.
- unique bool
- Indicates whether only a unique edge of the specified type between the nodes should be removed (if true), or all edges of the specified type between the nodes should be removed (if false).
Examples
var author = Node.FromKey("Author", "Author1");
var book = Node.FromKey("Book", "Book1");
graph.Unlink(author, book, "AuthorOf", unique: true);
Unlink(Node, Node, string, string, bool)
public void Unlink(Node a, Node b, string edgeTypeAtoB, string edgeTypeBtoA, bool unique = true)Removes the edges of specified types between two nodes in the graph.
Parameters
- a Node
- The first node involved in the edge.
- b Node
- The second node involved in the edge.
- edgeTypeAtoB string
- The type of edge from node
ato nodeb. - edgeTypeBtoA string
- The type of edge from node
bto nodea. - unique bool
- Indicates whether to remove only unique edges () or all matching edges ().
Examples
var author = Node.FromKey("Author", "JohnDoe");
var book = Node.FromKey("Book", "LearningGraphs");
graph.Unlink(author, book, "AuthorOf", "HasAuthor", unique: true);
Unlink<TFrom, TTo>(TFrom, TTo, string, bool)
public void Unlink<TFrom, TTo>(TFrom from, TTo to, string edgeType, bool unique = true) where TFrom : class where TTo : classRemoves an edge of the specified type between two strongly-typed nodes.
Parameters
- from TFrom
- The source node of the edge to be removed.
- to TTo
- The target node of the edge to be removed.
- edgeType string
- The type of the edge to be removed.
- unique bool
- If true, removes only a unique edge of the specified type; otherwise, removes all edges of the specified type between the nodes.
Type Parameters
- TFrom
- The type of the source node.
- TTo
- The type of the target node.
Unlink<TA, TB>(TA, TB, string, string, bool)
public void Unlink<TA, TB>(TA a, TB b, string edgeTypeAtoB, string edgeTypeBtoA, bool unique = true) where TA : class where TB : classRemoves the edges of the specified types between two strongly-typed nodes.
Parameters
- a TA
- The first node involved in the edge.
- b TB
- The second node involved in the edge.
- edgeTypeAtoB string
- The type of edge from node
ato nodeb. - edgeTypeBtoA string
- The type of edge from node
bto nodea. - unique bool
- If true, removes only unique edges; otherwise, removes all matching edges.
Type Parameters
- TA
- The type of the first node.
- TB
- The type of the second node.
| Overload | |
|---|---|
| UnlinkExcept(Node, Node, string) | Removes all edges of the specified type originating from the source node (`from`) except those connecting to the `except` node. |
| UnlinkExcept(Node, Node, string, string) | Removes all edges of the specified type from the 'from' node to other nodes, except for the edge to the 'except' node. Additionally, removes edges of the inverse specified type from the 'except' node to the 'from' node. |
UnlinkExcept(Node, Node, string)
public void UnlinkExcept(Node from, Node except, string edgeType)Removes all edges of the specified type originating from the source node (`from`) except those connecting to the `except` node.
Parameters
- from Node
- The source node from which edges will be removed.
- except Node
- The target node that should retain its connection with the source node.
- edgeType string
- The type of edge to remove, except for the connection to the `except` node.
Examples
var author = Node.FromKey("Author", "JohnDoe");
var book1 = Node.FromKey("Book", "BookA");
var book2 = Node.FromKey("Book", "BookB");
graph.UnlinkExcept(author, book1, "AuthorOf");
UnlinkExcept(Node, Node, string, string)
public void UnlinkExcept(Node from, Node except, string edgeTypeFromToExcept, string edgeTypeExceptToFrom)Removes all edges of the specified type from the 'from' node to other nodes, except for the edge to the 'except' node. Additionally, removes edges of the inverse specified type from the 'except' node to the 'from' node.
Parameters
- from Node
- The source node from which outgoing edges will be removed.
- except Node
- The target node to which the edges will be retained.
- edgeTypeFromToExcept string
- The type of the outgoing edges from the 'from' node to the 'except' node.
- edgeTypeExceptToFrom string
- The type of the outgoing edges from the 'except' node to the 'from' node.
Examples
var author = Node.FromKey("Author", "Author1");
var book = Node.FromKey("Book", "Book1");
graph.UnlinkExcept(author, book, "AuthorOf", "HasAuthor");
| Overload | |
|---|---|
| AddAlias(Node, Language, string, bool) | Adds an alias to a node in the graph database for the specified language. |
| AddAlias<T>(T, Language, string, bool) | Adds an alias to a strongly-typed node in the graph database for the specified language. |
AddAlias(Node, Language, string, bool)
public void AddAlias(Node from, Language language, string alias, bool ignoreCase)Adds an alias to a node in the graph database for the specified language.
Parameters
- from Node
- The node to which the alias is being added.
- language Language
- The language associated with the alias.
- alias string
- The alias value to be added.
- ignoreCase bool
- If true, the alias comparison will ignore case.
Examples
var authorNode = Node.FromKey("Author", "JohnDoe");
graph.AddAlias(authorNode, Language.English, "JDoe", ignoreCase: true);
AddAlias<T>(T, Language, string, bool)
public void AddAlias<T>(T from, Language language, string alias, bool ignoreCase) where T : classAdds an alias to a strongly-typed node in the graph database for the specified language.
Parameters
- from T
- The node to which the alias is being added.
- language Language
- The language associated with the alias.
- alias string
- The alias value to be added.
- ignoreCase bool
- If true, the alias comparison will ignore case.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute.
| Overload | |
|---|---|
| RemoveAlias(Node, Language, string, bool) | Removes a single alias from a node in the graph database for the specified language. |
| RemoveAlias<T>(T, Language, string, bool) | Removes a single alias from a strongly-typed node in the graph database for the specified language. |
RemoveAlias(Node, Language, string, bool)
public void RemoveAlias(Node from, Language language, string alias, bool ignoreCase)Removes a single alias from a node in the graph database for the specified language.
Parameters
- from Node
- The node from which the alias is being removed.
- language Language
- The language associated with the alias.
- alias string
- The alias value to be removed.
- ignoreCase bool
- Must match the
ignoreCasevalue the alias was added with, so the same alias node is resolved.
Examples
var authorNode = Node.FromKey("Author", "JohnDoe");
graph.RemoveAlias(authorNode, Language.English, "JDoe", ignoreCase: true);
RemoveAlias<T>(T, Language, string, bool)
public void RemoveAlias<T>(T from, Language language, string alias, bool ignoreCase) where T : classRemoves a single alias from a strongly-typed node in the graph database for the specified language.
Parameters
- from T
- The node from which the alias is being removed.
- language Language
- The language associated with the alias.
- alias string
- The alias value to be removed.
- ignoreCase bool
- Must match the
ignoreCasevalue the alias was added with, so the same alias node is resolved.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute.
| Overload | |
|---|---|
| ClearAliases(Node) | Clears all aliases associated with the specified node in the graph. |
| ClearAliases<T>(T) | Clears all aliases associated with the specified strongly-typed node in the graph. |
public async Task<FetchFolderContentPayload> FetchFolderContentAsync(string folderName, string sourceName, Uri uri)Fetches the content of a folder from the graph database based on the provided folder name, source name, and URI.
Parameters
- folderName
- The name of the folder whose content needs to be fetched.
- sourceName
- The source name associated with the folder.
- uri
- The URI from which the folder content is fetched.
Returns
An instance of ExistingFilesPayload containing the details of the existing files in the folder.
Examples
var folderContent = await graph.FetchFolderContentAsync("BooksFolder", "SourceA", new Uri("https://example.com/folder"));
public Task<Node> CreateUserAsync(string userName, string email, string firstName, string lastName, bool isActive = true, bool preferUserNameAsUniqueIdentifer = true, bool cache = false)Asynchronously creates a new user node in the graph database with the specified details.
Parameters
- userName
- The username of the user.
- The email address of the user.
- firstName
- The first name of the user.
- lastName
- The last name of the user.
Returns
A Node representing the newly created user.
Examples
var userNode = await graph.CreateUserAsync("JohnDoe123", "john.doe@example.com", "John", "Doe");
public Task<Node> CreateTeamAsync(string teamName, string description = null, bool cache = false)Creates a new team in the graph database with the specified name and optional description.
Parameters
- teamName
- The name of the team to be created.
- description
- An optional description of the team.
Returns
A Node representing the created team node.
Examples
var teamNode = await graph.CreateTeamAsync("Data Science Team", "Handles all data projects");
public async Task<Node> CreateFolderAsync(string folderName, string source, Uri uri = null, bool initiallyPrivate = false)Creates a folder node in the graph database with specified properties.
Parameters
- folderName
- The name of the folder to be created.
- source
- The source or context of the folder's creation.
- uri
- Optional URI associated with the folder. This can be used to link the folder to an external resource.
- initiallyPrivate
- Indicates whether the folder should be marked as private initially. Defaults to false.
Returns
A Node representing the created folder.
Examples
var folderNode = await graph.CreateFolderAsync("ResearchPapers", "AuthorData", new Uri("https://example.com/folder"), initiallyPrivate: true);
var folderNode = await graph.CreateFolderAsync("Drafts", "EditorWorkspace");
public Node CreateContact(string email, string firstName, string lastName)Creates a new contact node with the specified email, first name, and last name.
Parameters
- The unique email identifier of the contact. Must be a valid email format.
- firstName
- The first name of the contact.
- lastName
- The last name of the contact.
Returns
A Node representing the contact.
Examples
var contact = graph.CreateContact("john.doe@example.com", "John", "Doe");
public Node CreateOrganization(string domain, string name)Creates a new organization node in the graph database using the given domain as a unique identifier.
Parameters
- domain
- The root domain of the organization (e.g., "curiosity.ai"). Must be a valid domain.
- name
- The name of the organization.
Returns
A Node representing the created or updated organization.
Exceptions
- Exception
- Thrown if the domain is not a valid website root domain.
Examples
var organization = graph.CreateOrganization("publisherhouse.com", "Publisher House");
public Node CreateWebPage(string url, string title, string textContent, bool renderHTML, string source, string excerpt = null, string author = null)Creates a web page node in the graph with the provided attributes.
Parameters
- url
- The unique URL of the web page.
- title
- The title of the web page.
- textContent
- The textual content of the web page.
- renderHTML
- Indicates whether the HTML content of the page should be rendered.
- source
- The source or origin of the web page.
- excerpt
- Optional excerpt or snippet from the web page.
- author
- Optional author of the web page content.
Returns
A new node representing the web page.
Examples
var webPageNode = graph.CreateWebPage(
url: "https://example.com/article",
title: "Graph Databases",
textContent: "An introduction to graph databases.",
renderHTML: true,
source: "https://example.com",
excerpt: "An introduction...",
author: "John Doe");
public bool CheckPermissionsChanged(string filePath)Checks whether the permissions of the specified file have been changed.
Parameters
- filePath
- The path to the file whose permissions should be checked.
Returns
A boolean value indicating whether the permissions have changed. Returns false on non-Windows operating systems.
Examples
var permissionsChanged = graph.CheckPermissionsChanged("/path/to/file");
public async Task<bool> MapPermissionsAsync(string filePath, Node fileNode)Maps file access permissions in the graph database for the specified file path and file node.
Parameters
- filePath
- The file path for which permissions need to be mapped.
- fileNode
- The graph node representing the file.
Returns
A task representing the asynchronous operation. The task result is a boolean indicating whether the operation was successful (only supported on Windows).
Examples
var authorNode = Node.FromKey("Author", "john-doe");
var success = await graph.MapPermissionsAsync("C:/documents/file.txt", authorNode);
public async Task<Node> UploadFileAndPermissionsAsync(string filePath, string filename, string sourceName, bool checkHash = true, Uri uri = null, bool silent = false)Uploads a file to the graph database and sets up permissions by mapping it to a graph node.
Parameters
- filePath
- The path to the file to be uploaded.
- filename
- The name to assign to the file in the graph database.
- sourceName
- The source or origin of the file, used for metadata purposes.
- checkHash
- Indicates whether to verify the file's integrity using a hash. Defaults to true.
- uri
- Optional URI to associate with the uploaded file.
- silent
- Doesn't print log messages about the upload
Returns
A Node representing the uploaded file in the graph database.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
await graph.InitializeAccessControlAsync("/path/to/cache");
var fileNode = await graph.UploadFileAndPermissionsAsync("C:/files/myFile.txt", "myFile.txt", "AuthorFileSource");
| Overload | |
|---|---|
| UploadFileAsync(string, string, string, bool, Uri, bool, bool) | Uploads a file to the graph database and associates it with the specified source. Retries the operation until successful or the defined timeout elapses. |
| UploadFileAsync(Stream, string, string, bool, Uri, bool, bool) | Uploads a file to the graph database and creates a corresponding node with the given attributes. |
UploadFileAsync(string, string, string, bool, Uri, bool, bool)
public async Task<Node> UploadFileAsync(string filePath, string fileName, string sourceName, bool checkHash = true, Uri uri = null, bool initiallyPrivate = false, bool silent = false)Uploads a file to the graph database and associates it with the specified source. Retries the operation until successful or the defined timeout elapses.
Parameters
- filePath string
- The full file path of the file to be uploaded.
- fileName string
- The name under which the file should be saved in the graph database.
- sourceName string
- The source name to associate the uploaded file with.
- checkHash bool
- Determines whether the file's hash should be validated to prevent duplicates. Defaults to true.
- uri Uri
- Optional URI to specify the file destination. Defaults to null.
- initiallyPrivate bool
- Specifies whether the file starts as private. Defaults to false.
- silent bool
- Doesn't print log messages about the upload
Returns
A task that resolves to the Node representing the uploaded file in the graph database.
Examples
var node = await graph.UploadFileAsync("C:\\files\\book-cover.jpg", "cover.jpg", "BookSources");
UploadFileAsync(Stream, string, string, bool, Uri, bool, bool)
public Task<Node> UploadFileAsync(Stream file, string fileName, string sourceName, bool checkHash = true, Uri uri = null, bool initiallyPrivate = false, bool silent = false)Uploads a file to the graph database and creates a corresponding node with the given attributes.
Parameters
- file Stream
- The file stream to upload.
- fileName string
- The name of the file being uploaded.
- sourceName string
- The source identifier for the file.
- checkHash bool
- Indicates whether to check the file hash for duplicates. Default is true.
- uri Uri
- Optional URI associated with the file. Default is null.
- initiallyPrivate bool
- Indicates whether the file should be initially private. Default is false.
- silent bool
- Doesn't print log messages about the upload
Returns
A Node instance representing the uploaded file in the graph database.
Examples
using var fileStream = File.OpenRead("example.pdf");
var fileNode = await graph.UploadFileAsync(fileStream, "example.pdf", "source-id");
public async Task<Node> UploadFileWithIdentifierAsync(Stream file, string fileIdentifier, string displayFileName, string sourceName, bool checkHash = true, bool initiallyPrivate = false)Uploads a file to the graph database with a unique identifier, associating metadata such as filename and source.
Parameters
- file
- The file stream to be uploaded. The stream must be readable.
- fileIdentifier
- A unique identifier for the file.
- displayFileName
- The name of the file, used for metadata tagging or client display purposes.
- sourceName
- The source or origin name associated with the file upload.
- checkHash
- Indicates whether the file hash should be checked before upload. Defaults to true.
- initiallyPrivate
- Determines whether the uploaded file should initially be private. Defaults to false.
Returns
A Node representing the uploaded file entry in the graph database.
Exceptions
- ArgumentNullException
- Throws if
fileIdentifier,displayFileName, orsourceNameis null or empty.
Examples
using var fileStream = File.OpenRead("book_cover.jpg");
var fileNode = await graph.UploadFileWithIdentifierAsync(fileStream, "unique-book-1234", "book_cover.jpg", "PublisherA");
| Overload | |
|---|---|
| UploadFileToFolderAsync(Stream, string, string, Node, bool, Uri, bool, bool) | Uploads a file to a specified folder in the graph database. |
| UploadFileToFolderAsync(Uri, string, string, Node, bool, byte[]) | Uploads a file to a specified folder in the graph database. |
UploadFileToFolderAsync(Stream, string, string, Node, bool, Uri, bool, bool)
public async Task<Node> UploadFileToFolderAsync(Stream file, string fileName, string sourceName, Node parentFolderNode, bool checkHash = true, Uri uri = null, bool initiallyPrivate = false, bool inPlace = false)Uploads a file to a specified folder in the graph database.
Parameters
- file Stream
- The file stream to be uploaded.
- fileName string
- The name of the file including its extension.
- sourceName string
- The source identifier for the file (e.g., application or source system name).
- parentFolderNode Node
- The folder node where the file will be uploaded to. Must have a valid UID.
- checkHash bool
- Optional. Whether to validate file integrity using a hash. Default is true.
- uri Uri
- Optional. A URI representing the original file location, for reference or metadata tracking.
- initiallyPrivate bool
- Optional. Determines if the file should be marked as private upon upload. Default is false.
- inPlace bool
Returns
A new Node that represents the uploaded file within the given folder.
Examples
var folderNode = Node.FromKey("Folder", "MarketingAssets");
var fileStream = File.OpenRead("brochure.pdf");
var uploadedFileNode = await graph.UploadFileToFolderAsync(fileStream, "brochure.pdf", "MarketingTool", folderNode);
UploadFileToFolderAsync(Uri, string, string, Node, bool, byte[])
public async Task<Node> UploadFileToFolderAsync(Uri fileUrl, string fileName, string sourceName, Node parentFolderNode, bool initiallyPrivate = false, byte[] sha256Hash = null)Uploads a file to a specified folder in the graph database.
Parameters
- fileUrl Uri
- The Url of the file to be uploaded.
- fileName string
- The name of the file including its extension.
- sourceName string
- The source identifier for the file (e.g., application or source system name).
- parentFolderNode Node
- The folder node where the file will be uploaded to. Must have a valid UID.
- initiallyPrivate bool
- Optional. Determines if the file should be marked as private upon upload. Default is false.
- sha256Hash byte[]
- Optional. Hash of the file to check first if it needs to be uploaded. Compute with SHA256.Create().ComputeHash(...).
Returns
A new Node that represents the uploaded file within the given folder.
Examples
var folderNode = Node.FromKey("Folder", "MarketingAssets");
var fileStream = File.OpenRead("brochure.pdf");
var uploadedFileNode = await graph.UploadFileToFolderAsync(fileStream, "brochure.pdf", "MarketingTool", folderNode);
public string GetFileHash(Stream file)Compute a SHA256 hash for a given input stream file. The stream will be rewinded before and after computing the hash.
Parameters
- file
- A stream representing the file
Returns
The SHA256 hash of the file content
public async Task<Node> TryGetFileNodeAsync(string fileName, string sourceName, byte[] sha256Hash = null)Try getting the file node after checking if it exists in the graph, and optionally checking if the SHA256 hash is the same
Parameters
- fileName
- sourceName
- sha256Hash
public async Task DeleteFileAsync(string fileName, string sourceName)Deletes a file from the specified source in the graph database.
Parameters
- fileName
- The name of the file to delete.
- sourceName
- The source from which the file should be deleted.
Returns
A task that represents the asynchronous delete operation.
Examples
await graph.DeleteFileAsync("example.txt", "source1");
public async Task DeleteFolderAsync(string path, string sourceName)Deletes a folder from the graph database using the specified path and source name.
Parameters
- path
- The path of the folder to be deleted.
- sourceName
- The name of the source for the folder.
Returns
A Task representing the asynchronous operation.
Examples
await graph.DeleteFolderAsync("/authors/usa", "example-source");
public void MarkFileAsPrivate(Node fileNode)Marks the specified file node as private by removing the public access edge.
Parameters
- fileNode
- The file node to mark as private. This node must be of type "_FileEntry".
Exceptions
- ArgumentException
- Thrown if the provided node is not of type "_FileEntry".
Examples
var fileNode = Node.FromUID("unique-file-id", "_FileEntry");
graph.MarkFileAsPrivate(fileNode);
public void MarkFolderAsPrivate(Node folderNode)Marks a folder node as private by removing its association with the public access group.
Parameters
- folderNode
- The folder node to be marked as private. Must be of type "_Folder".
Exceptions
- ArgumentException
- Thrown if the provided node is not of type "_Folder".
Examples
var folderNode = Node.FromUID("folder123", "_Folder");
graph.MarkFolderAsPrivate(folderNode);
public void AddUserToTeam(Node userNode, Node teamNode)Adds a user node to a team node by creating a unique membership relationship between them.
Parameters
- userNode
- The node representing the user to be added to the team.
- teamNode
- The node representing the team to which the user will be added.
Examples
var user = Node.FromKey("User", "user123");
var team = Node.FromKey("Team", "teamABC");
graph.AddUserToTeam(user, team);
public void AddAdminToTeam(Node userNode, Node teamNode)Adds a user as an admin to a specified team, creating appropriate edges in the graph database.
Parameters
- userNode
- The node representing the user to be added as an admin. Must have type "_User".
- teamNode
- The node representing the team to which the user will be added as an admin. Must have type "_AccessGroup".
Examples
var adminUser = Node.FromKey("_User", "user123");
var team = Node.FromKey("_AccessGroup", "team456");
graph.AddAdminToTeam(adminUser, team);
public void RemoveAdminFromTeam(Node userNode, Node teamNode)Removes a user's admin rights on a team by removing the admin edges, while leaving the user's membership intact.
Parameters
- userNode
- The node representing the user to demote from admin. Must have type "_User".
- teamNode
- The node representing the team on which the user's admin rights are removed. Must have type "_AccessGroup".
Examples
var adminUser = Node.FromKey("_User", "user123");
var team = Node.FromKey("_AccessGroup", "team456");
graph.RemoveAdminFromTeam(adminUser, team);
public void RemoveUserFromTeam(Node userNode, Node teamNode)Removes a user from a team by removing all relevant edges between the user node and team node.
Parameters
- userNode
- The node representing the user to be removed.
- teamNode
- The node representing the team from which the user will be removed.
Examples
var userNode = Node.FromKey("_User", "user123");
var teamNode = Node.FromKey("_AccessGroup", "team456");
graph.RemoveUserFromTeam(userNode, teamNode);
| Overload | |
|---|---|
| RestrictAccessToTeam(Node, Node) | Restricts access to a specific node by associating it with a team access group node. |
| RestrictAccessToTeam<T>(T, Node) | Restricts access to a strongly-typed node by associating it with a team access group node. |
RestrictAccessToTeam(Node, Node)
public void RestrictAccessToTeam(Node node, Node teamNode)Restricts access to a specific node by associating it with a team access group node.
Parameters
- node Node
- The target node to restrict access to.
- teamNode Node
- The team node representing the access group.
Examples
Create a Book node and restrict its access to a specific team:
var bookNode = Node.FromKey("Book", "book-key");
var teamNode = Node.FromKey("_AccessGroup", "team-key");
graph.RestrictAccessToTeam(bookNode, teamNode);
Restrict access of an Author node to a specific team:
var authorNode = Node.FromKey("Author", "author-key");
var teamNode = Node.FromKey("_AccessGroup", "team-key");
graph.RestrictAccessToTeam(authorNode, teamNode);
RestrictAccessToTeam<T>(T, Node)
public void RestrictAccessToTeam<T>(T node, Node teamNode) where T : classRestricts access to a strongly-typed node by associating it with a team access group node.
Parameters
- node T
- The target node to restrict access to.
- teamNode Node
- The team node representing the access group.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute.
public void RemoveAccessFromTeam(Node node, Node teamNode)Removes a team access group as an owner of the specified node, revoking the access previously granted by RestrictAccessToTeam.
Parameters
- node
- The node from which the team's access is removed.
- teamNode
- The team node whose access is removed.
Examples
var bookNode = Node.FromKey("Book", "book-key");
var teamNode = Node.FromKey("_AccessGroup", "team-key");
graph.RemoveAccessFromTeam(bookNode, teamNode);
| Overload | |
|---|---|
| RestrictAccessToUser(Node, Node) | Restricts access to the specified node by associating it with a user node as its owner. Creates a bidirectional ownership relationship between the node and the user node. |
| RestrictAccessToUser<T>(T, Node) | Restricts access to a strongly-typed node by associating it with a user node as its owner. |
RestrictAccessToUser(Node, Node)
public void RestrictAccessToUser(Node node, Node userNode)Restricts access to the specified node by associating it with a user node as its owner. Creates a bidirectional ownership relationship between the node and the user node.
Parameters
- node Node
- The node to restrict access to.
- userNode Node
- The user node that will own the specified node.
Examples
var authorNode = Node.FromKey("Author", "JohnDoe");
var userNode = Node.FromKey("_User", "12345");
graph.RestrictAccessToUser(authorNode, userNode);
RestrictAccessToUser<T>(T, Node)
public void RestrictAccessToUser<T>(T node, Node userNode) where T : classRestricts access to a strongly-typed node by associating it with a user node as its owner.
Parameters
- node T
- The node to restrict access to.
- userNode Node
- The user node that will own the specified node.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute.
public void RemoveAccessFromUser(Node node, Node userNode)Removes a user as an owner of the specified node, revoking the access previously granted by RestrictAccessToUser.
Parameters
- node
- The node from which the user's access is removed.
- userNode
- The user node whose access is removed.
Examples
var authorNode = Node.FromKey("Author", "JohnDoe");
var userNode = Node.FromKey("_User", "12345");
graph.RemoveAccessFromUser(authorNode, userNode);
| Overload | |
|---|---|
| ClearPermissions(Node, IList<Node>) | Clears the permissions of the specified node, with an optional exception for specific owner nodes. |
| ClearPermissions<T>(T, IList<Node>) | Clears the permissions of the specified strongly-typed node, with an optional exception for specific owner nodes. |
ClearPermissions(Node, IList<Node>)
public void ClearPermissions(Node node, IList<Node> exceptOwners = null)Clears the permissions of the specified node, with an optional exception for specific owner nodes.
Parameters
- node Node
- The node for which permissions will be cleared.
- exceptOwners IList<Node>
- An optional list of owner nodes (of type "_User" or "_AccessGroup") whose permissions will be retained.
Exceptions
- ArgumentException
- Thrown if any of the provided owner nodes have an invalid type or missing identifier.
Examples
var bookNode = Node.FromKey("Book", "Book1");
var authorNode = Node.FromKey("_User", "Author1");
graph.ClearPermissions(bookNode, new [] { authorNode });
var publisherNode = Node.FromKey("Publisher", "Publisher1");
graph.ClearPermissions(publisherNode);
ClearPermissions<T>(T, IList<Node>)
public void ClearPermissions<T>(T node, IList<Node> exceptOwners = null) where T : classClears the permissions of the specified strongly-typed node, with an optional exception for specific owner nodes.
Parameters
- node T
- The node for which permissions will be cleared.
- exceptOwners IList<Node>
- An optional list of owner nodes (of type "_User" or "_AccessGroup") whose permissions will be retained.
Type Parameters
- T
- The type of the node. Must be decorated with
NodeAttribute.
Exceptions
- ArgumentException
- Thrown if any of the provided owner nodes have an invalid type or missing identifier.
Examples
var author = new Author { Name = "John Doe", Country = "USA" };
graph.ClearPermissions(author);
public async Task LogAsync(LogLevel logLevel, string message)Logs a message asynchronously to the graph's logging system.
Parameters
- message
- The message to be logged.
Returns
A task that represents the asynchronous operation.
Examples
await graph.LogAsync("Database connected successfully.");
public Task LogManyAsync((LogLevel logLevel, string message)[] messages)Logs a message asynchronously to the graph's logging system.
Parameters
- message
- The message to be logged.
Returns
A task that represents the asynchronous operation.
Examples
await graph.LogAsync("Database connected successfully.");
public async Task<Dictionary<Node, string>> MapAsync(string nodeType, string field, int pageSize = 1000)Retrieves a mapping of nodes to a specified field value for a given node type in the graph database, paged asynchronously.
Parameters
- nodeType
- The type of the nodes to query (e.g., "Author", "Book").
- field
- The field name to map (e.g., "Name", "Title").
- pageSize
- The number of nodes to fetch per page. Default is 1000.
Returns
A task that represents the asynchronous operation. The task result contains a dictionary mapping nodes to their respective field values.
Examples
var authorNames = await graph.MapAsync("Author", "Name");
var bookTitles = await graph.MapAsync("Book", "Title", 500);
public async Task UploadNewApplicationInterfaceAsync(string path, int retries = 5, bool autoPatch = false, CancellationToken cancellationToken = default)Uploads a new application interface to the system from the specified folder contents.
Parameters
- path
- The file path to the directory containing the application interface.
- retries
- The number of retry attempts on failure. Default is 5.
- autoPatch
- If true, won't delete the existing user interface before replacing it with the uploaded one. Default is false.
- cancellationToken
- A token to monitor for cancellation requests. Allows cancellation of the upload process.
Returns
A task representing the asynchronous operation.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
await graph.UploadNewApplicationInterfaceAsync("/path/to/directory");
public async Task<QueryResults> QueryAsync(Action<IQuery> query)Executes a query against the graph database asynchronously.
Parameters
- query
- A delegate to define the query logic using the
IQueryinterface.
Returns
An instance of QueryResults containing the results of the executed query.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
var result = await graph.QueryAsync(q =>
{
q.Match(Node.FromKey("Author", "JohnDoe"))
.Return("Name", "Country");
});
public async Task ClearEmbeddingsIndexAsync(string indexUID)Clears the embeddings index for the specified index UID in the graph database.
Parameters
- indexUID
- The unique identifier of the embeddings index to be cleared.
Returns
A task that represents the asynchronous operation.
Examples
await graph.ClearEmbeddingsIndexAsync("author-index");
public async Task AddEmbeddingsToIndexAsync(string indexUID, IEnumerable<NodeAndVector> vectors, int batchSize = 1_000)Adds a collection of node embeddings to the specified index in batches.
Parameters
- indexUID
- The unique identifier of the index to add embeddings to.
- vectors
- A collection of nodes and their associated vector embeddings.
- batchSize
- The number of embeddings to process per batch. Defaults to 1,000.
Returns
A task representing the asynchronous operation.
Examples
var authorNode = Node.FromKey("Author", "Author1");
var embedding = new NodeAndVector(authorNode, new float[] { 1,2,3,4 });
// Add embeddings to an index:
await graph.AddEmbeddingsToIndexAsync("author-embeddings", new[] { embedding }, batchSize: 500);
public async Task<Stream> ExportWorkspaceDefinitionAsync()Exports workspace configuration
Returns
An Stream containing the exported workspace configuration.
Examples
var graph = Graph.Connect("https://example.com", "my-token", "my-connector");
var export = await graph.ExportWorkspaceDefinition();
public async Task<ImportResult> ImportWorkspaceDefinitionsAsync(Stream import)Imports workspace configuration
Parameters
- import
- The workspace definition file (.zip) containing the definitions to be imported.
Returns
A task that represents the asynchronous operation, with a result of CustomCodeImportResult indicating the success or failure of the import.
Examples
var customCodeExport = File.OpenRead("path-to-export-file.zip";
var importResult = await graph.ImportWorkspaceDefinitionsAsync(customCodeExport);
Applies to
Curiosity.Library — 2024.1 and later. See the C# SDK reference for usage patterns and the Schema reference for declaring node and edge types.