Arrow interoperability

group Arrow interoperability

Arrow C Data, C Stream, and IPC readers, results, and buffers.

Functions

LanceDBError lancedb_table_nearest_to(const LanceDBTable *table, const float *vector, size_t dimension, size_t limit, const char *column, struct FFI_ArrowArray ***result_arrays, struct FFI_ArrowSchema **result_schema, size_t *count_out, char **error_message)

Vector search using nearest_to with full result conversion.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • vector – - array of floats representing the query vector

  • dimension – - dimension of the vector

  • limit – - maximum number of results to return

  • column – - vector column name (NULL for default “vector” column)

  • result_arrays – - pointer to receive array of Arrow C ABI arrays

  • result_schema – - pointer to receive single Arrow C ABI schema (shared by all arrays)

  • count_out – - pointer to receive number of result batches

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure Caller must free arrays with lancedb_free_arrow_arrays() and schema with lancedb_free_arrow_schema()

LanceDBError lancedb_record_batch_reader_from_arrow(const struct FFI_ArrowArray *array, const struct FFI_ArrowSchema *schema, LanceDBRecordBatchReader **reader_out, char **error_message)

Create a RecordBatchReader from Arrow C ABI structures.

The schema is imported first. If that import fails, the array still belongs to the caller and must be released. Once the schema imports, the array is handed to Arrow’s importer and the caller must not release it again, even when a later batch conversion fails. The schema itself is only read and remains owned by the caller. The caller is responsible for freeing the returned reader with lancedb_record_batch_reader_free(). If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • array – - pointer to FFI_ArrowArray containing record batch data

  • schema – - pointer to FFI_ArrowSchema containing the schema

  • reader_out – - pointer to receive the created reader

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_record_batch_reader_from_arrow_stream(struct ArrowArrayStream *stream, LanceDBRecordBatchReader **reader_out, char **error_message)

Create a RecordBatchReader from an Arrow C Stream.

The stream must provide the get_schema, get_next and release callbacks. get_last_error is optional and may return NULL; its text must stay valid until the next operation on the stream or release. Those callbacks are checked before the stream is moved. If a required pointer or callback is missing, the stream still belongs to the caller. After a successful move, the binding owns the producer and releases it exactly once, including when the schema cannot be acquired. The caller keeps ownership of the outer struct storage, and the source struct’s release callback is cleared, so it must not be released again.

Returns LANCEDB_INVALID_ARGUMENT for a NULL pointer or a missing required callback, LANCEDB_INVALID_INPUT when get_schema reports an error, and LANCEDB_ARROW when the returned schema cannot be imported.

The imported batches must be representable as Arrow RecordBatches: the root struct cannot have null rows. Nullable child fields, zero-row batches, and a root validity bitmap with no nulls are accepted. A root with actual nulls is reported as an Arrow error when that batch is consumed, before its child columns are written.

The stream, its schema and each returned ArrowArray are independently owned. The producer must keep the schema alive until its schema release callback runs and keep each array alive until that array’s own release callback runs. Arrays may be released after the stream or on a different thread; the schema is likewise independent of the stream.

The schema is acquired synchronously on the calling thread before this function returns. No record batch is pulled at import time; batches are read lazily when the reader is consumed by lancedb_table_create(), lancedb_table_add() or lancedb_table_merge_insert(). Calls on one stream are serialized, but callbacks may run on SDK worker threads, and release may run on a worker or on the thread that frees the reader. A producer must therefore allow its callbacks to be invoked from different threads over time, and keep its private state alive until release.

This binding does not collect all batches before writing. The pinned SDK may still buffer depending on the backend: embedded create/add stream batches, remote create encodes an IPC file before sending it, and remote merge may collect the reader for retries.

On entry, *reader_out and *error_message are cleared. Free the reader with lancedb_record_batch_reader_free(); this also releases a reader that was never consumed. If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • stream – - pointer to an initialized struct ArrowArrayStream

  • reader_out – - pointer to receive the created reader

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_record_batch_reader_from_ipc_file(const uint8_t *data, size_t len, LanceDBRecordBatchReader **reader_out, struct FFI_ArrowSchema **schema_out, char **error_message)

Create a RecordBatchReader and/or an Arrow schema from an Arrow IPC file.

At least one of reader_out and schema_out must not be NULL. The reader holds every batch of the file, so several batches can be added with a single lancedb_table_add() or merged with a single lancedb_table_merge_insert(). The schema alone is enough to create an empty table of the same shape. The bytes are only borrowed: the caller may release them as soon as this function returns. Every batch is decoded before returning, so zero bytes (also a NULL pointer with len 0), an IPC stream, a truncated file or a corrupt batch fail with LANCEDB_INVALID_INPUT and a decoding message before any table is changed. A size that cannot describe the buffer, a file whose announced footer does not fit in it, or a footer whose batches point outside it, are rejected before the decoder allocates from those numbers. On entry, both outputs and the error message are cleared. The caller must free a returned reader with lancedb_record_batch_reader_free() and a returned schema with lancedb_free_arrow_schema(). If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • data – - borrowed bytes of an Arrow IPC file (NULL only when len is 0)

  • len – - number of bytes in data

  • reader_out – - optional pointer to receive a reader over every batch (NULL to skip)

  • schema_out – - optional pointer to receive the Arrow C ABI schema (NULL to skip)

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

void lancedb_record_batch_reader_free(LanceDBRecordBatchReader *reader)

Free RecordBatchReader.

Parameters:

reader – - pointer to LanceDBRecordBatchReader

void lancedb_free_arrow_schema(FFI_ArrowSchema *schema)

Free Arrow schema.

Parameters:

schema – - pointer to Arrow schema

void lancedb_ipc_buffer_free(LanceDBIpcBuffer *buffer)

Free the bytes of an Arrow IPC file and reset the buffer.

The buffer keeps both fields unchanged until this call. It reads them as they are, frees the file bytes and zeroes the struct, so freeing an already freed or empty buffer is a no-op.

Parameters:

buffer – - pointer to LanceDBIpcBuffer, or NULL

void lancedb_free_arrow_arrays(struct FFI_ArrowArray **arrays, size_t count)

Free Arrow arrays returned by vector search functions.

Parameters:
  • arrays – - array of Arrow C ABI array pointers

  • count – - number of arrays

void lancedb_free_arrow_array(FFI_ArrowArray *array)

Free one Arrow C ABI array returned by a blob fetch function.

Parameters:

array – - Arrow C ABI array pointer returned by lancedb_table_fetch_blobs() or lancedb_table_fetch_blob_ranges()