Skip to main content
Version: V1.4.1

Deploy embedded seekdb with Rust

Start a local seekdb instance from Rust and use the mysql client to run a SQL query that combines full-text and vector search.

Prerequisites​

Use a current stable Rust toolchain with Cargo on one of these platforms.

  • Linux x86_64 or ARM64 with glibc 2.28 or later
  • macOS 15.0 or later on Intel or Apple Silicon
  • Windows x64 with the Rust MSVC toolchain (preview)

This example uses version 1.4.1 of the seekdb crate. If the engine bundle is not cached, the build script downloads and verifies it for the target platform. See the Rust crate documentation.

Create the Rust project​

cargo new --bin --edition 2024 seekdb-hybrid-search
cd seekdb-hybrid-search

Add these entries under [dependencies] in Cargo.toml.

seekdb = "=1.4.1"
mysql = { version = "28", default-features = false, features = ["minimal-rust"] }

Copy the full hybrid search SQL example into hybrid-search.sql next to Cargo.toml.

Replace the contents of src/main.rs with the following program. The binding starts seekdb and returns the Unix socket on Linux and macOS or the loopback TCP address on Windows. The program opens the test database and releases the SQL connection before closing the seekdb handle.

use mysql::{Conn, OptsBuilder, from_row_opt, prelude::Queryable};
use seekdb::Seekdb;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let db_dir = std::env::args_os()
.nth(1)
.ok_or("Usage: cargo run -- <data-directory>")?;
let db = Seekdb::open(db_dir)?;
let endpoint = db.connection_options()?;
let options = OptsBuilder::new()
.ip_or_hostname(Some(endpoint.host.unwrap_or_else(|| "127.0.0.1".into())))
.tcp_port(endpoint.port.unwrap_or(0))
.socket(endpoint.unix_socket)
.user(Some(endpoint.user))
.pass(Some(""))
.db_name(Some("test"));
let mut conn = Conn::new(options)?;
let version: String = conn
.query_first("SELECT VERSION()")?
.ok_or("No engine version")?;
println!("{version}");

{
let mut results = conn.query_iter(include_str!("../hybrid-search.sql"))?;
while let Some(rows) = results.iter() {
for row in rows {
println!("{}", from_row_opt::<String>(row?)?);
}
}
}
drop(conn);
db.close()?;
Ok(())
}

Run the program with an unused data directory.

cargo run -- ./seekdb-rust-data

Expect the program to print the engine version and a JSON result with the IDs ranked 1, 3, and 2.

5.7.25-OceanBase seekdb-v1.4.1.0
[
{
"id": 1,
"body": "SeekDB hybrid search",
"_score": 0.0325
},
{
"id": 3,
"body": "Combine keyword queries with vector retrieval",
"_score": 0.0164
},
{
"id": 2,
"body": "SeekDB installation guide for local application development",
"_score": 0.0161
}
]

The data persists after the program exits. To run the full example again, use a fresh directory, for example cargo run -- ./seekdb-rust-data-2.