Class Velr
- All Implemented Interfaces:
AutoCloseable
A Velr instance owns the native database handle and any child handles opened from it:
result streams, result tables, transactions, and explain traces. Close the connection when it is
no longer needed, preferably with try-with-resources. Closing a connection closes any still-open
child handles first.
The driver is synchronous. Queries return streaming handles for multi-table results and table handles for single-table results. Arrow bindings and vector embedder registration are available directly on the connection and, for Arrow input, inside explicit transactions.
-
Method Summary
Modifier and TypeMethodDescriptionbeginTx()Begin an explicit transaction.voidbindArrow(String logical, ArrowColumn... columns) Bind single-chunk Arrow C Data Interface columns as a logical table.voidbindArrow(String logical, List<ArrowColumn> columns) Bind single-chunk Arrow C Data Interface columns as a logical table.voidbindArrowChunks(String logical, ArrowColumn... columns) Bind chunked Arrow C Data Interface columns as a logical table.voidbindArrowChunks(String logical, List<ArrowColumn> columns) Bind chunked Arrow C Data Interface columns as a logical table.voidbindArrowIpc(String logical, byte[] ipcBytes) Bind Arrow IPC file / Feather v2 bytes as a logical table.voidclose()Close this connection and any still-open child handles.intReturn the schema version supported by the bundled Velr runtime.Execute an openCypher statement and stream every result table it produces.exec(String cypher, QueryOptions options) Execute an openCypher statement with query options and stream every result table it produces.Execute an openCypher statement that is expected to produce exactly one result table.execOne(String cypher, QueryOptions options) Execute an openCypher statement with query options that is expected to produce exactly one result table.Build an execution plan for an openCypher statement.explainAnalyze(String cypher) Execute and profile an openCypher statement, returning the resulting explain trace.booleanisClosed()Return whether this connection has been closed.migrate()Migrate the database schema to the version supported by the bundled Velr runtime.booleanReturn whether the database should be migrated before normal use.static Velropen()Open an in-memory Velr database.static VelrOpen a Velr database.static VelropenReadonly(String path) Open an existing Velr database in read-only mode.Execute an openCypher statement and collect the single result table as object maps.query(String cypher, QueryOptions options) Execute an openCypher statement with query options and collect the single result table as object maps.voidregisterChild(ai.velr.ChildHandle child) Driver-internal child-handle registration hook.voidregisterVectorEmbedder(String name, VectorEmbedder embedder) Register a named vector embedding callback.voidExecute an openCypher statement and discard any result tables.voidrun(String cypher, QueryOptions options) Execute an openCypher statement with query options and discard any result tables.intReturn the schema version stored in the database file.<T> Ttransaction(TransactionCallback<T> callback) Run a callback inside a transaction.voidunregisterChild(ai.velr.ChildHandle child) Driver-internal child-handle registration hook.
-
Method Details
-
open
Open an in-memory Velr database.- Returns:
- an open Velr connection
-
open
Open a Velr database.Pass
nullto open an in-memory database. Passing a path opens or creates the database file at that location.- Parameters:
path- database path, ornullfor an in-memory database- Returns:
- an open Velr connection
-
openReadonly
Open an existing Velr database in read-only mode.- Parameters:
path- database path- Returns:
- an open read-only Velr connection
-
isClosed
public boolean isClosed()Return whether this connection has been closed.- Returns:
trueafterclose()has completed
-
schemaVersion
public int schemaVersion()Return the schema version stored in the database file.- Returns:
- the database schema version
-
currentSchemaVersion
public int currentSchemaVersion()Return the schema version supported by the bundled Velr runtime.- Returns:
- the current Velr schema version
-
needsMigration
public boolean needsMigration()Return whether the database should be migrated before normal use.- Returns:
truewhenmigrate()has work to perform
-
migrate
Migrate the database schema to the version supported by the bundled Velr runtime.- Returns:
- a report describing the migration status and applied steps
-
exec
Execute an openCypher statement and stream every result table it produces.Use this method for statements that may produce multiple tables. Close the returned stream when finished, or use try-with-resources.
- Parameters:
cypher- openCypher statement- Returns:
- a stream of result tables
-
exec
Execute an openCypher statement with query options and stream every result table it produces.- Parameters:
cypher- openCypher statementoptions- query options such as parameters and row limits- Returns:
- a stream of result tables
-
execOne
Execute an openCypher statement that is expected to produce exactly one result table.Use
exec(String)when a statement may produce multiple tables. Close the returned table when finished, or use try-with-resources.- Parameters:
cypher- openCypher statement- Returns:
- the single result table
-
execOne
Execute an openCypher statement with query options that is expected to produce exactly one result table.- Parameters:
cypher- openCypher statementoptions- query options such as parameters and row limits- Returns:
- the single result table
-
run
Execute an openCypher statement and discard any result tables.- Parameters:
cypher- openCypher statement
-
run
Execute an openCypher statement with query options and discard any result tables.- Parameters:
cypher- openCypher statementoptions- query options such as parameters and row limits
-
query
Execute an openCypher statement and collect the single result table as object maps.Column names become map keys. Values are the Java-native rendering returned by
Cell.asObject().- Parameters:
cypher- openCypher statement- Returns:
- collected rows
-
query
Execute an openCypher statement with query options and collect the single result table as object maps.- Parameters:
cypher- openCypher statementoptions- query options such as parameters and row limits- Returns:
- collected rows
-
beginTx
Begin an explicit transaction.Commit or roll back the returned transaction. Closing a transaction without committing or rolling back closes the native transaction handle without committing.
- Returns:
- an open transaction
-
transaction
Run a callback inside a transaction.The transaction is committed when the callback returns normally and the transaction is still open. If the callback throws, or if commit is not reached, the transaction is rolled back when it is still open.
- Type Parameters:
T- callback result type- Parameters:
callback- transaction callback- Returns:
- the callback result
- Throws:
Exception- if the callback or commit/rollback logic throws
-
explain
Build an execution plan for an openCypher statement.- Parameters:
cypher- openCypher statement- Returns:
- an explain trace
-
explainAnalyze
Execute and profile an openCypher statement, returning the resulting explain trace.- Parameters:
cypher- openCypher statement- Returns:
- an explain-analyze trace
-
bindArrowIpc
Bind Arrow IPC file / Feather v2 bytes as a logical table.The byte array is borrowed only for the duration of the call. Velr decodes the IPC file and owns the resulting Arrow arrays before this method returns. Arrow IPC stream bytes are not accepted by this method.
- Parameters:
logical- logical table name to expose to queriesipcBytes- Arrow IPC file / Feather v2 bytes
-
bindArrow
Bind single-chunk Arrow C Data Interface columns as a logical table.For each column, the
ArrowArrayaddress is transferred to Velr by this call. Do not use or release transferred arrays after calling this method. TheArrowSchemaaddress is not consumed and may be released after this method returns.- Parameters:
logical- logical table name to expose to queriescolumns- one or more Arrow columns
-
bindArrow
Bind single-chunk Arrow C Data Interface columns as a logical table.- Parameters:
logical- logical table name to expose to queriescolumns- one or more Arrow columns
-
bindArrowChunks
Bind chunked Arrow C Data Interface columns as a logical table.Each column may contain one or more chunks. For every chunk, the
ArrowArrayaddress is transferred to Velr by this call. Do not use or release transferred arrays after calling this method. TheArrowSchemaaddress is not consumed and may be released after this method returns.- Parameters:
logical- logical table name to expose to queriescolumns- one or more Arrow columns
-
bindArrowChunks
Bind chunked Arrow C Data Interface columns as a logical table.- Parameters:
logical- logical table name to expose to queriescolumns- one or more Arrow columns
-
registerVectorEmbedder
Register a named vector embedding callback.Reference the same name from
CREATE VECTOR INDEX ... OPTIONS { indexConfig: { embedder: 'name' } }. Velr calls the embedder when indexed source values change and when vector queries need query text to be embedded.- Parameters:
name- embedder name used by vector index optionsembedder- callback that returns one vector per input
-
close
public void close()Close this connection and any still-open child handles.- Specified by:
closein interfaceAutoCloseable
-
registerChild
public void registerChild(ai.velr.ChildHandle child) Driver-internal child-handle registration hook. -
unregisterChild
public void unregisterChild(ai.velr.ChildHandle child) Driver-internal child-handle registration hook.
-