| Title: | Client for the 'AstraeaDB' Graph Database |
|---|---|
| Description: | Provides a client for 'AstraeaDB', a graph database with vector search capabilities. Supports node and edge create, read, update, and delete operations, label and edge-type lookups, graph traversals (breadth-first search, depth-first search, shortest path), temporal (time-travel) queries, graph algorithms (PageRank, Louvain community detection, connected components, and degree and betweenness centrality), vector similarity search, hybrid graph-vector search, Graph Query Language (GQL) execution, and graph-based retrieval-augmented generation (subgraph extraction with large language model integration). Communicates with the 'AstraeaDB' server over a JSON-over-TCP protocol. An optional 'Apache Arrow Flight' transport is available for high-performance bulk operations when the 'arrow' package is installed. |
| Authors: | James Harris [aut, cre] |
| Maintainer: | James Harris <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.1 |
| Built: | 2026-10-08 11:45:15 UTC |
| Source: | https://github.com/astraeadb/r-astraeadb |
An R6 class providing a high-performance client for AstraeaDB using the Apache Arrow Flight protocol. Arrow Flight enables efficient columnar data transfer, making it well-suited for bulk queries and analytical workloads.
The arrow package is optional and listed in Suggests. This
client checks for its availability at initialization and provides an
informative error message if arrow is not installed.
Arrow Flight is a gRPC-based protocol for high-performance data transport. When the AstraeaDB server exposes a Flight endpoint, this client can execute GQL queries and receive results as Apache Arrow Tables or record batches, which are more efficient than JSON for large result sets.
Typical usage:
Create an ArrowClient instance with the Flight URI.
Call $connect() to establish the connection.
Execute queries with $query() (returns Arrow Table) or
$query_df() (returns data.frame).
Call $disconnect() when finished.
For most users, the UnifiedClient is recommended as it
automatically selects the best transport available.
uriCharacter. The Arrow Flight server URI.
Defaults to "grpc://localhost:7689".
clientThe Arrow Flight client connection object, or NULL
when disconnected.
new()
Create a new ArrowClient.
Checks that the arrow package is installed and available. If not, an informative error is raised directing the user to install it.
ArrowClient$new(uri = "grpc://localhost:7689")
uriCharacter. The Arrow Flight gRPC URI.
Defaults to "grpc://localhost:7689".
A new ArrowClient object.
connect()
Connect to the Arrow Flight server.
Establishes a gRPC connection to the AstraeaDB Flight endpoint
specified by uri.
ArrowClient$connect()
Invisibly returns self for method chaining.
disconnect()
Disconnect from the Arrow Flight server.
Closes the connection and sets the client to NULL.
ArrowClient$disconnect()
Invisibly returns self for method chaining.
is_connected()
Check whether the client is currently connected.
ArrowClient$is_connected()
Logical. TRUE if connected, FALSE otherwise.
query()
Execute a GQL query and return an Arrow Table.
Sends the query as a Flight command descriptor, retrieves flight info, and fetches the data from the first endpoint.
ArrowClient$query(gql)
gqlCharacter. A GQL query string.
An Arrow Table containing the query results.
\donttest{
if (requireNamespace("arrow", quietly = TRUE) &&
astraea_server_available(port = 7689L)) {
client <- ArrowClient$new()
client$connect()
table <- client$query("MATCH (n:Person) RETURN n.name")
client$disconnect()
}
}
query_df()
Execute a GQL query and return the result as a data.frame.
This is a convenience wrapper around $query() that converts the
Arrow Table to a base R data.frame.
ArrowClient$query_df(gql)
gqlCharacter. A GQL query string.
A data.frame containing the query results.
\donttest{
if (requireNamespace("arrow", quietly = TRUE) &&
astraea_server_available(port = 7689L)) {
client <- ArrowClient$new()
client$connect()
df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age")
client$disconnect()
}
}
query_batches()
Execute a GQL query and process results in record batches.
Instead of reading all results into memory at once, this method streams results as individual Arrow RecordBatch objects and passes each to the provided callback function. This is useful for processing large result sets with bounded memory usage.
ArrowClient$query_batches(gql, callback)
gqlCharacter. A GQL query string.
callbackFunction. A function that accepts a single argument (an Arrow RecordBatch). Called once for each batch received.
Invisibly returns NULL.
\donttest{
if (requireNamespace("arrow", quietly = TRUE) &&
astraea_server_available(port = 7689L)) {
client <- ArrowClient$new()
client$connect()
client$query_batches(
"MATCH (n) RETURN n",
callback = function(batch) {
cat("Batch with", nrow(batch), "rows\n")
}
)
client$disconnect()
}
}
list_flights()
List available flights on the server.
Queries the Flight server for its list of available flight descriptors.
ArrowClient$list_flights()
A list of available flights as reported by the server.
\donttest{
if (requireNamespace("arrow", quietly = TRUE) &&
astraea_server_available(port = 7689L)) {
client <- ArrowClient$new()
client$connect()
flights <- client$list_flights()
client$disconnect()
}
}
print()
Print a summary of the ArrowClient.
ArrowClient$print(...)
...Ignored. Present for compatibility with the generic.
Invisibly returns self.
if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { # Requires the arrow package: install.packages("arrow") client <- ArrowClient$new("grpc://localhost:7689") client$connect() # Execute a GQL query and get an Arrow Table table <- client$query("MATCH (n:Person) RETURN n.name, n.age") # Or get a data.frame directly df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") # Process large results in batches client$query_batches( "MATCH (n) RETURN n", callback = function(batch) { cat("Received batch with", nrow(batch), "rows\n") } ) # List available flights flights <- client$list_flights() client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() table <- client$query("MATCH (n:Person) RETURN n.name") client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query_df` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query_batches` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() client$query_batches( "MATCH (n) RETURN n", callback = function(batch) { cat("Batch with", nrow(batch), "rows\n") } ) client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$list_flights` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() flights <- client$list_flights() client$disconnect() }if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { # Requires the arrow package: install.packages("arrow") client <- ArrowClient$new("grpc://localhost:7689") client$connect() # Execute a GQL query and get an Arrow Table table <- client$query("MATCH (n:Person) RETURN n.name, n.age") # Or get a data.frame directly df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") # Process large results in batches client$query_batches( "MATCH (n) RETURN n", callback = function(batch) { cat("Received batch with", nrow(batch), "rows\n") } ) # List available flights flights <- client$list_flights() client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() table <- client$query("MATCH (n:Person) RETURN n.name") client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query_df` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$query_batches` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() client$query_batches( "MATCH (n) RETURN n", callback = function(batch) { cat("Batch with", nrow(batch), "rows\n") } ) client$disconnect() } ## ------------------------------------------------ ## Method `ArrowClient$list_flights` ## ------------------------------------------------ if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- ArrowClient$new() client$connect() flights <- client$list_flights() client$disconnect() }
Creates an ArrowClient and connects to the Arrow Flight
server. This is a convenience wrapper that instantiates the client, calls
connect(), and returns the connected client object.
astraea_arrow_connect(uri = "grpc://localhost:7689")astraea_arrow_connect(uri = "grpc://localhost:7689")
uri |
Character. Flight server URI. Default:
|
The arrow package must be installed to use this function.
A connected ArrowClient object.
if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- astraea_arrow_connect() result <- client$query_df("MATCH (n) RETURN n") client$disconnect() }if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { client <- astraea_arrow_connect() result <- client$query_df("MATCH (n) RETURN n") client$disconnect() }
Creates an AstraeaClient and connects to the server in one
step. This is a convenience wrapper that instantiates the client, calls
connect(), and returns the connected client object.
astraea_connect(host = "127.0.0.1", port = 7687L, auth_token = NULL)astraea_connect(host = "127.0.0.1", port = 7687L, auth_token = NULL)
host |
Character. Server hostname. Default: |
port |
Integer. Server port. Default: |
auth_token |
Character or |
A connected AstraeaClient object.
if (astraea_server_available()) { client <- astraea_connect() client$ping() client$disconnect() }if (astraea_server_available()) { client <- astraea_connect() client$ping() client$disconnect() }
Tests whether an AstraeaDB server is reachable at the given host and port. Useful for conditionally running examples and tests that require a live server.
astraea_server_available(host = "127.0.0.1", port = 7687L, timeout = 2)astraea_server_available(host = "127.0.0.1", port = 7687L, timeout = 2)
host |
Character. Server hostname. Default: |
port |
Integer. Server port. Default: |
timeout |
Numeric. Connection timeout in seconds. Default: |
Logical. TRUE if server is reachable, FALSE otherwise.
if (astraea_server_available()) { client <- astraea_connect() }if (astraea_server_available()) { client <- astraea_connect() }
R6 client for the AstraeaDB graph database using the JSON-over-TCP protocol.
The client communicates with an AstraeaDB server by sending JSON-encoded
request lines over a TCP socket and reading JSON-encoded response lines back.
Each request contains a "type" field identifying the operation, and
each response contains a "status" field ("ok" or
"error") along with a "data" payload on success.
The client supports a comprehensive set of operations including:
Node and edge CRUD (create, read, update, delete)
Node and edge lookup by label or edge type
Graph traversals (BFS, DFS, shortest path)
Temporal queries (time-travel over edges with validity windows)
Graph algorithms (PageRank, Louvain community detection, connected components, degree and betweenness centrality)
GQL query execution
Vector similarity search (k-NN)
Hybrid graph-vector search
Semantic neighbor ranking and semantic walks
GraphRAG (subgraph extraction for LLM integration)
Graph statistics and raw subgraph export
Batch and data frame import/export operations
Create a client with AstraeaClient$new(), then call
$connect() to open the TCP socket. Always call $disconnect()
when finished, or use on.exit to ensure cleanup.
If the server requires authentication, pass an auth_token to the
constructor. The token is automatically attached to every request.
hostCharacter scalar. Server hostname. Default "127.0.0.1".
portInteger scalar. Server port. Default 7687L.
conSocket connection object, or NULL when disconnected.
auth_tokenCharacter scalar or NULL. Optional
authentication token sent with every request.
new()
Create a new AstraeaDB client.
AstraeaClient$new(host = "127.0.0.1", port = 7687L, auth_token = NULL)
hostCharacter scalar. Server hostname.
Default "127.0.0.1".
portInteger scalar. Server port. Default 7687L.
auth_tokenCharacter scalar or NULL. Optional
authentication token.
An AstraeaClient object (invisibly).
client <- AstraeaClient$new() client <- AstraeaClient$new(host = "db.example.com", port = 7688L) client <- AstraeaClient$new(auth_token = "my-secret-token")
connect()
Open a TCP socket connection to the AstraeaDB server.
AstraeaClient$connect()
The client object (invisibly), for method chaining.
\donttest{
if (astraea_server_available()) {
client <- AstraeaClient$new()
client$connect()
}
}
disconnect()
Close the TCP socket connection.
AstraeaClient$disconnect()
The client object (invisibly).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
client$disconnect()
client$disconnect()
}
}
is_connected()
Check whether the client is currently connected.
AstraeaClient$is_connected()
Logical scalar. TRUE if connected, FALSE
otherwise.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
client$is_connected()
client$disconnect()
}
}
print()
Print method showing connection status.
AstraeaClient$print(...)
...Ignored. Present for compatibility with the generic.
The client object (invisibly).
ping()
Health-check ping. Returns server information.
AstraeaClient$ping()
A list with server information (e.g., version,
pong).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
info <- client$ping()
message(info$version)
client$disconnect()
}
}
create_node()
Create a node.
AstraeaClient$create_node(labels, properties, embedding = NULL)
labelsCharacter vector of labels for the node.
propertiesNamed list of node properties.
embeddingOptional numeric vector. An embedding associated with the node for vector search.
Integer scalar: the ID of the newly created node.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
dim <- client$ping()$vector_dim
nid <- client$create_node(
labels = c("Person"),
properties = list(name = "Alice", age = 30),
embedding = rep(0.1, dim)
)
client$disconnect()
}
}
get_node()
Retrieve a node by its ID.
AstraeaClient$get_node(node_id)
node_idInteger scalar. The node ID to look up.
A list with labels (character vector) and
properties (named list).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
node <- client$get_node(a)
node$labels
node$properties$name
client$disconnect()
}
}
update_node()
Update a node's properties using merge semantics. Existing properties not present in the update are preserved.
AstraeaClient$update_node(node_id, properties)
node_idInteger scalar. The node ID to update.
propertiesNamed list of properties to merge.
The server response data (invisibly).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
client$update_node(a, list(city = "San Francisco"))
client$disconnect()
}
}
delete_node()
Delete a node and all edges connected to it.
AstraeaClient$delete_node(node_id)
node_idInteger scalar. The node ID to delete.
The server response data (invisibly).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
client$delete_node(a)
client$disconnect()
}
}
create_edge()
Create an edge between two nodes, with optional temporal validity.
AstraeaClient$create_edge( source, target, edge_type, properties = list(), weight = 1, valid_from = NULL, valid_to = NULL )
sourceInteger scalar. Source node ID.
targetInteger scalar. Target node ID.
edge_typeCharacter scalar. The relationship type
(e.g., "KNOWS").
propertiesNamed list of edge properties.
Default list().
weightNumeric scalar. Edge weight. Default 1.0.
valid_fromNumeric scalar or NULL. Start of temporal
validity window (milliseconds since epoch).
valid_toNumeric scalar or NULL. End of temporal
validity window (milliseconds since epoch).
Integer scalar: the ID of the newly created edge.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
eid <- client$create_edge(
source = a,
target = b,
edge_type = "KNOWS",
weight = 0.9
)
client$disconnect()
}
}
get_edge()
Retrieve an edge by its ID.
AstraeaClient$get_edge(edge_id)
edge_idInteger scalar. The edge ID to look up.
A list with source, target, edge_type,
properties, and optional temporal fields.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
e <- client$create_edge(a, b, "KNOWS")
edge <- client$get_edge(e)
edge$edge_type
client$disconnect()
}
}
update_edge()
Update an edge's properties using merge semantics.
AstraeaClient$update_edge(edge_id, properties)
edge_idInteger scalar. The edge ID to update.
propertiesNamed list of properties to merge.
The server response data (invisibly).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
e <- client$create_edge(a, b, "KNOWS")
client$update_edge(e, list(strength = "strong"))
client$disconnect()
}
}
delete_edge()
Delete an edge.
AstraeaClient$delete_edge(edge_id)
edge_idInteger scalar. The edge ID to delete.
The server response data (invisibly).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
e <- client$create_edge(a, b, "KNOWS")
client$delete_edge(e)
client$disconnect()
}
}
neighbors()
Get neighbors of a node, optionally filtered by direction and edge type.
AstraeaClient$neighbors(node_id, direction = "outgoing", edge_type = NULL)
node_idInteger scalar. The node whose neighbors to retrieve.
directionCharacter scalar. One of "outgoing",
"incoming", or "both". Default "outgoing".
edge_typeCharacter scalar or NULL. If non-NULL,
only return neighbors connected by this edge type.
A list of neighbor entries. Each entry is a list with at
least node_id and edge_id.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
nbrs <- client$neighbors(a, direction = "outgoing")
nbrs_knows <- client$neighbors(a, edge_type = "KNOWS")
client$disconnect()
}
}
bfs()
Breadth-first search starting from a node.
AstraeaClient$bfs(start, max_depth = 3L)
startInteger scalar. The starting node ID.
max_depthInteger scalar. Maximum traversal depth.
Default 3L.
A list of entries, each a list with node_id (integer)
and depth (integer).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
bfs_result <- client$bfs(a, max_depth = b)
client$disconnect()
}
}
shortest_path()
Find the shortest path between two nodes.
AstraeaClient$shortest_path(from_node, to_node, weighted = FALSE)
from_nodeInteger scalar. Source node ID.
to_nodeInteger scalar. Target node ID.
weightedLogical scalar. If TRUE, use edge weights
(Dijkstra). If FALSE, use hop count. Default FALSE.
A list with path (integer vector of node IDs),
length (hop count), and optionally cost (total weight
when weighted = TRUE).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
sp <- client$shortest_path(a, b, weighted = TRUE)
sp$path
sp$cost
client$disconnect()
}
}
neighbors_at()
Get neighbors of a node at a specific point in time. Only edges
whose temporal validity window includes timestamp are
traversed.
AstraeaClient$neighbors_at( node_id, direction = "outgoing", timestamp, edge_type = NULL )
node_idInteger scalar. The node whose neighbors to retrieve.
directionCharacter scalar. One of "outgoing",
"incoming", or "both". Default "outgoing".
timestampNumeric scalar. Point in time as milliseconds since the Unix epoch.
edge_typeCharacter scalar or NULL. Optional edge type
filter.
A list of neighbor entries valid at the given timestamp.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
# Neighbors as of January 1 2023 (ms since epoch)
nbrs <- client$neighbors_at(a, "outgoing", 1672531200000)
client$disconnect()
}
}
bfs_at()
Breadth-first search at a specific point in time.
AstraeaClient$bfs_at(start, max_depth = 3L, timestamp)
startInteger scalar. The starting node ID.
max_depthInteger scalar. Maximum traversal depth.
Default 3L.
timestampNumeric scalar. Point in time (ms since epoch).
A list of entries with node_id and depth.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
result <- client$bfs_at(a, max_depth = b, timestamp = 1672531200000)
client$disconnect()
}
}
shortest_path_at()
Find the shortest path at a specific point in time.
AstraeaClient$shortest_path_at(from_node, to_node, timestamp, weighted = FALSE)
from_nodeInteger scalar. Source node ID.
to_nodeInteger scalar. Target node ID.
timestampNumeric scalar. Point in time (ms since epoch).
weightedLogical scalar. Use edge weights? Default
FALSE.
A list with path, length, and optionally
cost.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
sp <- client$shortest_path_at(a, b, timestamp = 1672531200000)
client$disconnect()
}
}
query()
Execute a GQL (Graph Query Language) query string.
AstraeaClient$query(gql)
gqlCharacter scalar. The GQL query to execute.
The query result data as returned by the server.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
result <- client$query("MATCH (p:Person) RETURN p.name, p.city")
client$disconnect()
}
}
vector_search()
Perform k-nearest neighbor vector similarity search.
AstraeaClient$vector_search(query_vector, k = 10L)
query_vectorNumeric vector. The query embedding.
kInteger scalar. Number of nearest neighbors to return.
Default 10L.
A list of result entries, each containing at least
node_id and distance (smaller is closer). A legacy
score alias equal to distance is also present for
backward compatibility with older clients.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
dim <- client$ping()$vector_dim
results <- client$vector_search(rep(0.1, dim), k = 5L)
client$disconnect()
}
}
hybrid_search()
Combined graph proximity and vector similarity search.
The alpha parameter controls the blend between graph
proximity and vector similarity. alpha = 0.0 uses pure
graph distance; alpha = 1.0 uses pure vector similarity.
AstraeaClient$hybrid_search( anchor, query_vector, max_hops = 3L, k = 10L, alpha = 0.5 )
anchorInteger scalar. Anchor node ID for graph proximity.
query_vectorNumeric vector. Query embedding.
max_hopsInteger scalar. Maximum graph hops from anchor.
Default 3L.
kInteger scalar. Number of results. Default 10L.
alphaNumeric scalar in [0, 1]. Blend factor.
Default 0.5.
A list of result entries with node_id and combined
scores.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
dim <- client$ping()$vector_dim
results <- client$hybrid_search(
anchor = a,
query_vector = rep(0.1, dim),
k = b,
alpha = 0.7
)
client$disconnect()
}
}
semantic_neighbors()
Get neighbors ranked by semantic similarity to a concept vector.
AstraeaClient$semantic_neighbors( node_id, concept, direction = "outgoing", k = 10L )
node_idInteger scalar. The node whose neighbors to rank.
conceptNumeric vector. The concept embedding to rank against.
directionCharacter scalar. One of "outgoing",
"incoming", or "both". Default "outgoing".
kInteger scalar. Maximum number of ranked neighbors.
Default 10L.
A list of neighbor entries with node_id and
distance (smaller is closer to the concept).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
dim <- client$ping()$vector_dim
nbrs <- client$semantic_neighbors(a, rep(0.1, dim), k = b)
client$disconnect()
}
}
semantic_walk()
Greedy walk following edges whose targets are most similar to a concept vector.
AstraeaClient$semantic_walk(start, concept, max_hops = 3L)
startInteger scalar. Starting node ID.
conceptNumeric vector. Concept embedding guiding the walk.
max_hopsInteger scalar. Maximum walk length.
Default 3L.
A list representing the walk path.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
dim <- client$ping()$vector_dim
path <- client$semantic_walk(a, rep(0.1, dim), max_hops = 4L)
client$disconnect()
}
}
extract_subgraph()
Extract a subgraph centered on a node and linearize it to text.
AstraeaClient$extract_subgraph( center, hops = 2L, max_nodes = 50L, format = "structured" )
centerInteger scalar. Center node ID.
hopsInteger scalar. Radius in hops. Default 2L.
max_nodesInteger scalar. Maximum number of nodes to include.
Default 50L.
formatCharacter scalar. Output format: one of
"structured", "prose", "triples", or
"json". Default "structured".
A list with extracted subgraph data including text,
node_count, and edge_count.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
sg <- client$extract_subgraph(a, hops = b, max_nodes = 20L)
sg$text
client$disconnect()
}
}
graph_rag()
Execute a full GraphRAG pipeline: extract a subgraph and send it to a language model.
Provide either anchor (a node ID to center the subgraph on)
or question_embedding (a vector to locate the closest node
via vector search), or both.
AstraeaClient$graph_rag( question, anchor = NULL, question_embedding = NULL, hops = 2L, max_nodes = 50L, format = "structured" )
questionCharacter scalar. The natural-language question.
anchorInteger scalar or NULL. Anchor node ID.
question_embeddingNumeric vector or NULL. Embedding
of the question for vector-based anchor selection.
hopsInteger scalar. Subgraph radius. Default 2L.
max_nodesInteger scalar. Maximum subgraph nodes.
Default 50L.
formatCharacter scalar. Linearization format.
Default "structured".
A list with the RAG result, typically including an
answer field.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
answer <- client$graph_rag(
question = "What does Alice work on?",
anchor = a
)
client$disconnect()
}
}
dfs()
Depth-first search starting from a node.
AstraeaClient$dfs(start, max_depth = 3L)
startInteger scalar. The starting node ID.
max_depthInteger scalar. Maximum traversal depth.
Default 3L.
A list of node IDs (integers) in depth-first visitation order.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
visited <- client$dfs(a, max_depth = b)
client$disconnect()
}
}
dfs_at()
Depth-first search as of a specific point in time.
AstraeaClient$dfs_at(start, max_depth = 3L, timestamp)
startInteger scalar. The starting node ID.
max_depthInteger scalar. Maximum traversal depth.
Default 3L.
timestampNumeric scalar. Point in time (ms since epoch).
A list of node IDs (integers) in depth-first visitation
order as of timestamp.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
visited <- client$dfs_at(a, max_depth = b, timestamp = 1672531200000)
client$disconnect()
}
}
find_by_label()
Find all nodes carrying a given label.
AstraeaClient$find_by_label(label)
labelCharacter scalar. The node label to match.
A list of matching node IDs (integers).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
ids <- client$find_by_label("Person")
client$disconnect()
}
}
find_edge_by_type()
Find all edges of a given edge type.
AstraeaClient$find_edge_by_type(edge_type)
edge_typeCharacter scalar. The edge type to match.
A list of entries, each a list with edge_id,
source, and target node IDs.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
edges <- client$find_edge_by_type("KNOWS")
client$disconnect()
}
}
delete_by_label()
Delete every node carrying a given label, along with all its edges.
AstraeaClient$delete_by_label(label)
labelCharacter scalar. The node label to match.
Integer scalar: the number of nodes deleted.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
n_removed <- client$delete_by_label("Temporary")
client$disconnect()
}
}
get_subgraph()
Retrieve the raw subgraph (nodes and edges) around a center node, suitable for visualization or client-side processing.
AstraeaClient$get_subgraph(center, hops = 3L, max_nodes = 50L)
centerInteger scalar. The center node ID.
hopsInteger scalar. Neighborhood radius in hops.
Default 3L.
max_nodesInteger scalar. Maximum number of nodes to return.
Default 50L.
A list with nodes (each a list with id,
labels, properties, has_embedding) and
edges (each a list with id, source,
target, edge_type, properties, weight,
valid_from, valid_to).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
sg <- client$get_subgraph(a, hops = b, max_nodes = 100L)
client$disconnect()
}
}
graph_stats()
Retrieve graph-wide statistics: node and edge counts, per-label node counts, and vector-index information when available.
AstraeaClient$graph_stats()
A named list of statistics, including total_nodes,
total_edges, and labels (a per-label node count).
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
stats <- client$graph_stats()
stats$total_nodes
client$disconnect()
}
}
run_pagerank()
Run the PageRank algorithm over the whole graph or a node subset.
AstraeaClient$run_pagerank( nodes = NULL, damping = 0.85, max_iterations = 100L, tolerance = 1e-06 )
nodesOptional integer vector. Restrict the computation to
these node IDs. NULL (default) uses the whole graph.
dampingNumeric scalar. Damping factor. Default 0.85.
max_iterationsInteger scalar. Maximum iterations.
Default 100L.
toleranceNumeric scalar. Convergence tolerance.
Default 1e-6.
A named list mapping node ID (a character key) to its PageRank score.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
scores <- client$run_pagerank()
client$disconnect()
}
}
run_louvain()
Run Louvain community detection over the whole graph or a subset.
AstraeaClient$run_louvain(nodes = NULL)
nodesOptional integer vector. Restrict the computation to
these node IDs. NULL (default) uses the whole graph.
A list with communities (a named list mapping node ID
to community index) and num_communities.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
res <- client$run_louvain()
res$num_communities
client$disconnect()
}
}
run_connected_components()
Find connected components of the whole graph or a node subset.
AstraeaClient$run_connected_components(nodes = NULL, strong = FALSE)
nodesOptional integer vector. Restrict the computation to
these node IDs. NULL (default) uses the whole graph.
strongLogical scalar. If TRUE, compute strongly
connected components; otherwise weakly connected. Default
FALSE.
A list with components (a list of integer vectors of
node IDs) and count.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
cc <- client$run_connected_components()
cc$count
client$disconnect()
}
}
run_degree_centrality()
Compute degree centrality for the whole graph or a node subset.
AstraeaClient$run_degree_centrality(nodes = NULL, direction = "outgoing")
nodesOptional integer vector. Restrict the computation to
these node IDs. NULL (default) uses the whole graph.
directionCharacter scalar. One of "outgoing"
(default), "incoming", or "both".
A named list mapping node ID (a character key) to its degree-centrality score.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
scores <- client$run_degree_centrality(direction = "both")
client$disconnect()
}
}
run_betweenness_centrality()
Compute betweenness centrality for the whole graph or a node subset.
AstraeaClient$run_betweenness_centrality(nodes = NULL)
nodesOptional integer vector. Restrict the computation to
these node IDs. NULL (default) uses the whole graph.
A named list mapping node ID (a character key) to its betweenness-centrality score.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
scores <- client$run_betweenness_centrality()
client$disconnect()
}
}
create_nodes()
Create multiple nodes in a single batch.
AstraeaClient$create_nodes(nodes_list)
nodes_listA list of node specifications. Each element must
be a list with labels (character vector) and
properties (named list). An optional embedding
(numeric vector) may be included.
An integer vector of created node IDs, in the same order as the input.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
ids <- client$create_nodes(list(
list(labels = "Person", properties = list(name = "Alice")),
list(labels = "Person", properties = list(name = "Bob"))
))
client$disconnect()
}
}
create_edges()
Create multiple edges in a single batch.
AstraeaClient$create_edges(edges_list)
edges_listA list of edge specifications. Each element must
be a list with source, target, and edge_type.
Optional fields: properties, weight,
valid_from, valid_to.
An integer vector of created edge IDs, in the same order as the input.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
eids <- client$create_edges(list(
list(source = a, target = b, edge_type = "KNOWS"),
list(source = b, target = b, edge_type = "FOLLOWS", weight = 0.5)
))
client$disconnect()
}
}
delete_nodes()
Delete multiple nodes. Errors for individual nodes are silently skipped.
AstraeaClient$delete_nodes(node_ids)
node_idsInteger vector of node IDs to delete.
Integer scalar: the count of successfully deleted nodes.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
deleted <- client$delete_nodes(c(a, b))
client$disconnect()
}
}
delete_edges()
Delete multiple edges. Errors for individual edges are silently skipped.
AstraeaClient$delete_edges(edge_ids)
edge_idsInteger vector of edge IDs to delete.
Integer scalar: the count of successfully deleted edges.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
deleted <- client$delete_edges(e)
client$disconnect()
}
}
import_nodes_df()
Import nodes from a data.frame.
Each row becomes a node. One column supplies the label(s), and the remaining columns (excluding any embedding columns) become node properties.
AstraeaClient$import_nodes_df( df, label_col = "label", id_col = NULL, embedding_cols = NULL )
dfA data.frame with one row per node.
label_colCharacter scalar. Name of the column containing
node labels. Default "label".
id_colCharacter scalar or NULL. If non-NULL,
this column is stored in the node properties as an external
identifier.
embedding_colsCharacter vector or NULL. Column names
whose values form the embedding vector.
An integer vector of created node IDs.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
df <- data.frame(
label = c("Person", "Person"),
name = c("Alice", "Bob"),
age = c(30, 25),
stringsAsFactors = FALSE
)
ids <- client$import_nodes_df(df)
client$disconnect()
}
}
import_edges_df()
Import edges from a data.frame.
Each row becomes an edge. Columns supply the source/target node IDs, edge type, and optionally weight and temporal bounds. Remaining columns become edge properties.
AstraeaClient$import_edges_df( df, source_col = "source", target_col = "target", type_col = "type", weight_col = NULL, valid_from_col = NULL, valid_to_col = NULL )
dfA data.frame with one row per edge.
source_colCharacter scalar. Column with source node IDs.
Default "source".
target_colCharacter scalar. Column with target node IDs.
Default "target".
type_colCharacter scalar. Column with edge type strings.
Default "type".
weight_colCharacter scalar or NULL. Column with edge
weights.
valid_from_colCharacter scalar or NULL. Column with
temporal start (ms since epoch).
valid_to_colCharacter scalar or NULL. Column with
temporal end (ms since epoch).
An integer vector of created edge IDs.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
edf <- data.frame(
source = c(a, b),
target = c(b, a),
type = c("KNOWS", "FOLLOWS"),
stringsAsFactors = FALSE
)
eids <- client$import_edges_df(edf)
client$disconnect()
}
}
export_nodes_df()
Export nodes to a data.frame with node_id, a
comma-separated labels column, and flattened property
columns.
AstraeaClient$export_nodes_df(node_ids)
node_idsInteger vector of node IDs to export.
A data.frame with one row per node.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
df <- client$export_nodes_df(c(a, b))
client$disconnect()
}
}
export_bfs_df()
Run BFS from a starting node and return the results as a
data.frame that includes node details.
AstraeaClient$export_bfs_df(start, max_depth = 3L)
startInteger scalar. Starting node ID.
max_depthInteger scalar. Maximum BFS depth.
Default 3L.
A data.frame with node_id, depth,
labels, and flattened property columns.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
bfs_df <- client$export_bfs_df(a, max_depth = b)
client$disconnect()
}
}
results_to_dataframe()
Convert a list of search results to a data.frame.
This is a convenience method for converting results from
vector_search(), hybrid_search(), or similar methods
into a tabular format.
AstraeaClient$results_to_dataframe(results)
resultsA list of result entries (e.g., from
vector_search()). Each entry should be a list with named
elements.
A data.frame with one row per result entry. Returns
an empty data.frame if results is empty.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
dim <- client$ping()$vector_dim
results <- client$vector_search(rep(0.1, dim), k = 5L)
df <- client$results_to_dataframe(results)
client$disconnect()
}
}
nodes_to_dataframe()
Fetch multiple nodes by ID and return as a data.frame.
Similar to export_nodes_df() but preserves the labels
column as a list column (using I) rather than
collapsing to a comma-separated string.
AstraeaClient$nodes_to_dataframe(node_ids)
node_idsInteger vector of node IDs to fetch.
A data.frame with columns id, labels
(list column), and flattened property columns.
\donttest{
if (astraea_server_available()) {
client <- astraea_connect()
a <- client$create_node(c("Person"), list(name = "Alice"))
b <- client$create_node(c("Person"), list(name = "Bob"))
df <- client$nodes_to_dataframe(c(a, b))
df$labels[[1]]
client$disconnect()
}
}
clone()
The objects of this class are cloneable with this method.
AstraeaClient$clone(deep = FALSE)
deepWhether to make a deep clone.
if (astraea_server_available()) { # Connect to a local AstraeaDB server client <- AstraeaClient$new() client$connect() # Health check client$ping() # Create nodes alice_id <- client$create_node( labels = c("Person"), properties = list(name = "Alice", age = 30) ) bob_id <- client$create_node( labels = c("Person"), properties = list(name = "Bob", age = 25) ) # Create an edge edge_id <- client$create_edge( source = alice_id, target = bob_id, edge_type = "KNOWS", properties = list(since = 2020) ) # Traverse the graph client$neighbors(alice_id, direction = "outgoing") client$bfs(alice_id, max_depth = 2L) # Clean up client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$new` ## ------------------------------------------------ client <- AstraeaClient$new() client <- AstraeaClient$new(host = "db.example.com", port = 7688L) client <- AstraeaClient$new(auth_token = "my-secret-token") ## ------------------------------------------------ ## Method `AstraeaClient$connect` ## ------------------------------------------------ if (astraea_server_available()) { client <- AstraeaClient$new() client$connect() } ## ------------------------------------------------ ## Method `AstraeaClient$disconnect` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() client$disconnect() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$is_connected` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() client$is_connected() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$ping` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() info <- client$ping() message(info$version) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim nid <- client$create_node( labels = c("Person"), properties = list(name = "Alice", age = 30), embedding = rep(0.1, dim) ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) node <- client$get_node(a) node$labels node$properties$name client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$update_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) client$update_node(a, list(city = "San Francisco")) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) client$delete_node(a) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) eid <- client$create_edge( source = a, target = b, edge_type = "KNOWS", weight = 0.9 ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") edge <- client$get_edge(e) edge$edge_type client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$update_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") client$update_edge(e, list(strength = "strong")) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") client$delete_edge(e) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$neighbors` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) nbrs <- client$neighbors(a, direction = "outgoing") nbrs_knows <- client$neighbors(a, edge_type = "KNOWS") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$bfs` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) bfs_result <- client$bfs(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$shortest_path` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sp <- client$shortest_path(a, b, weighted = TRUE) sp$path sp$cost client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$neighbors_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) # Neighbors as of January 1 2023 (ms since epoch) nbrs <- client$neighbors_at(a, "outgoing", 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$bfs_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) result <- client$bfs_at(a, max_depth = b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$shortest_path_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sp <- client$shortest_path_at(a, b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$query` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() result <- client$query("MATCH (p:Person) RETURN p.name, p.city") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$vector_search` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim results <- client$vector_search(rep(0.1, dim), k = 5L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$hybrid_search` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim results <- client$hybrid_search( anchor = a, query_vector = rep(0.1, dim), k = b, alpha = 0.7 ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$semantic_neighbors` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim nbrs <- client$semantic_neighbors(a, rep(0.1, dim), k = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$semantic_walk` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim path <- client$semantic_walk(a, rep(0.1, dim), max_hops = 4L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$extract_subgraph` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sg <- client$extract_subgraph(a, hops = b, max_nodes = 20L) sg$text client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$graph_rag` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) answer <- client$graph_rag( question = "What does Alice work on?", anchor = a ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$dfs` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) visited <- client$dfs(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$dfs_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) visited <- client$dfs_at(a, max_depth = b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$find_by_label` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() ids <- client$find_by_label("Person") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$find_edge_by_type` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() edges <- client$find_edge_by_type("KNOWS") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_by_label` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() n_removed <- client$delete_by_label("Temporary") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_subgraph` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sg <- client$get_subgraph(a, hops = b, max_nodes = 100L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$graph_stats` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() stats <- client$graph_stats() stats$total_nodes client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_pagerank` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_pagerank() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_louvain` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() res <- client$run_louvain() res$num_communities client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_connected_components` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() cc <- client$run_connected_components() cc$count client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_degree_centrality` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_degree_centrality(direction = "both") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_betweenness_centrality` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_betweenness_centrality() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_nodes` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() ids <- client$create_nodes(list( list(labels = "Person", properties = list(name = "Alice")), list(labels = "Person", properties = list(name = "Bob")) )) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_edges` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) eids <- client$create_edges(list( list(source = a, target = b, edge_type = "KNOWS"), list(source = b, target = b, edge_type = "FOLLOWS", weight = 0.5) )) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_nodes` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) deleted <- client$delete_nodes(c(a, b)) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_edges` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() deleted <- client$delete_edges(e) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$import_nodes_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() df <- data.frame( label = c("Person", "Person"), name = c("Alice", "Bob"), age = c(30, 25), stringsAsFactors = FALSE ) ids <- client$import_nodes_df(df) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$import_edges_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) edf <- data.frame( source = c(a, b), target = c(b, a), type = c("KNOWS", "FOLLOWS"), stringsAsFactors = FALSE ) eids <- client$import_edges_df(edf) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$export_nodes_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) df <- client$export_nodes_df(c(a, b)) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$export_bfs_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) bfs_df <- client$export_bfs_df(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$results_to_dataframe` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim results <- client$vector_search(rep(0.1, dim), k = 5L) df <- client$results_to_dataframe(results) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$nodes_to_dataframe` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) df <- client$nodes_to_dataframe(c(a, b)) df$labels[[1]] client$disconnect() }if (astraea_server_available()) { # Connect to a local AstraeaDB server client <- AstraeaClient$new() client$connect() # Health check client$ping() # Create nodes alice_id <- client$create_node( labels = c("Person"), properties = list(name = "Alice", age = 30) ) bob_id <- client$create_node( labels = c("Person"), properties = list(name = "Bob", age = 25) ) # Create an edge edge_id <- client$create_edge( source = alice_id, target = bob_id, edge_type = "KNOWS", properties = list(since = 2020) ) # Traverse the graph client$neighbors(alice_id, direction = "outgoing") client$bfs(alice_id, max_depth = 2L) # Clean up client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$new` ## ------------------------------------------------ client <- AstraeaClient$new() client <- AstraeaClient$new(host = "db.example.com", port = 7688L) client <- AstraeaClient$new(auth_token = "my-secret-token") ## ------------------------------------------------ ## Method `AstraeaClient$connect` ## ------------------------------------------------ if (astraea_server_available()) { client <- AstraeaClient$new() client$connect() } ## ------------------------------------------------ ## Method `AstraeaClient$disconnect` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() client$disconnect() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$is_connected` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() client$is_connected() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$ping` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() info <- client$ping() message(info$version) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim nid <- client$create_node( labels = c("Person"), properties = list(name = "Alice", age = 30), embedding = rep(0.1, dim) ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) node <- client$get_node(a) node$labels node$properties$name client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$update_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) client$update_node(a, list(city = "San Francisco")) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_node` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) client$delete_node(a) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) eid <- client$create_edge( source = a, target = b, edge_type = "KNOWS", weight = 0.9 ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") edge <- client$get_edge(e) edge$edge_type client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$update_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") client$update_edge(e, list(strength = "strong")) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_edge` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) e <- client$create_edge(a, b, "KNOWS") client$delete_edge(e) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$neighbors` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) nbrs <- client$neighbors(a, direction = "outgoing") nbrs_knows <- client$neighbors(a, edge_type = "KNOWS") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$bfs` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) bfs_result <- client$bfs(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$shortest_path` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sp <- client$shortest_path(a, b, weighted = TRUE) sp$path sp$cost client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$neighbors_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) # Neighbors as of January 1 2023 (ms since epoch) nbrs <- client$neighbors_at(a, "outgoing", 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$bfs_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) result <- client$bfs_at(a, max_depth = b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$shortest_path_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sp <- client$shortest_path_at(a, b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$query` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() result <- client$query("MATCH (p:Person) RETURN p.name, p.city") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$vector_search` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim results <- client$vector_search(rep(0.1, dim), k = 5L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$hybrid_search` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim results <- client$hybrid_search( anchor = a, query_vector = rep(0.1, dim), k = b, alpha = 0.7 ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$semantic_neighbors` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim nbrs <- client$semantic_neighbors(a, rep(0.1, dim), k = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$semantic_walk` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) dim <- client$ping()$vector_dim path <- client$semantic_walk(a, rep(0.1, dim), max_hops = 4L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$extract_subgraph` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sg <- client$extract_subgraph(a, hops = b, max_nodes = 20L) sg$text client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$graph_rag` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) answer <- client$graph_rag( question = "What does Alice work on?", anchor = a ) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$dfs` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) visited <- client$dfs(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$dfs_at` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) visited <- client$dfs_at(a, max_depth = b, timestamp = 1672531200000) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$find_by_label` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() ids <- client$find_by_label("Person") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$find_edge_by_type` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() edges <- client$find_edge_by_type("KNOWS") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_by_label` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() n_removed <- client$delete_by_label("Temporary") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$get_subgraph` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) sg <- client$get_subgraph(a, hops = b, max_nodes = 100L) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$graph_stats` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() stats <- client$graph_stats() stats$total_nodes client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_pagerank` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_pagerank() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_louvain` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() res <- client$run_louvain() res$num_communities client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_connected_components` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() cc <- client$run_connected_components() cc$count client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_degree_centrality` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_degree_centrality(direction = "both") client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$run_betweenness_centrality` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() scores <- client$run_betweenness_centrality() client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_nodes` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() ids <- client$create_nodes(list( list(labels = "Person", properties = list(name = "Alice")), list(labels = "Person", properties = list(name = "Bob")) )) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$create_edges` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) eids <- client$create_edges(list( list(source = a, target = b, edge_type = "KNOWS"), list(source = b, target = b, edge_type = "FOLLOWS", weight = 0.5) )) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_nodes` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) deleted <- client$delete_nodes(c(a, b)) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$delete_edges` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() deleted <- client$delete_edges(e) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$import_nodes_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() df <- data.frame( label = c("Person", "Person"), name = c("Alice", "Bob"), age = c(30, 25), stringsAsFactors = FALSE ) ids <- client$import_nodes_df(df) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$import_edges_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) edf <- data.frame( source = c(a, b), target = c(b, a), type = c("KNOWS", "FOLLOWS"), stringsAsFactors = FALSE ) eids <- client$import_edges_df(edf) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$export_nodes_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) df <- client$export_nodes_df(c(a, b)) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$export_bfs_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) bfs_df <- client$export_bfs_df(a, max_depth = b) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$results_to_dataframe` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() dim <- client$ping()$vector_dim results <- client$vector_search(rep(0.1, dim), k = 5L) df <- client$results_to_dataframe(results) client$disconnect() } ## ------------------------------------------------ ## Method `AstraeaClient$nodes_to_dataframe` ## ------------------------------------------------ if (astraea_server_available()) { client <- astraea_connect() a <- client$create_node(c("Person"), list(name = "Alice")) b <- client$create_node(c("Person"), list(name = "Bob")) df <- client$nodes_to_dataframe(c(a, b)) df$labels[[1]] client$disconnect() }
Given vectors of source and destination ports, determines which port represents the "service" (server) side of the connection using a three-tier heuristic:
If exactly one port is in the privileged range (< 1024), it is the service port.
If exactly one port appears in the well-known ports lookup table, it wins.
Otherwise the lower port number is chosen (statistically more likely to be the service).
classify_service_port(src_port, dst_port)classify_service_port(src_port, dst_port)
src_port |
Integer vector of source port numbers. |
dst_port |
Integer vector of destination port numbers. |
Integer vector of the same length containing the service port for
each pair. Returns NA_integer_ where either input is NA.
classify_service_port(52000, 443) classify_service_port(c(52000, 3306), c(80, 52000))classify_service_port(52000, 443) classify_service_port(c(52000, 3306), c(80, 52000))
Returns the human-readable service name for a given port number based on
the package's built-in well-known ports table, or NA_character_ if
the port is not recognized.
port_service_name(port)port_service_name(port)
port |
Integer vector of port numbers. |
Character vector of service names, with NA_character_ for
unrecognized ports.
port_service_name(443) port_service_name(c(80, 3306, 99999))port_service_name(443) port_service_name(c(80, 3306, 99999))
Functions for classifying network service ports and looking up well-known port names. Used by the PCAP ingestion script to aggregate packets into flows keyed by service port.
An R6 class that provides a unified interface to AstraeaDB by automatically
selecting the best available transport. It always creates a JSON/TCP client
(AstraeaClient) and optionally creates an Arrow Flight client
(ArrowClient) when the arrow package is installed.
The UnifiedClient delegates all CRUD operations (node, edge, traversal, vector search, etc.) to the JSON/TCP client. For GQL query execution, it prefers the Arrow Flight transport when available, as Arrow provides more efficient columnar data transfer for analytical workloads. If Arrow is not available or its connection fails, queries transparently fall back to the JSON/TCP transport.
Typical usage:
Create a UnifiedClient instance.
Call $connect() to establish connections.
Use CRUD methods ($create_node(), $get_node(), etc.)
and query methods ($query(), $query_df()).
Call $disconnect() when finished.
json_clientAn AstraeaClient instance for JSON/TCP
communication. Always available.
arrow_clientAn ArrowClient instance for Arrow
Flight communication, or NULL if the arrow package is not
installed or initialization failed.
use_arrowLogical. Whether Arrow Flight transport is active and should be used for queries.
new()
Create a new UnifiedClient.
Always creates a JSON/TCP client. If the arrow package is available, also creates an Arrow Flight client. Arrow initialization failure is non-fatal and results in a message.
UnifiedClient$new( host = "127.0.0.1", port = 7687L, flight_uri = NULL, auth_token = NULL )
hostCharacter. Server hostname for JSON/TCP transport.
Defaults to "127.0.0.1".
portInteger. Server port for JSON/TCP transport.
Defaults to 7687L.
flight_uriCharacter or NULL. Arrow Flight gRPC URI.
If NULL, constructed automatically as
sprintf("grpc://%s:7689", host).
auth_tokenCharacter or NULL. Authentication token for
the JSON/TCP client.
A new UnifiedClient object.
connect()
Connect to AstraeaDB server(s).
Connects the JSON/TCP client. If Arrow Flight is enabled, also attempts to connect the Arrow client. Arrow connection failure is non-fatal and results in a fallback to JSON/TCP with a message.
UnifiedClient$connect()
Invisibly returns self for method chaining.
disconnect()
Disconnect all client connections.
Closes the JSON/TCP connection and, if active, the Arrow Flight connection.
UnifiedClient$disconnect()
Invisibly returns self for method chaining.
create_node()
Create a node. Delegates to the JSON/TCP client.
UnifiedClient$create_node(labels, properties, embedding = NULL)
labelsList of character labels for the node.
propertiesNamed list of node properties.
embeddingOptional numeric vector for vector similarity search.
Integer. The ID of the newly created node.
get_node()
Get a node by ID. Delegates to the JSON/TCP client.
UnifiedClient$get_node(node_id)
node_idInteger. The node ID.
A list containing node data (labels, properties, etc.).
update_node()
Update a node's properties. Delegates to the JSON/TCP client.
UnifiedClient$update_node(node_id, properties)
node_idInteger. The node ID.
propertiesNamed list of properties to merge.
The server response data.
delete_node()
Delete a node and its connected edges. Delegates to the JSON/TCP client.
UnifiedClient$delete_node(node_id)
node_idInteger. The node ID.
The server response data.
create_edge()
Create an edge. Delegates to the JSON/TCP client.
UnifiedClient$create_edge( source, target, edge_type, properties = list(), weight = 1, valid_from = NULL, valid_to = NULL )
sourceInteger. Source node ID.
targetInteger. Target node ID.
edge_typeCharacter. The edge type label.
propertiesNamed list of edge properties.
weightNumeric. Edge weight. Defaults to 1.0.
valid_fromNumeric or NULL. Temporal start (ms epoch).
valid_toNumeric or NULL. Temporal end (ms epoch).
Integer. The ID of the newly created edge.
get_edge()
Get an edge by ID. Delegates to the JSON/TCP client.
UnifiedClient$get_edge(edge_id)
edge_idInteger. The edge ID.
A list containing edge data.
update_edge()
Update an edge's properties. Delegates to the JSON/TCP client.
UnifiedClient$update_edge(edge_id, properties)
edge_idInteger. The edge ID.
propertiesNamed list of properties to merge.
The server response data.
delete_edge()
Delete an edge. Delegates to the JSON/TCP client.
UnifiedClient$delete_edge(edge_id)
edge_idInteger. The edge ID.
The server response data.
neighbors()
Get neighbors of a node. Delegates to the JSON/TCP client.
UnifiedClient$neighbors(node_id, direction = "outgoing", edge_type = NULL)
node_idInteger. The node ID.
directionCharacter. One of "outgoing", "incoming",
or "both". Defaults to "outgoing".
edge_typeCharacter or NULL. Filter by edge type.
A list of neighbor entries.
bfs()
Breadth-first search from a start node. Delegates to the JSON/TCP client.
UnifiedClient$bfs(start, max_depth = 3L)
startInteger. Starting node ID.
max_depthInteger. Maximum traversal depth. Defaults to 3L.
A list of entries with node_id and depth.
shortest_path()
Find the shortest path between two nodes. Delegates to the JSON/TCP client.
UnifiedClient$shortest_path(from_node, to_node, weighted = FALSE)
from_nodeInteger. Source node ID.
to_nodeInteger. Target node ID.
weightedLogical. Use edge weights? Defaults to FALSE.
A list with path information.
neighbors_at()
Get neighbors at a specific point in time. Delegates to the JSON/TCP client.
UnifiedClient$neighbors_at( node_id, direction = "outgoing", timestamp, edge_type = NULL )
node_idInteger. The node ID.
directionCharacter. Direction filter. Defaults to
"outgoing".
timestampNumeric. Point-in-time timestamp (ms epoch).
edge_typeCharacter or NULL. Filter by edge type.
A list of neighbor entries valid at the given timestamp.
bfs_at()
BFS traversal at a specific point in time. Delegates to the JSON/TCP client.
UnifiedClient$bfs_at(start, max_depth = 3L, timestamp)
startInteger. Starting node ID.
max_depthInteger. Maximum depth. Defaults to 3L.
timestampNumeric. Point-in-time timestamp (ms epoch).
A list of entries with node_id and depth.
shortest_path_at()
Find shortest path at a specific point in time. Delegates to the JSON/TCP client.
UnifiedClient$shortest_path_at(from_node, to_node, timestamp, weighted = FALSE)
from_nodeInteger. Source node ID.
to_nodeInteger. Target node ID.
timestampNumeric. Point-in-time timestamp (ms epoch).
weightedLogical. Use edge weights? Defaults to FALSE.
A list with path information.
vector_search()
k-nearest neighbor vector search. Delegates to the JSON/TCP client.
UnifiedClient$vector_search(query_vector, k = 10L)
query_vectorNumeric vector. The query embedding.
kInteger. Number of results. Defaults to 10L.
A list of search results with node_id and
similarity.
hybrid_search()
Hybrid graph-vector search. Delegates to the JSON/TCP client.
UnifiedClient$hybrid_search( anchor, query_vector, max_hops = 3L, k = 10L, alpha = 0.5 )
anchorInteger. Anchor node ID for graph proximity.
query_vectorNumeric vector. Query embedding for similarity.
max_hopsInteger. Maximum graph hops. Defaults to 3L.
kInteger. Number of results. Defaults to 10L.
alphaNumeric. Balance between graph (0) and vector (1).
Defaults to 0.5.
A list of search results.
semantic_neighbors()
Get neighbors ranked by semantic similarity. Delegates to the JSON/TCP client.
UnifiedClient$semantic_neighbors( node_id, concept, direction = "outgoing", k = 10L )
node_idInteger. The node ID.
conceptNumeric vector. Concept embedding for ranking.
directionCharacter. Direction filter. Defaults to
"outgoing".
kInteger. Number of results. Defaults to 10L.
A list of neighbor entries with similarity scores.
semantic_walk()
Greedy semantic walk following edges most similar to a concept. Delegates to the JSON/TCP client.
UnifiedClient$semantic_walk(start, concept, max_hops = 3L)
startInteger. Starting node ID.
conceptNumeric vector. Concept embedding for guidance.
max_hopsInteger. Maximum walk length. Defaults to 3L.
A list representing the walk path.
extract_subgraph()
Extract a subgraph centered on a node. Delegates to the JSON/TCP client.
UnifiedClient$extract_subgraph( center, hops = 2L, max_nodes = 50L, format = "structured" )
centerInteger. Center node ID.
hopsInteger. Radius in hops. Defaults to 2L.
max_nodesInteger. Maximum nodes to return. Defaults to
50L.
formatCharacter. Output format: "structured",
"prose", "triples", or "json".
Defaults to "structured".
A list with subgraph data and linearized text.
graph_rag()
Execute a GraphRAG query. Delegates to the JSON/TCP client.
UnifiedClient$graph_rag( question, anchor = NULL, question_embedding = NULL, hops = 2L, max_nodes = 50L, format = "structured" )
questionCharacter. The question to answer.
anchorInteger or NULL. Anchor node ID.
question_embeddingNumeric vector or NULL. Embedding of
the question.
hopsInteger. Subgraph radius. Defaults to 2L.
max_nodesInteger. Maximum subgraph nodes. Defaults to
50L.
formatCharacter. Linearization format. Defaults to
"structured".
A list with the LLM-generated answer and context.
dfs()
Depth-first search from a node. Delegates to the JSON/TCP client.
UnifiedClient$dfs(start, max_depth = 3L)
startInteger. The starting node ID.
max_depthInteger. Maximum traversal depth. Default 3L.
A list of node IDs in depth-first visitation order.
dfs_at()
Depth-first search as of a point in time. Delegates to the JSON/TCP client.
UnifiedClient$dfs_at(start, max_depth = 3L, timestamp)
startInteger. The starting node ID.
max_depthInteger. Maximum traversal depth. Default 3L.
timestampNumeric. Point in time (ms since epoch).
A list of node IDs in depth-first visitation order.
find_by_label()
Find nodes by label. Delegates to the JSON/TCP client.
UnifiedClient$find_by_label(label)
labelCharacter. The node label to match.
A list of matching node IDs.
find_edge_by_type()
Find edges by edge type. Delegates to the JSON/TCP client.
UnifiedClient$find_edge_by_type(edge_type)
edge_typeCharacter. The edge type to match.
A list of entries with edge_id, source,
target.
delete_by_label()
Delete all nodes with a label. Delegates to the JSON/TCP client.
UnifiedClient$delete_by_label(label)
labelCharacter. The node label to match.
Integer scalar: the number of nodes deleted.
get_subgraph()
Retrieve the raw subgraph around a node. Delegates to the JSON/TCP client.
UnifiedClient$get_subgraph(center, hops = 3L, max_nodes = 50L)
centerInteger. The center node ID.
hopsInteger. Neighborhood radius. Default 3L.
max_nodesInteger. Maximum nodes to return. Default 50L.
A list with nodes and edges.
graph_stats()
Retrieve graph-wide statistics. Delegates to the JSON/TCP client.
UnifiedClient$graph_stats()
A named list of statistics.
run_pagerank()
Run PageRank. Delegates to the JSON/TCP client.
UnifiedClient$run_pagerank( nodes = NULL, damping = 0.85, max_iterations = 100L, tolerance = 1e-06 )
nodesOptional integer vector restricting the computation.
dampingNumeric. Damping factor. Default 0.85.
max_iterationsInteger. Maximum iterations. Default 100L.
toleranceNumeric. Convergence tolerance. Default 1e-6.
A named list mapping node ID to PageRank score.
run_louvain()
Run Louvain community detection. Delegates to the JSON/TCP client.
UnifiedClient$run_louvain(nodes = NULL)
nodesOptional integer vector restricting the computation.
A list with communities and num_communities.
run_connected_components()
Find connected components. Delegates to the JSON/TCP client.
UnifiedClient$run_connected_components(nodes = NULL, strong = FALSE)
nodesOptional integer vector restricting the computation.
strongLogical. Strongly (TRUE) or weakly
(FALSE, default) connected.
A list with components and count.
run_degree_centrality()
Compute degree centrality. Delegates to the JSON/TCP client.
UnifiedClient$run_degree_centrality(nodes = NULL, direction = "outgoing")
nodesOptional integer vector restricting the computation.
directionCharacter. "outgoing" (default),
"incoming", or "both".
A named list mapping node ID to degree-centrality score.
run_betweenness_centrality()
Compute betweenness centrality. Delegates to the JSON/TCP client.
UnifiedClient$run_betweenness_centrality(nodes = NULL)
nodesOptional integer vector restricting the computation.
A named list mapping node ID to betweenness-centrality score.
create_nodes()
Create multiple nodes. Delegates to the JSON/TCP client.
UnifiedClient$create_nodes(nodes_list)
nodes_listA list of lists, each with labels,
properties, and optionally embedding.
An integer vector of created node IDs.
create_edges()
Create multiple edges. Delegates to the JSON/TCP client.
UnifiedClient$create_edges(edges_list)
edges_listA list of lists, each with source,
target, edge_type, and optionally properties,
weight, valid_from, valid_to.
An integer vector of created edge IDs.
delete_nodes()
Delete multiple nodes. Delegates to the JSON/TCP client.
UnifiedClient$delete_nodes(node_ids)
node_idsInteger vector of node IDs to delete.
Integer. Number of successfully deleted nodes.
delete_edges()
Delete multiple edges. Delegates to the JSON/TCP client.
UnifiedClient$delete_edges(edge_ids)
edge_idsInteger vector of edge IDs to delete.
Integer. Number of successfully deleted edges.
import_nodes_df()
Import nodes from a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$import_nodes_df( df, label_col = "label", id_col = NULL, embedding_cols = NULL )
dfA data.frame containing node data.
label_colCharacter. Column name for labels.
Defaults to "label".
id_colCharacter or NULL. Column for external IDs.
embedding_colsCharacter vector or NULL. Columns for
embedding values.
An integer vector of created node IDs.
import_edges_df()
Import edges from a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$import_edges_df( df, source_col = "source", target_col = "target", type_col = "type", weight_col = NULL, valid_from_col = NULL, valid_to_col = NULL )
dfA data.frame containing edge data.
source_colCharacter. Column for source node IDs.
Defaults to "source".
target_colCharacter. Column for target node IDs.
Defaults to "target".
type_colCharacter. Column for edge types.
Defaults to "type".
weight_colCharacter or NULL. Column for weights.
valid_from_colCharacter or NULL. Column for temporal
start.
valid_to_colCharacter or NULL. Column for temporal end.
An integer vector of created edge IDs.
export_nodes_df()
Export nodes to a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$export_nodes_df(node_ids)
node_idsInteger vector of node IDs.
A data.frame with columns for node ID, labels, and properties.
export_bfs_df()
Run BFS and return results as a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$export_bfs_df(start, max_depth = 3L)
startInteger. Starting node ID.
max_depthInteger. Maximum depth. Defaults to 3L.
A data.frame with BFS results including node details.
results_to_dataframe()
Convert search results to a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$results_to_dataframe(results)
resultsA list of result entries.
A data.frame with one row per result.
nodes_to_dataframe()
Fetch nodes by ID and return as a data.frame. Delegates to the JSON/TCP client.
UnifiedClient$nodes_to_dataframe(node_ids)
node_idsInteger vector of node IDs.
A data.frame with columns for ID, labels, and properties.
ping()
Health check. Delegates to the JSON/TCP client.
UnifiedClient$ping()
A list with server status information.
query()
Execute a GQL query.
Uses Arrow Flight transport if available for higher performance. Falls back to JSON/TCP transport otherwise.
UnifiedClient$query(gql)
gqlCharacter. A GQL query string.
Query results. An Arrow Table when using Arrow transport, or a list when using JSON/TCP.
\donttest{
if (astraea_server_available()) {
client <- UnifiedClient$new()
client$connect()
result <- client$query("MATCH (n:Person) RETURN n.name")
client$disconnect()
}
}
query_df()
Execute a GQL query and return a data.frame.
Uses Arrow Flight transport if available. Falls back to JSON/TCP, converting the result to a data.frame.
UnifiedClient$query_df(gql)
gqlCharacter. A GQL query string.
A data.frame containing the query results.
\donttest{
if (astraea_server_available()) {
client <- UnifiedClient$new()
client$connect()
df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age")
client$disconnect()
}
}
is_arrow_enabled()
Check whether Arrow Flight transport is currently active.
UnifiedClient$is_arrow_enabled()
Logical. TRUE if Arrow Flight is enabled and connected,
FALSE otherwise.
print()
Print a summary of the UnifiedClient.
UnifiedClient$print(...)
...Ignored. Present for compatibility with the generic.
Invisibly returns self.
if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { # Basic usage client <- UnifiedClient$new() client$connect() # CRUD operations use JSON/TCP node_id <- client$create_node(list("Person"), list(name = "Alice", age = 30)) node <- client$get_node(node_id) # Queries use Arrow Flight if available, otherwise JSON/TCP df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") # Check transport status client$is_arrow_enabled() client$disconnect() # With authentication client <- UnifiedClient$new(auth_token = "my-secret-token") client$connect() # Custom Flight URI client <- UnifiedClient$new( host = "db.example.com", port = 7687L, flight_uri = "grpc://db.example.com:7689" ) client$connect() } ## ------------------------------------------------ ## Method `UnifiedClient$query` ## ------------------------------------------------ if (astraea_server_available()) { client <- UnifiedClient$new() client$connect() result <- client$query("MATCH (n:Person) RETURN n.name") client$disconnect() } ## ------------------------------------------------ ## Method `UnifiedClient$query_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- UnifiedClient$new() client$connect() df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") client$disconnect() }if (requireNamespace("arrow", quietly = TRUE) && astraea_server_available(port = 7689L)) { # Basic usage client <- UnifiedClient$new() client$connect() # CRUD operations use JSON/TCP node_id <- client$create_node(list("Person"), list(name = "Alice", age = 30)) node <- client$get_node(node_id) # Queries use Arrow Flight if available, otherwise JSON/TCP df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") # Check transport status client$is_arrow_enabled() client$disconnect() # With authentication client <- UnifiedClient$new(auth_token = "my-secret-token") client$connect() # Custom Flight URI client <- UnifiedClient$new( host = "db.example.com", port = 7687L, flight_uri = "grpc://db.example.com:7689" ) client$connect() } ## ------------------------------------------------ ## Method `UnifiedClient$query` ## ------------------------------------------------ if (astraea_server_available()) { client <- UnifiedClient$new() client$connect() result <- client$query("MATCH (n:Person) RETURN n.name") client$disconnect() } ## ------------------------------------------------ ## Method `UnifiedClient$query_df` ## ------------------------------------------------ if (astraea_server_available()) { client <- UnifiedClient$new() client$connect() df <- client$query_df("MATCH (n:Person) RETURN n.name, n.age") client$disconnect() }