Skip to main content
Version: V1.1.0

Experience hybrid search with SQL

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

info

To use seekdb from an SDK instead, see Experience embedded seekdb with the Python 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 hybrid search.
  6. Tune search with boost.
  7. Clean up.

Deployment options

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

  • Embedded mode: seekdb runs as a lightweight library inside your application. Install with pip. Suited for learning, prototyping, and running on resource-constrained devices.

  • 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 scalar columns, a vector column, and full-text indexes so you can try full-text search with filters and hybrid search.

    CREATE TABLE doc_table(
    c1 INT,
    vector VECTOR(3),
    query VARCHAR(255),
    content VARCHAR(255),
    VECTOR INDEX idx1(vector) WITH (distance=l2, type=hnsw, lib=vsag),
    FULLTEXT INDEX idx2(query),
    FULLTEXT INDEX idx3(content)
    )
    ORGANIZATION HEAP;
  2. Insert data.

    INSERT INTO doc_table VALUES
    (1, '[1,2,3]', "hello world", "seekdb Elasticsearch database"),
    (2, '[1,2,1]', "hello world, what is your name", "seekdb database"),
    (3, '[1,1,1]', "hello world, how are you", "seekdb mysql database"),
    (4, '[1,3,1]', "real world, where are you from", "postgres mysql database"),
    (5, '[1,3,2]', "real world, how old are you", "redis mysql database"),
    (6, '[2,1,1]', "hello world, where are you from", "starrocks seekdb database");
  1. Set the search parameters.

    SET @parm = '{
    "query": {
    "query_string": {
    "fields": ["query", "content"],
    "query": "hello oceanbase"
    }
    },
    "knn" : {
    "field": "vector",
    "k": 5,
    "query_vector": [1,2,3]
    }
    }';
  2. Run the query.

    SELECT json_pretty(DBMS_HYBRID_SEARCH.SEARCH('doc_table', @parm));

    Example result:

    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | json_pretty(DBMS_HYBRID_SEARCH.SEARCH('doc_table', @parm)) |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | [
    {
    "c1": 1,
    "query": "hello world",
    "_score": 1.3716216216216217,
    "vector": "[1,2,3]",
    "content": "seekdb Elasticsearch database"
    },
    {
    "c1": 2,
    "query": "hello world, what is your name",
    "_score": 0.6646586312048193,
    "vector": "[1,2,1]",
    "content": "seekdb database"
    },
    {
    "c1": 3,
    "query": "hello world, how are you",
    "_score": 0.6593354613375797,
    "vector": "[1,1,1]",
    "content": "seekdb mysql database"
    },
    {
    "c1": 5,
    "query": "real world, how old are you",
    "_score": 0.41421356,
    "vector": "[1,3,2]",
    "content": "redis mysql database"
    },
    {
    "c1": 6,
    "query": "hello world, where are you from",
    "_score": 0.3503184713375797,
    "vector": "[2,1,1]",
    "content": "starrocks seekdb database"
    },
    {
    "c1": 4,
    "query": "real world, where are you from",
    "_score": 0.30901699,
    "vector": "[1,3,1]",
    "content": "postgres mysql database"
    }
    ] |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set

Step 6: Tune search with boost

You can use the boost parameter to change the balance between full-text and vector search. For example, to favor keyword match over semantic similarity, increase the full-text boost.

  1. Set the search parameters.

    SET @parm = '{
    "query": {
    "query_string": {
    "fields": ["query", "content"],
    "query": "hello oceanbase",
    "boost": 2.0
    }
    },
    "knn" : {
    "field": "vector",
    "k": 5,
    "query_vector": [1,2,3],
    "boost": 1.0
    }
    }';
  2. Run the query.

    SELECT json_pretty(DBMS_HYBRID_SEARCH.SEARCH('doc_table', @parm));

    Example result:

    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | json_pretty(DBMS_HYBRID_SEARCH.SEARCH('doc_table', @parm)) |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | [
    {
    "c1": 1,
    "query": "hello world",
    "_score": 1.7432432432432434,
    "vector": "[1,2,3]",
    "content": "seekdb Elasticsearch database"
    },
    {
    "c1": 3,
    "query": "hello world, how are you",
    "_score": 1.0096539326751595,
    "vector": "[1,1,1]",
    "content": "seekdb mysql database"
    },
    {
    "c1": 2,
    "query": "hello world, what is your name",
    "_score": 0.9959839324096386,
    "vector": "[1,2,1]",
    "content": "seekdb database"
    },
    {
    "c1": 6,
    "query": "hello world, where are you from",
    "_score": 0.7006369426751594,
    "vector": "[2,1,1]",
    "content": "starrocks seekdb database"
    },
    {
    "c1": 5,
    "query": "real world, how old are you",
    "_score": 0.41421356,
    "vector": "[1,3,2]",
    "content": "redis mysql database"
    },
    {
    "c1": 4,
    "query": "real world, where are you from",
    "_score": 0.30901699,
    "vector": "[1,3,1]",
    "content": "postgres mysql database"
    }
    ] |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set

Adjusting boost changes how much keyword match and semantic similarity affect the final order. Increase query_string.boost to favor keywords; increase knn.boost to favor semantic similarity.

Step 7: Clean up

To remove the example database and table:

  1. Drop the table.

    DROP TABLE doc_table;
  2. Drop the database.

    DROP DATABASE my_test;

What's next

Explore more seekdb features and build AI applications: