3 weeks ago
Lakebase Search brings vector search and BM25 keyword search directly into Lakebase, Databricks’ managed, serverless PostgreSQL offering.
It introduces two PostgreSQL extensions:
Together, these extensions enable semantic, keyword, and hybrid retrieval using SQL in the same database that stores your operational data.
In this post, we’ll explore how Lakebase Search works, when to use each retrieval mode, and how to build a working search implementation with SQL.
Modern applications commonly need three types of search:
| Search mode | Question it answers | Example query |
| Keyword | Which records contain these exact terms? | SKU-12345, an error code |
| Semantic (vector) | Which records have a similar meaning? | “A fantasy book about a boy wizard” |
| Hybrid | Which records are relevant by both meaning and keywords? | “Harry Potter magic school adventure” |
PostgreSQL has long provided reliable transactional capabilities, built-in full-text search, and vector search through extensions such as pgvector.
However, at scale, teams often operate three separate systems:
This architecture introduces several challenges:
Lakebase Search aims to simplify this architecture by bringing keyword and vector retrieval into the same PostgreSQL database, using SQL as the common interface.
Lakebase Search introduces two extensions that support different retrieval strategies.
| Extension | Purpose | Index type |
| lakebase_vector | ANN vector search with pgvector-compatible types, operators, and syntax | lakebase_ann |
| lakebase_text | BM25 keyword search using PostgreSQL tsvector | lakebase_bm25 |
The vector search index uses IVF partitioning with RaBitQ quantization.
Key characteristics include:
Databricks positions the technology for very large indexes, including workloads with more than one billion vectors. Consult the official documentation for benchmark results and the conditions under which these performance claims apply.
BM25 is a ranking algorithm that considers term frequency, document length, and corpus-wide statistics.
PostgreSQL’s built-in ts_rank does not use corpus-wide inverse document frequency statistics in the same way. This can affect relevance ranking for large document collections.
Lakebase Search also uses Block-Max WAND to efficiently retrieve top-ranked results without scoring every matching document.
Hybrid search combines vector similarity and keyword relevance in a single SQL statement.
There is no separate hybrid operator. Instead, you can retrieve candidates from both search methods and combine their rankings using an algorithm such as Reciprocal Rank Fusion (RRF).
We’ll implement this in Section 6.
Before enabling Lakebase Search, check the following prerequisites:
Important: Enabling Lakebase Search is irreversible according to the feature guidance described here and restarts all computes in the project, dropping active connections. Test it in a disposable project before enabling it in a production environment.
After enabling the feature, install the extensions:
CREATE EXTENSION IF NOT EXISTS lakebase_vector CASCADE; CREATE EXTENSION IF NOT EXISTS lakebase_text;
The CASCADE option installs the required pgvector dependency for lakebase_vector.
Vector search retrieves records based on the similarity between numerical embeddings.
Each record stores an embedding in a VECTOR(n) column, where n must match the embedding model’s output dimension. The table column, index configuration, and query vector must all use compatible dimensions and distance metrics.
| Metric | Operator class | Operator | Typical Use case |
| Cosine distance | vector_cosine_ops | <=> | Text embeddings and semantic search |
| L2 (Euclidean) distance | vector_l2_ops | <-> | Workloads where absolute geometric distance matters |
| Negative inner product | vector_ip_ops | <#> | Similarity ranking, especially with normalized vectors |
Choose the metric based on how your embedding model is intended to be used. The index operator class and query operator must match.
CREATE TABLE items (
id BIGSERIAL PRIMARY KEY,
embedding VECTOR(3)
);The three-dimensional vector is used here only to keep the example small. In a real application, use the dimension produced by your embedding model, such as 384 or another supported dimension.
INSERT INTO items (embedding) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000);
This generates synthetic vectors for demonstration purposes. It does not generate meaningful semantic embeddings.
CREATE INDEX ON items USING lakebase_ann (embedding vector_l2_ops);
For larger datasets, building the index after bulk-loading data can be more efficient than creating it before the initial load.
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
This query returns the five nearest vectors using L2 distance.
Lakebase Search exposes options for managing index-building performance and query-time recall.
Verify the supported settings and their exact configuration syntax in the documentation for your Lakebase version.
Vector search is useful for semantic similarity, but exact identifiers, product codes, error messages, and terminology often benefit from keyword retrieval.
Lakebase Search provides BM25 ranking through the lakebase_text extension.
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
passage TEXT,
vector TSVECTOR GENERATED ALWAYS AS (
to_tsvector('english', passage)
) STORED
);The generated column automatically maintains the text-search representation when the underlying passage changes.
INSERT INTO documents (passage)
VALUES
('Postgres is a powerful open-source relational database.'),
('Vector search finds semantically similar results.'),
('BM25 ranking improves full-text search relevance scores.');CREATE INDEX documents_passage_bm25 ON documents USING lakebase_bm25 (vector);
Build the index after loading the initial dataset so that the index can calculate corpus statistics from the populated collection.
SELECT
id,
passage,
vector <@> to_bm25query(
to_tsvector('english', 'database'),
'documents_passage_bm25'
) AS score
FROM documents
ORDER BY score
LIMIT 5;The <@> operator returns a negative BM25 score, so ascending order places the most relevant results first.
Operational consideration: BM25 ranking depends on corpus statistics calculated during index construction. Review the documented behavior for inserts and updates, and determine whether your workload requires index maintenance or rebuilding to keep ranking quality aligned with the evolving dataset.
Vector and keyword retrieval produce scores on different scales. Combining their raw scores directly can therefore be misleading.
Reciprocal Rank Fusion avoids this issue by combining the rank positions of documents rather than their raw scores.
The RRF formula is:
RRF(d)=1k+rv(d)+1k+rk(d)\operatorname{RRF}(d) = \frac{1}{k+r_v(d)} + \frac{1}{k+r_k(d)}
Where:
A document appearing near the top of both result lists receives a stronger combined score.
CREATE TABLE docs (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
embedding VECTOR(3),
body_tsv TSVECTOR GENERATED ALWAYS AS (
to_tsvector('english', body)
) STORED
);INSERT INTO docs (title, body, embedding)
VALUES
(
'Postgres overview',
'Postgres is an open-source relational database.',
'[0.1, 0.2, 0.3]'
),
(
'Vector search guide',
'Vector search finds semantically similar results.',
'[0.4, 0.5, 0.6]'
),
(
'Full-text search',
'BM25 ranking improves keyword search relevance.',
'[0.7, 0.8, 0.9]'
);These embeddings are illustrative and are not intended to represent actual semantic relationships.
CREATE INDEX ON docs USING lakebase_ann (embedding vector_cosine_ops); CREATE INDEX docs_body_bm25 ON docs USING lakebase_bm25 (body_tsv);
The following query retrieves candidates from both methods, assigns ranks, and combines them using RRF.
WITH vector_ranked AS (
SELECT
id,
RANK() OVER (ORDER BY dist) AS rank
FROM (
SELECT
id,
embedding <=> '[0.1, 0.2, 0.3]' AS dist
FROM docs
ORDER BY dist
LIMIT 40
) v
),
keyword_ranked AS (
SELECT
id,
RANK() OVER (ORDER BY score) AS rank
FROM (
SELECT
id,
body_tsv <@> to_bm25query(
to_tsvector('english', 'database'),
'docs_body_bm25'
) AS score
FROM docs
ORDER BY score
LIMIT 40
) k
)
SELECT
d.id,
d.title,
COALESCE(1.0 / (60 + v.rank), 0)
+ COALESCE(1.0 / (60 + k.rank), 0) AS rrf_score
FROM docs d
LEFT JOIN vector_ranked v
ON d.id = v.id
LEFT JOIN keyword_ranked k
ON d.id = k.id
WHERE v.id IS NOT NULL
OR k.id IS NOT NULL
ORDER BY rrf_score DESC, d.id
LIMIT 10;The LEFT JOIN and COALESCE expressions ensure that a document found by only one retrieval method still contributes to the final ranking.
The d.id tie-breaker makes result ordering deterministic for equal RRF scores, although stable pagination across changing data may still require an appropriate snapshot or cursor strategy.
Tuning tip: The candidate limit of 40 and the RRF constant of 60 are starting points, not universal defaults. Evaluate them against your dataset, relevance requirements, recall targets, and latency budget. Weighted fusion is another option when one retrieval method should contribute more strongly than the other.
You do not need to write every record directly into PostgreSQL.
Lakebase synced tables allow you to replicate a Unity Catalog Delta table into Lakebase, making lakehouse data available to operational applications and search workloads.
| Mode | Behavior | Change Data Feed required | Best suited for |
| Snapshot | One-time full copy | No | Initial setup and smaller datasets |
| Triggered | Updates on demand or on a schedule | Yes | Periodic refreshes |
| Continuous | Ongoing, near-real-time synchronization | Yes | Applications requiring frequent updates |
For modes that require Change Data Feed (CDF), enable it on the source Delta table:
ALTER TABLE your_table
SET TBLPROPERTIES (
delta.enableChangeDataFeed = true
);Once the synced data is available in Lakebase:
An important design principle: Search freshness is constrained by the freshness of the underlying synchronized data and any downstream embedding or indexing work. Select the synchronization mode based on your application’s latency requirements.
| Use case | Recommended approach | Why |
| RAG over internal documents | Vector or hybrid | Retrieves semantically relevant passages, with hybrid search adding exact-term matching |
| Product and e-commerce search | Hybrid | Combines descriptions and semantic similarity with product names and SKUs |
| Similar historical support tickets | Vector | Finds issues with similar meaning even when wording differs |
| Source code, identifiers, and error codes | Keyword | Exact terminology and identifiers matter |
| Recommendations based on similarity | Vector | Finds items with similar embedding representations |
These are starting points. The best approach depends on your data, query patterns, and relevance evaluation results.
Lakebase Search simplifies the search architecture, but it does not eliminate the need for careful system design.
The feature is in Beta, and enabling it is described as irreversible. Test it in a separate project and confirm the current feature limitations before rolling it out.
Search queries and transactional operations share the database environment. Heavy indexing or retrieval workloads can affect application latency, so benchmark realistic workloads and size your compute accordingly.
Lakebase Search is not necessarily a drop-in replacement for every Elasticsearch or OpenSearch capability.
Evaluate requirements such as:
Your application is responsible for producing and maintaining embeddings. The vector dimension must match the model output and schema, and switching embedding models generally requires regenerating embeddings and rebuilding or updating the relevant indexes.
If your primary requirement is a managed vector index over Delta tables, evaluate Databricks Vector Search as well.
Lakebase Search is especially worth considering when retrieval needs to live alongside operational PostgreSQL data. The right choice depends on your data architecture, query requirements, latency targets, and operational constraints.
| Task | SQL |
| Install vector extension | CREATE EXTENSION IF NOT EXISTS lakebase_vector CASCADE; |
| Install text extension | CREATE EXTENSION IF NOT EXISTS lakebase_text; |
| Define vector column | embedding VECTOR(384) |
| Define text-search column | body_tsv TSVECTOR GENERATED ALWAYS AS (to_tsvector('english', body)) STORED |
| Create ANN index | CREATE INDEX ON tbl USING lakebase_ann (embedding vector_cosine_ops); |
| Create BM25 index | CREATE INDEX idx ON tbl USING lakebase_bm25 (body_tsv); |
| Run vector search | SELECT * FROM tbl ORDER BY embedding <=> '[...]' LIMIT 10; |
| Run BM25 search | SELECT *, body_tsv <@> to_bm25query(to_tsvector('english', 'q'), 'idx') AS score FROM tbl ORDER BY score LIMIT 10; |
Lakebase Search brings vector, keyword, and hybrid retrieval into the PostgreSQL database that already holds your operational data.
By combining lakebase_vector and lakebase_text, applications can use SQL to retrieve semantically similar content, rank keyword matches with BM25, and combine both result sets with Reciprocal Rank Fusion.
For workloads where search and transactions operate on the same data, this can reduce infrastructure complexity and eliminate some of the synchronization work associated with maintaining separate search systems.
However, Lakebase Search is still in Beta. Before adopting it for production workloads, validate its relevance, recall, latency, indexing behavior, and operational trade-offs against your own dataset.
Have you tried Lakebase Search? Share your implementation experience, performance results, and questions in the comments.
Author: Isaac Pandraju Feature status: Beta Last reviewed: October 2026