Knowledge Base · Learning paths
One-Year Compilation: Getting Started with AI Database Hybrid Search
In the AI era, RAG teams often struggle with the lack of precision in vector search and missing synonyms in full-text search. This guide breaks down OceanBase hybrid search: a single SQL query that seamlessly combines vector search, full-text search, scalar filtering, and RRF ranking to simplify architecture, reduce operational costs, and enable efficient hybrid retrieval.
Translated from Chinese by AI. Spotted an issue? Use the feedback button.
🔗 Original article: https://mp.weixin.qq.com/s/cs5kYXcw...
Original content · Zucheng, Haiqian · Zucheng, Haiqian · Lao Ji’s Tech Talks · July 13, 2026, 07:00 · Zhejiang
Prologue
In the AI era, vector search and full-text search are essential components of AI infrastructure.
At several recent in-person events, conversations with AI developers and DBAs revealed a common problem that many AI teams—especially those with RAG experience—run into: vector search retrieves semantically relevant content but often misses precise information, while full-text search matches keywords but can easily miss synonymous expressions.
Many teams therefore use Elasticsearch for full-text search and a dedicated vector database for semantic retrieval, then write application-layer code to merge the retrieved results and rank them using RRF. As more pieces are stitched together, the system grows increasingly complex. Search quality and performance may still fall short of expectations, while operations and troubleshooting costs are the first things to rise.
Over the past year, two database experts I know—Zucheng and Haiqian—have devoted considerable time to putting together a practical introduction to hybrid search combining vector, full-text, and scalar search. This article covers the many considerations involved in using a database’s hybrid search capabilities. We hope it helps you get started quickly and make better use of this essential capability in the AI era!
(Bookmark this article for future reference.)
Follow the OceanBase community’s WeChat official account, “Lao Ji’s Tech Talks.” We’ll continue sharing technical content related to #AI and #Data here!
Hybrid Search
A few notes before we begin:
-
Rather than explaining vector search and full-text search separately, this article shows how to use a database’s hybrid search capabilities to bring semantic retrieval, keyword retrieval, structured filtering, and rank fusion together in a single SQL statement. The goal is to simplify data queries for AI applications and reduce operational complexity. This is a long article, so feel free to jump to the sections most relevant to you.
-
The original text is a carefully prepared, collaboratively contributed chapter by Zucheng and Haiqian in Easy Data x AI [1], a community course jointly published by DataWhale and OceanBase. I have preserved the original tables, SQL, parameters, and limitations wherever possible, adding only a few explanations at key points to make the material easier to read and understand.
-
The prerequisite reading for this article is A Gentle Introduction to Vector Databases. It requires no prior knowledge and offers an accessible introduction to vector databases—an indispensable technology in the AI era.
-
Another useful companion article is Vector Database Best Practices, a collection of hard-earned insights into operating and maintaining vector databases. If you need to run a vector database PoC (Proof of Concept) for an AI use case, this is highly recommended reading.
Note:
All examples in this article reflect the behavior of OceanBase 4.6.0.
OceanBase 4.4.x and later, as well as seekdb, also support hybrid search, but specific behavior may vary slightly by version.
Summary
| Article Summary | |
|---|---|
| Pain Points Addressed | Eliminates poor search results, high operational complexity, and data consistency issues caused by stitching together multiple search methods |
| Core Value | Combines vector search + full-text search + scalar filtering in a single SQL statement for high-quality, efficient data retrieval |
| Use Cases | RAG knowledge bases, multimodal search, and other scenarios requiring hybrid searches across structured and unstructured or semi-structured data |
| Key Limitations | Supports only heap tables and HNSW indexes; available only in MySQL mode |
OceanBase hybrid search combines vector search (semantic), full-text search (keyword), and scalar filtering (structured conditions) in a single SQL statement, automatically merging and ranking results using built-in fusion algorithms such as RRF.
It replaces the cumbersome combination of a “vector database + search engine” with a single-database architecture, delivering better performance while balancing recall and precision.
Contents
-
In a Nutshell — What Is Hybrid Search?
-
Why Hybrid Search? — The Limitations of a Single Search Method
-
Quick Start — Create a Table, Build Indexes, and Run Your First Hybrid Query
-
Search Capabilities Explained — Vector Search, Full-Text Search, Scalar Filtering, and Fusion Algorithms
-
Real-World Scenarios and Best Practices — Applying Hybrid Search to RAG
-
Comparing Hybrid Search Capabilities Across Major Databases — MySQL, PostgreSQL, Elasticsearch, Oracle, TiDB, and More
-
Limitations and Compatibility — Key Limitations, Syntax Restrictions, and Parameter Constraints
-
Conclusion — Core Value and Recommended Next Steps
Hybrid Search = Vector Search + Full-Text Search + Scalar Filtering, all in a single SQL statement, with automatic rank fusion handled by the database engine.
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1, 0.2, 0.3, 0.4]",
"k": 10,
"filter": {
"range": {"id": {"gte": 1, "lte": 10}}
}
},
"query": {
"match": {"title": "database optimization"}
},
"rank": {
"rrf": {"rank_constant": 60}
},
"size": 10
}'
);
This SQL statement performs four tasks at once:
-
Vector Search: Uses
knnto find semantically similar documents -
Full-Text Search: Uses
query.matchto find documents matching the keywords -
Scalar Filtering: Uses
knn.filter.rangeto restrict the id range, filtering only the vector search results -
Rank Fusion: Uses
rank.rrfto automatically merge the two result sets and produce the final ranking
2. Why Hybrid Search Is Needed
2.1 Blind Spots of Single-Method Search
Consider a RAG knowledge base with the following documents stored in its database:
| id | title | content | category |
|---|---|---|---|
| 1 | OceanBase 4.6.0 Feature Updates | This release adds vector search capabilities with support for HNSW indexes... | Release Notes |
| 2 | OceanBase Version Feature Reference | Vector indexes: supported since the 4.3 series; full-text search: supported since 4.3.1... | Quick Reference |
| 3 | Guide to Choosing a Vector Index | A comparison of use cases and performance for vector indexes such as HNSW and IVF... | Best Practices |
| 4 | OceanBase 4.6.0 Upgrade Guide | Upgrade from 4.5.x to 4.6.0, with support for vector search... | Operations Manual |
When a user submits the query “OceanBase vector index”:
| Search Method | Results Retrieved | Results Missed | Reason |
|---|---|---|---|
| Vector search (semantic) | Documents 1, 3, 4 | Document 2 | Semantically, “vector index” ≈ “vector search” ≈ “vector search,” allowing documents 1, 3, and 4 to be retrieved. However, document 2 uses a quick-reference table format with sparse semantic information, making it difficult for vector search to match. |
| Full-text search (keyword) | Documents 2, 3 | Documents 1, 4 | Exact matching for “vector index” retrieves documents 2 and 3. Documents 1 and 4 both use “vector search,” so they are missed due to the keyword mismatch. |
| Hybrid search | Documents 1, 2, 3, 4 | — | Vector search retrieves documents 1, 3, and 4 (semantic relevance), while full-text search retrieves documents 2 and 3 (keyword matches). Combining the results retrieves all four documents. |
Keyword search can miss synonymous expressions, while semantic search can miss exact terms. Hybrid search brings together comprehensive coverage and precise results.
2.2 Limitations of Existing Approaches
Common approaches to implementing hybrid search include the following, each with its own use cases and limitations:
| Approach | Characteristics and Limitations |
|---|---|
| Vector search only | Powerful vector search capabilities, but exact keyword matching and scalar filtering require additional components. |
| Full-text search only | Excellent keyword search, but a lack of semantic understanding limits recall for synonyms and similar expressions. |
| A single database managing both vector and full-text data, with application-layer integration | The database provides vector and full-text search but no built-in result fusion. Application code must invoke each search separately, then manually merge and rank the results. Development costs are high, and fusion quality depends on developer expertise. |
| Separate deployment of a vector database and a relational database | Multiple underlying systems provide vector retrieval, relational storage, and full-text retrieval separately. Combining these systems adds operational complexity, while data synchronization and transactional consistency require extra attention. |
The core problem with these approaches is this: Each search capability looks effective on its own. But when these capabilities are scattered across different systems, unified index building and result fusion at the database engine level become difficult, making integration and operations extremely costly.
2.3 The Value of Hybrid Search
Hybrid Search unifies multimodal search capabilities at the database engine level.
| Benefit | Description |
|---|---|
| Result fusion quality | Built-in algorithms such as RRF and Weighted Sum optimize ranking quality at the engine level. |
| Development efficiency | A single SQL statement replaces application-layer logic for merging multiple result sets, reducing both development effort and the risk of errors introduced by custom integration. |
| Simpler operations | A single database replaces a multi-system setup combining a vector database and a relational database. |
| Data consistency | ACID transactions ensure that search data and business data remain inherently consistent. |
3. Quick Start
3.1 Create a Heap Table
Hybrid Search only supports heap tables(ORGANIZATION HEAP). When creating the table, declare vector columns( VECTOR ), a JSON column, and an Array column to store multimodal data:
CREATE TABLE articles(
id INT,
title VARCHAR(255), -- Text title for full-text search
content TEXT, -- Text content for full-text search
embedding VECTOR(4), -- Vector column; dimensions match the sample data (adjust based on the embedding model in production)
title_embedding VECTOR(4), -- Vector column; dimensions match the sample data (adjust based on the embedding model in production)
tags JSON, -- JSON tags for scalar filtering
categories ARRAY(VARCHAR(100)) -- Category array for scalar filtering
) ORGANIZATION = HEAP;
3.2 Create Indexes
Create the appropriate indexes for the columns you want to search. Vector search requires vector indexes (HNSW_SQ is recommended for a balance between memory usage and performance), while full-text search requires full-text indexes. For filtering JSON/Array columns, creating a Search Index is recommended to improve performance:
-- Vector indexes: for semantic similarity search
CREATE VECTOR INDEX idx_embedding ON articles(embedding)
WITH (distance=l2, type=hnsw_sq, lib=vsag);
CREATE VECTOR INDEX idx_title_embedding ON articles(title_embedding)
WITH (distance=l2, type=hnsw_sq, lib=vsag);
-- Full-text index: for keyword matching
CREATE FULLTEXT INDEX idx_title on articles(title);
-- Search Index: accelerates scalar filtering on JSON/Array columns
ALTER TABLE articles ADD SEARCH INDEX idx_tags(tags);
ALTER TABLE articles ADD SEARCH INDEX idx_categories(categories);
3.3 Insert Sample Data
Prepare a few test records containing articles on different machine learning topics:
INSERT INTO articles VALUES (
1,
'Machine Learning Basics',
'Introduction to machine learning algorithms and concepts',
'[0.1, 0.2, 0.3, 0.4]',
'[0.1, 0.2, 0.3, 0.4]',
'{"level": "beginner", "topic": "ml"}',
ARRAY('AI', 'ML')
);
INSERT INTO articles VALUES (
2,
'Deep Learning Guide',
'Comprehensive guide to neural networks and deep learning',
'[0.15, 0.25, 0.35, 0.45]',
'[0.15, 0.25, 0.35, 0.45]',
'{"level": "advanced", "topic": "dl"}',
ARRAY('AI', 'Deep Learning')
);
INSERT INTO articles VALUES (
3,
'Python Programming',
'Learn Python programming from scratch',
'[0.05, 0.1, 0.15, 0.2]',
'[0.05, 0.1, 0.15, 0.2]',
'{"level": "beginner", "topic": "python"}',
ARRAY('Programming')
);
INSERT INTO articles VALUES (
4,
'Database Systems',
'Introduction to relational database management systems',
'[0.2, 0.1, 0.3, 0.2]',
'[0.2, 0.1, 0.3, 0.2]',
'{"level": "intermediate", "topic": "database"}',
ARRAY('Database', 'SQL')
);
3.4 Running a Hybrid Query
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5
},
"query": {
"match": {"title": "learning"}
},
"rank": {
"rrf": {"rank_constant": 60}
},
"size": 5
}'
);
Here is what each part of this SQL statement does:
| Clause | Purpose |
|---|---|
HYBRID_SEARCH(TABLE articles, ...) |
Specifies the table to search |
"knn": {...} |
Vector search: Finds the 5 most similar records in the embedding column using the vector [0.1,0.2,0.3,0.4] |
"query": {...} |
Full-text search: Matches documents containing "learning" in the title column |
"rank": {...} |
Rank fusion: Merges the two sets of results using the RRF algorithm, with rank_constant=60 controlling ranking weights |
"size": 5 |
Result count: Returns the top 5 results after fusion |
__score |
The final score after fusion; a higher score indicates a better match |
In short: knn handles semantic search, query handles keyword search, and rank handles rank fusion.
4. Query Capabilities in Detail
4.1 Overview of Query Modes
What does your query need?
├─ Semantic similarity ──→ knn clause (vector search)
├─ Keyword matching ──→ query clause (full-text search)
├─ Structured filtering ──→ filter clause (scalar filtering)
└─ Combined requirements ──→ Multiple clauses + rank fusion
| Query Mode | Query Structure | Use Cases |
|---|---|---|
| Single vector search | knn only |
Semantic similarity search |
| Single full-text search | query only |
Keyword/phrase matching |
| Scalar filtering | query.bool.filter |
Filtering by structured conditions |
| Hybrid query | knn + query + rank |
Combining semantics, keywords, and filters |
Basic query syntax:
HYBRID_SEARCH(TABLE table_name, 'DSL_STRING')
Top-level structure of the query's DSL_STRING:
{
"knn": { ... }, // Vector search (optional; can also be an array for multiple vector searches)
"query": { ... }, // Query conditions (optional; supports full-text, scalar, Array, and JSON queries)
"rank": { ... }, // Fusion algorithm (applies when both knn and query are present)
"from": 0, // Pagination offset (default: 0)
"size": 10, // Number of results to return (default: 10)
"min_score": 0.0 // Minimum score threshold (optional)
}
The query clause supports the following query types, each with different placement and relevance scoring rules. Relevance scoring refers to whether a clause contributes to score calculations such as BM25—scoring clauses affect result ranking, while non-scoring clauses only filter results, determining “which documents are included” without affecting their ranking.
| Category | Clause | Allowed Locations | Relevance Scoring | Description |
|---|---|---|---|---|
| Full-text search | match / match_phrase / multi_match / query_string | Top level of query; any clause within bool | Contributes at the top level and in must/should; does not contribute in filter/must_not | Keyword/phrase matching with BM25 relevance scoring |
| Compound query | bool | Top level of query; any clause within bool | Determined by child clauses | must/should support only full-text clauses and contribute to scoring; filter/must_not support all types but do not contribute to scoring |
| Scalar filtering | term / terms / range | Top level of query; bool.filter/must_not; knn.filter | No | Exact matching and range filtering |
| Array filtering | array_contains / array_contains_all / array_overlaps | Top level of query; bool.filter/must_not; knn.filter | No | Filtering on array columns |
| JSON filtering | json_contains / json_member_of / json_overlaps | Top level of query; bool.filter/must_not; knn.filter | No | Filtering on JSON columns |
| JSON path extraction | field_name.path (e.g., doc_json.name) | Used with term/terms/range | No | Extracting scalar values from JSON |
Combination Rules:
-
Full-text search clauses can be used anywhere within query; full-text clauses in bool.filter only filter results and do not contribute to scoring
-
Scalar, Array, and JSON filters cannot be placed in bool.must/bool.should (doing so will cause an error). They are allowed in the other locations: the top level of query, bool.filter, bool.must_not, and knn.filter
-
Scoring exemption for nested bool clauses: If a bool clause is inside an outer filter or must_not clause, its internal must/should clauses do not contribute to scoring either. In this case, scalar/Array/JSON clauses can appear in the nested must/should clauses.
-
knn.filter and query.bool.filter are not shared: If full-text and vector searches require the same filtering conditions, you must specify them separately.
4.2 Vector Search
Strengths: Understands semantic similarity and retrieves results related to synonyms and similar terms without requiring exact keyword matches.
Limitations: May miss exact terms and is less precise than keyword search when matching proper nouns; requires precomputed vector embeddings.
Complete knn structure:
{
"knn": {
"field": "embedding", // Required: vector column name
"query_vector": "[0.1,0.2,...]", // Required: query vector; string format recommended
"k": 10, // Required: number of results to return [1, 16384]
"boost": 1.0, // Optional: fusion weight; default 1.0; range >= 0
"similarity": 0.8, // Optional: similarity threshold [0.0, 1.0]; IP distance not supported
"filter": { ... }, // Optional: filtering conditions; same syntax as query.bool; does not contribute to scoring
"search_options": { // Optional: vector query tuning parameters
"ef_search": 64, // HNSW search breadth [1, 1000]; default 1000
"refine_k": 4.0, // Refinement search multiplier [1.0, 1000.0]; supported only by HNSW_BQ indexes
"filter_mode": "pre", // Filtering mode: pre / pre-knn / pre-brute / post / post-index-merge
"drop_ratio_search": 0.0, // Drop ratio for sparse vector search [0.0, 0.9]
}
}
}
| Clause | Purpose |
|---|---|
field + query_vector + k |
Basic vector search: find the k most similar results in the embedding column using the query vector |
boost |
Fusion weight for WRRF/Weighted Sum scenarios |
similarity |
Similarity threshold; returns only results with similarity >= 0.5 (IP distance not supported) |
filter |
Scalar filtering; uses the same syntax as query.bool and does not contribute to scoring |
search_options |
Vector query tuning parameters |
knn Parameters
| Parameter | Required | Default | Range | Description |
|---|---|---|---|---|
field |
Yes | - | - | Vector column name |
query_vector |
Yes | - | - | Query vector; string format "[0.1,0.2,...]" recommended |
k |
Yes | - | [1, 16384] | Number of results to return |
boost |
No | 1.0 | >= 0 or > 0; see the specific rules for details | Fusion weight (WRRF/Weighted Sum scenarios) |
similarity |
No | - | [0.0, 1.0] | Similarity threshold; returns only results with similarity >= this value; IP distance not supported |
filter |
No | - | - | Filtering conditions; uses the same syntax as query.bool and does not contribute to scoring |
search_options |
No | - | - | Vector query tuning parameters; see below for details |
search_options Parameters
| Parameter | Default | Range | Applicable Index Types | Description |
|---|---|---|---|---|
ef_search |
1000 | [1, 1000] | All HNSW indexes | HNSW search width; higher values improve recall but slow down searches |
refine_k |
1.0 | [1.0, 1000.0] | HNSW_BQ only | Refinement multiplier used for reranking in quantized vector indexes |
filter_mode |
Adaptive | See below | All indexes | Filtering mode |
drop_ratio_search |
0.0 | [0.0, 0.9] | Sparse vector indexes | Drop ratio for sparse vector searches |
filter_mode Options :
| Value | Meaning | Use Case |
|---|---|---|
"pre" |
Adaptive filtering before vector search | Default strategy; automatically selects a method based on selectivity |
"pre-knn" |
Filtering before vector search + KNN | When filter conditions are highly selective |
"pre-brute" |
Filtering before vector search + brute-force scan | For small datasets (< 20,000 rows) |
"post" |
Vector search before filtering | When filter conditions have low selectivity |
"post-index-merge" |
Vector search before filtering + index merge | When auxiliary indexes are available |
Multi-Vector Search
knn supports an array format for multi-vector search. Each vector search runs independently, and the results are merged using a fusion algorithm:
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": [
{
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 0.7
},
{
"field": "title_embedding",
"query_vector": "[0.4,0.3,0.2,0.1]",
"k": 5,
"boost": 0.3
}
],
"size": 5
}'
);
Key points for multi-vector search:
-
The
fieldin eachknnsearch can reference a different vector column -
Parameters such as
boost,filter, andsearch_optionscan be configured independently for each search -
Filters are not shared across searches; each
filtermust be specified separately -
Results from all vector searches are combined into a union and ranked using a score fusion algorithm
4.3 Full-Text Search
Advantages : Matches keywords precisely, providing high recall for exact terms such as proper nouns, model numbers, and IDs; supports BM25 relevance scoring.
Disadvantages : Cannot understand semantics; synonyms and related terms require additional configuration. May return results that match keywords but are semantically irrelevant.
Full-text search structure for query:
{
"query": {
// Full-text search (contributes to scoring)
"match": { ... }, // Single-field matching
"match_phrase": { ... }, // Phrase matching
"multi_match": { ... }, // Multi-field matching
"query_string": { ... }, // Query string
// Compound queries
"bool": { ... } // Boolean combination; can nest full-text queries and scalar filters
}
}
See Section 4.4 for scalar filters (term/terms/range), array filters, and JSON filters.
match Query
Single-field full-text matching supports both shorthand and full formats:
-- Shorthand format
{"match": {"title": "machine learning"}}
-- Full format:
{"match": {"title": {"query": "machine learning", "boost": 2.0, "operator": "and", "minimum_should_match": 2}}}
| Parameter | Required | Default | Description |
|---|---|---|---|
| query | Yes | - | Query text |
| boost | No | 1.0 | Weight. The boost for a top-level object within query must be > 0; in all other cases, it must be >= 0 |
| operator | No | "or" | Matching logic after tokenization; "and" requires all terms to match |
| minimum_should_match | No | 1 | Minimum number of terms that must match after tokenization; accepts only non-negative integers |
match_phrase Query
Phrase matching, with terms required to appear in the same order:
{"match_phrase": {"title": {"query": "machine learning", "slop": 2, "boost": 1.5}}}
| Parameter | Required | Default | Description |
|---|---|---|---|
| query | Yes | - | Query phrase |
| slop | No | 0 | Allowed distance between terms; 0 means terms must be adjacent and in the same order |
| boost | No | 1.0 | Weight. The boost for a top-level object within query must be > 0; in all other cases, it must be >= 0 |
multi_match Query
Full-text matching across multiple fields, with support for field weighting using the syntax "field_name^weight":
{
"multi_match": {
"query": "machine learning",
"fields": ["title^2.0", "content"],
"type": "best_fields",
"operator": "or",
"minimum_should_match": 1,
"boost": 1.5
}
}
| Parameter | Required | Default | Description |
|---|---|---|---|
| fields | Yes | - | List of fields; supports weighting syntax such as "title^2.0". If no weight is specified, it defaults to 1.0 |
| query | Yes | - | Query text |
| type | No | "best_fields" | Matching strategy: best_fields / most_fields |
| operator | No | "or" | Matching logic after tokenization |
| minimum_should_match | No | 1 | Minimum number of terms that must match after tokenization |
| boost | No | 1.0 | Weight. The boost for a top-level object within query must be > 0; in all other cases, it must be >= 0 |
query_string Query
Supports term weighting using the syntax "term^weight", with multiple terms separated by spaces (OR logic by default):
{
"query_string": {
"query": "database^2.0 optimization",
"fields": ["title^1.5", "content"],
"type": "best_fields",
"default_operator": "and",
"minimum_should_match": 1,
"boost": 1.0
}
}
| Parameter | Required | Default | Description |
|---|---|---|---|
| query | Yes | - | Query text; supports term weighting syntax such as "word^0.3" |
| fields | Yes | - | List of fields; supports weighting syntax such as "title^2.0" |
| type | No | "best_fields" | Matching strategy: best_fields / most_fields |
| default_operator | No | "or" | Default matching logic after tokenization (note: this parameter name differs from the operator parameter in match/multi_match) |
| minimum_should_match | No | 1 | Minimum number of terms that must match after tokenization |
| boost | No | 1.0 | Weight. The boost for a top-level object within query must be > 0; in all other cases, it must be >= 0 |
Note: The following content will trigger an error if it appears in the query text of
query_string.query:
-
Reserved keywords (case-insensitive):
and,or,not,to -
Reserved characters:
+ - & | ! = < > ( ) [ ] { } " ~ * ? : \ /
For example,
"query": "database and optimization"triggersERROR 1210: query contains reserved keywordbecause ofand;"query": "hello (world)"triggersERROR 1210: query contains reserved characterbecause of(. To use these words or characters, use thematchfamily of queries or aboolcompound query instead.
bool Compound Queries
{
"bool": {
"must": [
{"match": {"title": "learning"}}
],
"should": [
{"match": {"content": "algorithm"}}
],
"must_not": [
{"match": {"title": "deep"}}
],
"filter": [
{"range": {"id": {"gte": 1, "lte": 5}}}
],
"minimum_should_match": 1,
"boost": 1.2
}
}
| Clause | Scoring | Required | Description |
|---|---|---|---|
| must | Yes | No (at least one positive condition is required) | Must match; contributes to the score |
| should | Yes | No | Optional match; contributes to the score |
| must_not | No | No | Excludes matches; does not contribute to the score. Requires at least one positive condition |
| filter | No | No (at least one positive condition is required) | Must match; does not contribute to the score |
| minimum_should_match | - | No | Minimum number of should clauses that must match; defaults to 1 when should is present and neither must nor filter is present, otherwise defaults to 0 |
| boost | - | No | Weight value; must be > 0; defaults to 1.0 |
4.4 Scalar Filtering
Advantages: Precisely filters structured conditions (price ranges, time intervals, tags, etc.) with high filtering performance. Array/JSON columns can use a Search Index for acceleration, while scalar columns use standard indexes (such as B-tree indexes).
Limitations: Performs only Boolean checks and does not contribute to relevance scoring. Cannot perform semantic or keyword searches on its own and must be used with other search methods.
Scalar filter conditions do not contribute to scoring and do not support boost. They can be placed at the top level of query, in bool.filter / bool.must_not, or in knn.filter, but not in bool.must / bool.should.
range Queries
{"range": {"id": {"gte": 3, "lte": 100}}}
| Operator | Description |
|---|---|
| gt | Greater than |
| gte | Greater than or equal to |
| lt | Less than |
| lte | Less than or equal to |
Supports numeric and date types.
term / terms Exact Matching
-- Single-value match
{"term": {"id": 1}}
-- Multiple-value match
{"terms": {"id": [1, 3, 5]}}
| Operator | Description | Value Format |
|---|---|---|
| term | Exactly matches a single value | Single value |
| terms | Matches any of multiple values | Array |
Array Filtering
Array column filters are placed at the top level of query and support three operators:
-- Contains the specified element
{"array_contains": {"categories": "ai"}}
-- Overlaps with the specified array
{"array_overlaps": {"categories": ["ai", "cloud"]}}
-- Contains all elements of the specified array
{"array_contains_all": {"categories": ["ai", "ml"]}}
| Operator | Description | Value Format |
|---|---|---|
| array_contains | The array contains the specified element | Single value |
| array_overlaps | The array overlaps with the specified array | Array |
| array_contains_all | The array contains all elements of the specified array | Array |
Note: We recommend creating a Search Index on the corresponding column to accelerate array filtering queries. Array filters cannot be placed inside
bool.must/bool.should.
JSON Filtering
JSON column filters are placed at the top level of query. Three operators are supported, all using candidate to specify the candidate value and an optional path to specify the JSON path:
-- json_contains: Checks whether doc_json contains {"name": "doc2"}
{"json_contains": {"doc_json": {"candidate": {"name": "doc2"}, "path": "$"}}}
-- json_member_of: Checks whether the doc_json.name value belongs to the candidate array
{"json_member_of": {"doc_json": {"candidate": "doc2", "path": "$.name"}}}
-- json_overlaps: Checks whether the $.tags path in doc_json overlaps with the candidate array
{"json_overlaps": {"doc_json": {"candidate": ["database", "mysql"], "path": "$.tags"}}}
| Operator | Description | candidate Format |
|---|---|---|
| json_contains | Whether the JSON document contains the candidate value | JSON object or its string representation |
| json_member_of | Whether the JSON value belongs to the candidate array | JSON value or its string representation |
| json_overlaps | Whether the JSON document overlaps with the candidate value | JSON array or its string representation |
| Parameter | Required | Default | Description |
|---|---|---|---|
| candidate | Yes | - | Candidate value, which can be a JSON object or its string representation (ensure proper escaping) |
| path | No | "$" |
JSON path, such as $.tags; defaults to the root path |
Note: We recommend creating a Search Index on the JSON column to accelerate filtering. JSON filters cannot be placed inside
bool.must/bool.should.
JSON Path Extraction
In scalar filters such as term, terms, and range, you can use the field_name.path syntax to extract nested values from JSON fields:
-- term: Exact match on a JSON path value
{"term": {"doc_json.name": "doc2"}}
-- range: Range filtering on a JSON path value
{"range": {"doc_json.metadata.score": {"gte": 50}}}
-- terms: Match a JSON path value against multiple values
{"terms": {"doc_json.name": ["doc1", "doc2", "doc3"]}}
Note:
doc_json.nameis equivalent tojson_extract(doc_json, '$.name').
4.5 Hybrid Queries and Fusion Algorithms
Advantages: Combines semantic understanding with exact keyword matching, improving both recall and precision. Multiple built-in fusion algorithms eliminate the need to merge results at the application layer.
Disadvantages: Requires maintaining both vector and full-text indexes, increasing storage costs. Fusion algorithm parameters require tuning.
4.5.1 Which Searches Can Be Combined
The knn and query clauses in Hybrid Search can coexist; a query can execute as long as at least one is present. When both are specified, rank controls how their results are fused. When only one is specified, results are returned based on that clause's own scores.
knn supports multiple vector search paths in array form, while query provides a single search path (with multiple conditions combined through bool.must / bool.should). Scalar filters ( term / terms / range / array_* / json_* ) do not contribute to scoring; they only filter results.
| Search Type | Number of Paths | Contributes to Scoring | Description |
|---|---|---|---|
Vector search ( knn ) |
1–N paths | Yes | A single-path object or a multi-path array; each path produces scores independently |
Full-text search ( query ) |
1 path | Yes | match / match_phrase / multi_match / query_string produce BM25 scores |
Scalar filtering ( filter / term / terms / range / array_* / json_* ) |
Unlimited | No | Can be placed in knn.filter or query.bool.filter / query.bool.must_not |
Common Combination Patterns:
| Pattern | knn | query | filter | Description |
|---|---|---|---|---|
| Single-path vector only | Object | - | - | Vector-based semantic search only |
| Multi-path vector only | Array | - | - | Search multiple vector columns independently, then fuse the results |
| Full-text only | - | match, etc. | - | Keyword matching only |
| Scalar only | - | - | bool.filter/array_ /json_ | Structured filtering only; no scores produced |
| Vector + full-text | Object/array | match, etc. | - | Fusion of semantic and keyword search paths |
| Vector + scalar | Object/array | - | knn.filter or bool.filter | Vector search + structured filtering |
| Full-text + scalar | - | match, etc. | bool.filter | Keyword search + structured filtering |
| Vector + full-text + scalar | Object/array | match, etc. | filter (within knn or bool) | Combines all three to handle the most complex search requirements |
What Is a “Search Path”?
Each element in the
knnarray is an independent vector search path—for example, searching text vectors and image vectors simultaneously counts as 2 paths. Multiple conditions inquery(such as multiplematchclauses withinbool.must) still count as 1 full-text search path: they are combined through bool within a single path, rather than fused as independent paths. Scalar filters (filter) do not produce scores and do not participate in fusion ranking.
Note:
Scalar-only filtering (without knn or full-text match) is supported, but results are returned in the table’s natural order, without relevance ranking. If ranking is required, specify at least one vector or full-text search path.
4.5.2 Vector + Full-Text Fusion
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 1.0
},
"query": {
"match": {
"title": {
"query": "learning",
"boost": 1.0
}
}
},
"size": 5
}'
);
When both knn and query are specified, Weighted Sum fusion is used by default—the scores from the two paths are added directly, with each path’s weight defaulting to 1.0.
4.5.3 Multi-Path Vector + Full-Text Fusion
When multiple vector columns are available (such as text vectors and image vectors), you can run multiple vector search paths simultaneously:
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": [
{
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 10,
"boost": 0.7
},
{
"field": "title_embedding",
"query_vector": "[0.3,0.4,0.2,0.1]",
"k": 10,
"boost": 0.3
}
],
"query": {
"match": {"title": "mobile phone"}
},
"rank": {"rrf": {"rank_constant": 60}},
"size": 10
}'
);
Notes:
-
Each vector search can have a different
boostweight (in the example above, the text weight is 0.7 and the image weight is 0.3) -
Each search has its own independent
filter; specify them separately as needed -
Results from multiple vector searches are first combined into a union, then fused with the full-text results
4.5.4 Fusion Algorithms Explained
The core question in hybrid search is: Vector search and full-text search produce results using different logic. How can we combine them to best reflect the original intent of the query?
-
Vector search returns semantic distance or similarity values (such as L2 distance from 0 to ∞, or cosine similarity from -1 to 1)
-
Full-text search returns BM25 scores (typically from 0 to 30)
Adding these two types of scores directly is like adding Celsius and Fahrenheit temperatures—the arithmetic works, but the result does not meaningfully represent the temperature. Fusion algorithms address this “different units” problem by combining the two types of results to better match the query.
Which scenario matches yours?
├─ Both searches deliver results of similar quality ──→ Weighted Sum (default; add directly)
├─ Unsure which search delivers better results ──→ RRF (uses ranks, not scores)
├─ Want to prioritize results from one search ──→ WRRF (rank fusion + weighting)
└─ Results from one search always dominate the top ranks ──→ Weighted Sum + MinMax (normalize before adding)
| Algorithm | Query Syntax | Core Idea | Use Case |
|---|---|---|---|
| Weighted Sum | Default / "rank":{"weighted_sum":{"normalizer":"none"}} |
Direct weighted sum—add the weighted scores from both searches directly | Both searches deliver results of similar quality |
| Weighted Sum + MinMax | "rank":{"weighted_sum":{"normalizer":"minmax"}} |
Normalize before adding—scale both sets of scores to 0–1, then add them | Results from one search always dominate the top ranks |
| RRF | "rank":{"rrf":{"rank_constant":60}} |
Use ranks, not scores—calculate scores based on ranking positions | The safest choice when you are unsure which search performs better |
| WRRF | RRF + per-search boost | Rank fusion + differentiated weights—build on RRF to emphasize one search | You want to prioritize results from one search |
Recommendation: When in doubt, start with RRF. It is unaffected by score ranges and works without parameter tuning.
Where to Set Fusion Weights (boost):
| Location | Syntax | Value Range | Description |
|---|---|---|---|
knn level |
"knn": {"boost": 1.0} |
>= 0 | Controls the weight of the vector search |
knn array element |
"knn": [{"boost": 0.7}, ...] |
>= 0 | Sets an independent weight for each vector search when using multiple vector searches |
| Within the first-level object of a full-text clause | "match": {"title": {"boost": 1.0}} |
>= 0 | Within clauses such as match/multi_match |
| Not within the first-level object of a full-text clause | "match": {"title": {"boost": 1.0}} |
> 0 | Within clauses such as match/multi_match |
bool level |
"bool": {"boost": 1.0} |
> 0 | Controls the weight of the entire bool query |
Note: The top-level
querydoes not support theboostparameter;knn.boostand the full-text clause'sboosthave a multiplicative relationship.
RRF Fusion
Design rationale: The core idea behind RRF (Reciprocal Rank Fusion) is to ignore scores and focus only on rankings. Whether a vector search score is 0.95 or a full-text search score is 28.5, RRF only cares about "where this document ranks." Higher-ranked results contribute more to the score; as rankings drop, the decay becomes more gradual. This eliminates the problem of "incompatible scoring scales" at its source.
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 1.0
},
"query": {
"match": {
"title": {
"query": "learning",
"boost": 1.0
}
}
},
"rank": {
"rrf": {
"rank_constant": 60,
"rank_window_size": 100
}
},
"size": 5
}'
);
RRF formula: score = Σ(weight_i × 1 / (rank_constant + rank_i))
-
rank_constant: Defaults to 60; must be >= 1. It controls how much of an advantage higher-ranked results receive—a smaller value creates a larger gap between Top 1 and Top 10, while a larger value smooths out the differences between ranks. -
rank_window_size: The ranking window size. Defaults tofrom + sizeand must be >=size. It controls the size of the candidate set used for fusion—increasing it expands the candidate set and can improve recall, but adds computational overhead. -
Results from each search are sorted by their original scores in descending order and then assigned ranks.
How should you choose rank_constant?
-
The default of 60 works well for most scenarios and does not need adjustment.
-
If you want higher-ranked results to have a more pronounced advantage (a more "elitist" approach), lower it to 10–30.
-
If you want smoother differences between ranks (a more "democratic" approach), increase it to 100+.
WRRF Fusion (Weighted RRF)
Design rationale: RRF treats both searches equally by default, but in practice you often trust one more than the other. For example, semantic understanding is typically more important than keyword matching in RAG scenarios, while exact matches on product names are often more important than semantic similarity in descriptions for e-commerce search. WRRF builds on RRF by assigning a boost weight to each search, letting you express "which search matters more to me."
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 2.0
},
"query": {
"match": {
"title": {
"query": "learning",
"boost": 1.0
}
}
},
"rank": {
"rrf": {
"rank_constant": 60,
"rank_window_size": 100
}
},
"size": 5
}'
);
In the example above, vector search has boost=2.0 and full-text search has boost=1.0, meaning that highly ranked vector search results contribute twice as much to the final score as full-text search results.
Note:
boostcan be set at theknnlevel or within a full-text clause (such asmatch/multi_match).knn.boostcontrols the weight of vector search, whileboostwithin a full-text clause controls that clause's weight (the two have a multiplicative relationship). The top-levelquerydoes not support theboostparameter.
How should you choose boost?
-
1.0 = Equal treatment (default)
-
1.5~2.0 = Moderate emphasis, suitable when one retrieval path matters more but the other still contributes
-
3.0+ = Strong emphasis on one retrieval path, suitable when you rely almost entirely on one path and use the other as a supplement
Weighted Sum + MinMax Normalization
When Is Normalization Needed?
-
If results from one retrieval path consistently rank higher—not because they are more relevant, but because their scores are inherently higher—normalization is needed
-
If you are unsure whether normalization is needed, RRF is a safer choice—RRF is inherently unaffected by score ranges
Design Rationale : Weighted Sum is the most intuitive fusion method: it adds the scores from the two retrieval paths. But adding them directly poses a problem: if vector search scores range from 0~1 while full-text search scores range from 0~30, full-text scores will naturally overwhelm vector scores. Even if vector search considers a document highly relevant, its score cannot compete with a moderate full-text score. MinMax normalization first scales both sets of scores to the same 0~1 range, preventing either retrieval path from completely dominating the query results.
SELECT id, title, __score
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 0.7
},
"query": {
"match": {
"title": {
"query": "learning",
"boost": 0.3
}
}
},
"rank": {
"weighted_sum": {
"normalizer": "minmax",
"rank_window_size": 100
}
},
"size": 5
}'
);
Normalization formula: normalized_score = (score - min) / (max - min)
When the difference between max and min is extremely small (< 1e-6), the normalized score defaults to 1.0.
4.5.5 Pagination and Filtering
Score Filtering with min_score
Return only results with a fused score >= min_score, filtering out low-scoring documents with low relevance:
SELECT id, title
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 0.7
},
"query": {
"match": {
"title": {
"query": "learning",
"boost": 0.3
}
}
},
"min_score": 0.5,
"size": 5
}'
);
Pagination with from / size
SELECT id, title
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5
},
"from": 2,
"size": 3,
"min_score": 0.1
}'
);
-
from: Offset; defaults to 0 -
size: Number of results to return; defaults to 10 -
Limit :
from + size <= 10000
Vector Search + Full-Text Search + Scalar Filtering (Complete Example)
SELECT id, title
FROM HYBRID_SEARCH(
TABLE articles,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.1,0.2,0.3,0.4]",
"k": 5,
"boost": 1.5
},
"query": {
"bool": {
"must": [
{"match": {"title": "learning"}}
],
"filter": [
{"range": {"id": {"gte": 1, "lte": 8}}}
],
"boost": 1.0
}
},
"rank": {
"rrf": {"rank_constant": 60}
},
"size": 5
}'
);
5. Real-World Scenarios and Best Practices
The first four chapters explained the capabilities, limitations, and syntax of hybrid search. This chapter takes a different angle: How much harder would these scenarios be to implement without hybrid search?
Below, we use a typical RAG knowledge base scenario to demonstrate the simplicity and efficiency of hybrid search.
5.1 RAG / AI Conversational Systems
5.1.1 Scenario Requirements
A user asks the AI a natural-language question, such as “How does OceanBase ensure consistency in distributed transactions?” The system needs to retrieve the most relevant document chunks from the knowledge base and feed them to a large language model (LLM) to generate an answer.
The core requirements for this scenario are:
-
Semantic coverage: User questions rarely match document titles exactly, so semantic understanding is essential for finding documents with similar meanings.
-
Keyword fallback: A semantic model may miss technical terms such as “two-phase commit” or “global snapshot,” making exact keyword matching necessary.
-
Recall first: It is better to retrieve a few extra documents and let the LLM select the relevant ones than to miss critical information.
5.1.2 The Traditional Approach
Without hybrid search, a typical solution uses an LLM to expand, rewrite, and transform queries, then queries both vector and full-text indexes and merges the results at the application layer:
-
Step 1: Use an LLM to expand the user’s question -> three to five derived questions to improve the query hit rate.
-
Step 2: Vectorize each derived question and query the vector index for semantically similar documents -> Top 20 × number of derived questions.
-
Step 3: Extract keywords from the questions and query the full-text index for matching documents -> Top 20 × number of derived questions.
-
Step 4: Merge and deduplicate results at the application layer (the two retrieval paths may return overlapping documents), manually implement RRF ranking, and return the Top 5.
The problems with this approach:
-
Querying two systems independently makes application code more complex.
-
Fusing results after they are returned by the compute layer is inefficient. With multiple retrieval paths, the database engine can optimize storage-level queries to accelerate retrieval and reduce hardware overhead.
5.1.3 Using Hybrid Search
A single SQL statement replaces Steps 2 through 4 above. Create a table with a vector column and columns indexed for full-text search. At query time, retrieve candidates through both the vector and full-text paths, then let RRF fuse the results automatically:
You can read this SQL in three parts: first, create a heap table to store documents and vectors; next, create the vector and full-text indexes; finally, use HYBRID_SEARCH to query both retrieval paths simultaneously. The real complexity lies in the third part—the hybrid query. When reading it, focus on knn, query, and rank.
-- 1. Create the table (this example uses 4-dimensional vectors; adjust to your embedding model in practice)
CREATE TABLE rag_docs(
id INT,
title VARCHAR(255),
content TEXT,
embedding VECTOR(4),
category VARCHAR(50),
created_at DATE
) ORGANIZATION = HEAP;
-- 2. Create indexes
CREATE VECTOR INDEX idx_emb ON rag_docs(embedding)
WITH (distance=cosine, type=hnsw_sq, lib=vsag);
CREATE FULLTEXT INDEX idx_title on rag_docs(title);
-- 3. Hybrid query
SELECT id, title, content, __score
FROM HYBRID_SEARCH(
TABLE rag_docs,
'{
"knn": {
"field": "embedding",
"query_vector": "[0.12,0.34,0.56,0.78]",
"k": 20,
"boost": 1.5
},
"query": {
"multi_match": {
"query": "distributed transaction consistency",
"fields": ["title", "content"]
}
},
"rank": {
"rrf": {"rank_constant": 60}
},
"size": 5
}'
);
The -- 3. Hybrid query section above is the key: knn retrieves a larger pool of candidates based on vector similarity, multi_match provides a keyword fallback using titles and document bodies, and rank.rrf fuses the results from both paths based on their rankings. Here, size: 5 does not limit each path to five results; it specifies that the final output is the Top 5 after fusion. The vector path’s k: 20 retrieves extra candidates up front so that critical information is not cut off before it even reaches the fusion stage.
How hybrid search query clauses map to the traditional workflow:
| Query Syntax | Corresponding Traditional Step |
|---|---|
knn |
Step 2: Vector search |
query |
Step 3: Full-text search |
rank.rrf |
Step 4: Manual RRF ranking |
Parameter Selection Guidelines:
-
distance=cosine: Cosine distance is recommended for semantic text search because it is insensitive to vector magnitude. -
k=20: Retrieve a larger initial set of results, then use RRF fusion to select the top 5 matches. -
boost=1.5: Give semantic search slightly more weight, since semantic understanding matters more than keywords in RAG scenarios. -
rrf: A robust choice when the score distributions of the two retrieval paths are unknown, as it is insensitive to outlier scores.
| Tuning Goal | Action | Expected Effect |
|---|---|---|
| Improve low recall | Increase knn.k and the number of results retrieved by query |
Feed more candidates into fusion, reducing missed relevant results |
| Strengthen keyword matching | Increase boost for the query path |
Rank exact keyword matches higher |
| Reduce interference from semantic search | Set min_score to filter out low-scoring results |
Reduce noise from irrelevant semantic results |
| Make reranking more aggressive | Decrease rank_constant (e.g., to 30) |
Amplify the influence of rank position, making highly ranked items stand out more |
| Make reranking more conservative | Increase rank_constant (e.g., to 100) |
Reduce the influence of rank position, balancing contributions from the retrieval paths |
Practical Tips:
-
Vector dimensions must match the embedding model’s output (for example, OpenAI text-embedding-3-small outputs 1536 dimensions).
-
The full-text index must use the utf8mb4 character set; otherwise, Chinese tokenization may behave unexpectedly.
-
Avoid setting
ktoo high. Typically, k = 3–5 × size is sufficient; larger k values require more computation.
6. Comparison of Leading Database Products
6.1 Core Capabilities Compared
Hybrid Search Interfaces Compared
| Hybrid Search Interface | OceanBase | MySQL | PostgreSQL | Elasticsearch | Oracle 26ai | TiDB |
|---|---|---|---|---|---|---|
| SQL interface | ✅ | ❌ | ❌ Requires application-layer composition | ✅ | ✅ | ❌ |
| Python/SDK hybrid search | 🔄 Integration in progress | ❌ | ❌ Requires application-layer fusion | ✅ elasticsearch-py | ✅ | ✅ pytidb SDK |
Fusion Algorithms Compared
| Fusion Algorithms | OceanBase | MySQL | PostgreSQL | Elasticsearch | Oracle 26ai | TiDB |
|---|---|---|---|---|---|---|
| Supported algorithms | RRF / Weighted Sum / WRRF | - | - | RRF / scripted | RRF / RSF | RRF / Weighted |
| Weight control | boost parameter | - | - | boost parameter | score_weight | vs_weight / fts_weight |
| Multi-path support | N vector search paths + 1 full-text search path + scalar filtering | - | - | Multiple paths | 1 vector search path + 1 full-text search path | 1 vector search path + 1 full-text search path |
Transactions and Architecture Compared
| Transactions and Architecture | OceanBase | MySQL | PostgreSQL | Elasticsearch | Oracle 26ai | TiDB |
|---|---|---|---|---|---|---|
| Transaction support | ACID | ACID | ACID | Not supported | ACID | ACID |
6.2 OceanBase Advantages
-
Multimodal search with a single SQL statement: Combine vector search, full-text search, and scalar filtering in one SQL statement, without integrating multiple systems
-
Multiple built-in fusion algorithms: Weighted Sum / RRF / WRRF cover mainstream fusion needs
-
MySQL protocol compatibility: Reduce migration costs and use existing MySQL ecosystem tools directly
-
Distributed architecture: Supports horizontal scaling for large-scale data workloads
-
Transactional consistency: Hybrid search and business data reside in the same database, with native ACID transaction support
-
Multilingual support: Full-text indexes support multiple languages
-
High compression ratio: High compression for document storage makes it well suited to massive datasets
7. Limitations and Compatibility
7.1 Key Limitations
The following limitations determine whether Hybrid Search is suitable for your use case. Review them before deployment:
| Limitation | Impact | Recommended Approach |
|---|---|---|
| Only row-store tables (heap tables, ORGANIZATION HEAP) are supported | Hybrid Search cannot be used with column-store tables | Use heap tables to store data that requires hybrid search |
| Only HNSW-family indexes (HNSW / HNSW_SQ / HNSW_BQ) are supported | IVF-family indexes (IVF_FLAT/IVF_SQ8/IVF_PQ) are incompatible | Specify type=hnsw_sq (recommended) or type=hnsw when creating a vector index |
| Only MySQL mode is supported | Oracle mode is unavailable | Use a MySQL tenant |
7.2 Syntax Limitations
The following limitations affect how SQL statements are written:
| Limitation | Description | Recommended Syntax |
|---|---|---|
A WHERE clause at the same query level is not supported |
Filter conditions must be specified within the search query | WHERE → knn.filter or query.bool.filter |
A LIMIT clause at the same query level is not supported |
Use from / size within the search query for pagination |
LIMIT → "size": 10 |
An ORDER BY clause at the same query level is not supported |
Results are automatically sorted by the fusion score | Custom sorting cannot be specified |
| Multiple vector or full-text indexes on a searched column are not supported | Hybrid search through the SQL interface only checks the first full-text or vector index. If multiple indexes exist, an error may indicate that no full-text index can be found | Keep only one vector or full-text index on each referenced column (whether this behavior is by design remains to be confirmed) |
| Vector queries require an index | An error occurs if no vector index exists | Create a VECTOR INDEX first |
| Full-text queries require an index | An error occurs if no full-text index exists | Create a FULLTEXT INDEX first |
The score column is named __score |
Uses a double underscore, unlike the ES-style _score |
SELECT __score |
| Reserved-word restrictions in full-text search | The keywords and / or / not / to and 21 special characters are not supported |
Use a match or bool query instead |
7.3 Parameter Limits
The following parameters have value restrictions:
| Parameter | Allowed Range / Restriction |
|---|---|
from + size |
<= 10000 |
KNN k |
[1, 16384] |
rank_constant |
>= 1 |
rank_window_size |
>= size |
similarity |
IP distance is not supported |
knn.boost |
>= 0 |
| Weights in first-level clauses of a full-text search query | >= 0 |
| Weights in clauses below the first level of a full-text search query | > 0 |
bool.boost |
> 0 |
| Field weights / term weights | > 0 |
7.4 Other Considerations
| Item | Description |
|---|---|
| Scalar conditions do not contribute to scoring | Conditions within filter do not contribute to scoring and do not support boost; range / term / terms cannot be used in must / should clauses that require scoring |
| Generated columns are not supported | Generated columns cannot be used in queries |
rank_feature is not supported |
The current version does not support rank_feature queries |
| Multi-vector search does not support sparse vectors | Multi-vector search using the knn array format supports only dense vectors |
| Composite full-text indexes have no effect | Composite indexes on full-text columns ( CREATE FULLTEXT INDEX idx on table (col1, col2) ) have no effect on hybrid search; a separate index must be created for each column |
| Field names are case-insensitive | Field names in queries are case-insensitive |
| Filters are not shared across search branches | The filter for query and each knn is independent and must be specified separately |
refine_k applicability |
Supported only by HNSW_BQ indexes, not by standard HNSW/HNSW_SQ indexes |
7.5 Version Differences
| Version | Hybrid Search Method | Description |
|---|---|---|
| 4.4.1 | dbms_hybrid_search package | Compatible with ES hybrid query syntax; supports only RRF fusion |
| 4.6.0 | HYBRID_SEARCH SQL syntax | Pure SQL approach, compatible with ES DSL syntax; supports RRF / Weighted Sum / MinMax normalization |
The HYBRID_SEARCH syntax in 4.6.0 is recommended, as it offers a more complete feature set.
7.6 Frequently Asked Questions (FAQ)
Q: What is the difference between HYBRID_SEARCH and the dbms_hybrid_search package?
| Comparison | HYBRID_SEARCH (4.6.0+) | dbms_hybrid_search (4.4.1) |
|---|---|---|
| Syntax | Pure SQL syntax | PL package calls |
| Fusion algorithms | Weighted Sum / RRF / WRRF | RRF only |
| Recommendation | Recommended | For compatibility with older versions |
Q: What is the difference between a full-text index and a Search Index?
| Comparison | FULLTEXT INDEX | SEARCH INDEX |
|---|---|---|
| Purpose | Full-text search (BM25 scoring) | Accelerates filtering on JSON/Array columns |
| Supported types | VARCHAR / TEXT | JSON / ARRAY; can be created on a single column or multiple columns (e.g., ADD SEARCH INDEX idx(tags, categories) ) |
| Contributes to scoring | Yes | No |
| Use in queries | match / match_phrase, etc. | array_contains, etc. |
8. Summary
If you’ve had the patience to read this far, you must be a truly dedicated AI or database enthusiast. Thank you so much!
One last thing: this article covers a lot of ground, so there’s no need to memorize the SQL or parameters just yet. What matters is remembering these familiar fundamentals: vector search handles semantic retrieval, full-text search provides keyword-based fallback, scalar filtering narrows the scope, and fusion algorithms combine results from multiple retrieval methods into a single ranked list.
To wrap up, here are the key takeaways. OceanBase Hybrid Search 4.6.0 enables multimodal search with a single SQL statement. The core benefits of this hybrid search capability are:
-
Eliminate search blind spots: Vector search and full-text search complement each other to improve recall
-
Simplify development and operations: Replace multiple systems with a single database, and replace application-layer result merging with a single SQL statement
-
Flexible fusion strategies: Three built-in fusion algorithms—Weighted Sum / RRF / WRRF—support different use cases
Recommended adoption path:
-
Getting started: Start with RRF fusion, which requires no parameter tuning
-
Fine-tuning: Switch to Weighted Sum + minmax, and use boost to control the weight of each retrieval method
-
Performance optimization: Adjust parameters such as ef_search and filter_mode
References
[1] Easy Data x AI: https://github.com/datawhalechina/easy-data-x-ai