This directory contains comprehensive C FFI bindings for LanceDB, allowing you to use all LanceDB functionality from C and C++ applications.
├── src/ # Rust FFI implementation │ ├── lib.rs # Main library entry point │ ├── connection.rs # Connection management │ ├── table.rs # Table operations and data manipulation │ ├── query.rs # Complete query API implementation │ ├── index.rs # Index management │ ├── error.rs # Error handling and reporting │ └── types.rs # Type definitions and conversions ├── include/ │ └── lancedb.h # Complete C header file with Arrow C ABI ├── examples/ │ ├── full.cpp # C++ example using Arrow. Covering most of the API │ └── simple.cpp # C++ example using Arrow. Similar to rust/examples/simple.rs ├── tests/ # C++ unit tests using Catch2 ├── Cargo.toml # Rust crate configuration ├── CMakeLists.txt # CMake build configuration └── README.md # This file - Rust toolchain (rustc, cargo)
- CMake (3.15 or later)
- C++ compiler with C++20 support (gcc, clang)
- Apache Arrow C++ library
- pkg-config
-
Build everything using CMake:
mkdir -p build cd build cmake .. make -
Run the example:
./simple ./full
If you prefer to build manually:
-
Build the Rust library:
cargo build --release
-
Compile the C++ simple example with Arrow:
g++ -std=c++20 -Wall -Wextra -O2 \ -I./include \ $(pkg-config --cflags arrow) \ -o examples/simple examples/simple.cpp \ -L./target/release -llancedb \ $(pkg-config --libs arrow) \ -Wl,-rpath,./target/release
-
Run the simple example:
./examples/simple
The C API provides comprehensive LanceDB functionality:
lancedb_connect()- Create connection builderlancedb_connect_builder_execute()- Execute connectionlancedb_connection_free()- Free connection resources
lancedb_connection_table_names()- List all tableslancedb_connection_open_table()- Open existing tablelancedb_connection_drop_table()- Delete tablelancedb_connection_rename_table()- Rename table (Cloud only)lancedb_connection_drop_all_tables()- Delete all tables
lancedb_table_create()- Create new table with Arrow schema (returns table object)lancedb_table_arrow_schema()- Get table schema as Arrow C ABIlancedb_table_version()- Get table versionlancedb_table_count_rows()- Count table rowslancedb_table_add()- Add data from Arrow RecordBatchReaderlancedb_table_merge_insert()- Upsert data (insert new, update existing)lancedb_table_delete()- Delete rows with predicatelancedb_table_nearest_to()- Simple vector search functionlancedb_table_free()- Free table resources
lancedb_query_new()- Create general querylancedb_vector_query_new()- Create vector querylancedb_query_limit()/lancedb_vector_query_limit()- Set result limitlancedb_query_offset()/lancedb_vector_query_offset()- Set result offsetlancedb_query_select()/lancedb_vector_query_select()- Set column projectionlancedb_query_where_filter()/lancedb_vector_query_where_filter()- Add WHERE clauselancedb_vector_query_column()- Set vector columnlancedb_vector_query_distance_type()- Set distance metriclancedb_vector_query_nprobes()- Set search probeslancedb_vector_query_refine_factor()- Set refine factorlancedb_vector_query_ef()- Set HNSW ef parameterlancedb_query_execute()/lancedb_vector_query_execute()- Execute querylancedb_query_result_to_arrow()- Convert results to Arrow C ABIlancedb_query_free()/lancedb_vector_query_free()- Free query resources
lancedb_table_create_vector_index()- Create vector indexlancedb_table_create_scalar_index()- Create scalar indexlancedb_table_create_fts_index()- Create full-text search indexlancedb_table_list_indices()- List all table indiceslancedb_table_drop_index()- Drop specific indexlancedb_table_optimize()- Optimize table (compact/prune/rebuild indices)lancedb_free_index_list()- Free index list
- All functions that return
LanceDBErrornow accept an optionalerror_messageparameter - When provided (non-NULL), detailed error messages are populated for debugging
- Use
lancedb_free_string()to free error message strings lancedb_error_to_message()- Convert error codes to human-readable messages
lancedb_connection_uri()- Get database URIlancedb_free_table_names()- Free table names arraylancedb_record_batch_reader_from_arrow()- Create reader from Arrow C ABIlancedb_free_arrow_arrays()- Free Arrow arrayslancedb_free_arrow_schema()- Free Arrow schemalancedb_free_string()- Free strings returned by LanceDB functions