Skip to main content
Version: V1.4.1

Experience vector search with SQL

seekdb can be used from an SDK or over SQL. This topic walks you through trying vector search via SQL.

info

To use seekdb from an SDK instead, see Experience vector search with the SDK.

In this example you will:

  1. Deploy seekdb in client/server mode.
  2. Connect to seekdb.
  3. Create a database.
  4. Create a table and insert data.
  5. Run a vector search.
  6. Clean up.

Deployment options​

seekdb supports several deployment options, from quick prototyping to large-scale production.

  • Embedded mode: Install the Python package with pip. The embedded binding manages a separate local seekdb process for learning or prototyping.

  • Client/server mode: Recommended for testing and production. Easy to set up and run as a standalone service.

info

For a full overview of deployment options, see Deployment overview.

Step 1: Deploy seekdb in client/server mode​

Prerequisites​

  • Your system is RPM-based. Supported distributions include:
    • Anolis OS 8.x (Linux kernel 4.19 or later)
    • Anolis OS 23.x (Linux kernel 6.6 or later)
    • CentOS Linux 7.x and 9.x (Linux kernel 4.19 or later)
    • openEuler 22.03 and 24.03 (Linux kernel 5.10.0 or later)
  • At least 1 CPU core and 2 GB of available memory.
  • MySQL client installed.
  • Your user can run sudo.
  • The jq CLI is installed and systemd is configured as the service manager.

Deploy seekdb​

  1. Install seekdb.

    curl -fsSL https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/seekdb/seekdb_install.sh | sudo bash
  2. Start seekdb.

    sudo systemctl start seekdb
  3. Check status.

    sudo systemctl status seekdb

    When the status shows Service is ready, seekdb is running.

Step 2: Connect to seekdb​

Connect with the MySQL client:

mysql -h127.0.0.1 -uroot -P2881 -p****** -A

Step 3: Create a database​

Create a database named my_test. You can also use the default database test if you prefer.

  1. Create the database.

    CREATE DATABASE my_test;
  2. Use it.

    USE my_test;

Step 4: Create a table and insert data​

  1. Create a table with a vector column and index.

    Use the VECTOR(dim) type for vector columns and create an index on that column. The vector index must include at least type and distance.

    Example: table with vector column embedding of dimension 3 and an HNSW index with L2 distance

    CREATE TABLE t1(
    id INT PRIMARY KEY,
    doc VARCHAR(200),
    embedding VECTOR(3),
    VECTOR INDEX idx1(embedding) WITH (distance=L2, type=hnsw)
    );
  2. Insert data.

    INSERT INTO t1
    VALUES (1, 'apple', '[1.2,0.7,1.1]'),
    (2, 'banana', '[0.6,1.2,0.8]'),
    (3, 'orange', '[1.1,1.1,0.9]'),
    (4, 'carrot', '[5.3,4.8,5.4]'),
    (5, 'spinach', '[4.9,5.3,4.8]'),
    (6, 'tomato', '[5.2,4.9,5.1]');

Vector search takes a query vector. To find the three closest rows to the vector for "fruit" [0.9, 1.0, 0.9]:

SELECT id, doc FROM t1
ORDER BY l2_distance(embedding, '[0.9, 1.0, 0.9]')
APPROXIMATE LIMIT 3;

Example result:

+----+--------+
| id | doc |
+----+--------+
| 3 | orange |
| 2 | banana |
| 1 | apple |
+----+--------+
3 rows in set

Step 6: Clean up​

To remove the example database and table:

  1. Drop the table.

    DROP TABLE t1;
  2. Drop the database.

    DROP DATABASE my_test;

What's next​

Explore more seekdb features and build AI applications: