BM25 Search
How to run keyword (BM25) search with model reranking using the per-table bm25 endpoint.
BM25 Search runs a keyword search through each Table's bm25 endpoint and then has a model rerank the candidates by how well they answer the query. By the end of this guide, you will be able to retrieve Contents for queries that contain exact names, codes, or terms, with scores, and control whether and how the results are reranked.
Prerequisites:
- Vector sync must be completed for the Table you want to search. BM25 searches the text chunks produced by the sync.
- A secret Project API Key (
sk-proj_…) is required: the search is aPOSTrequest, which publishable keys cannot make. Call it from your server, not from the browser. - The query is not embedded, so no
API.EMBEDDINGS.TOKENSare consumed. Model tokens spent on reranking (rerank: true) are recorded asAI.ASK.TOKENS.
How It Works
- BM25 scoring — The query is split into words. Korean words also contribute two-character bigrams, so "환불정책" matches "환불 정책이 어떻게 되나요". Each text chunk is scored by how often the query words appear (term frequency), how rare each word is across the corpus (IDF), and how long the chunk is (length normalization). A content's score is the best of its chunks, normalized so the top content is
1(bm25_score). - Reranking — The top
candidatescontents are handed to a model that rates how well each one actually answers the query, from0to1. That rating is the finalscore. Withrerank: falsethis step is skipped andbm25_scorebecomes thescore. - Selection — Contents below
thresholdare dropped and up tocountitems are returned in descendingscoreorder.
Which search should you use?
| Situation | Recommendation |
|---|---|
| Product names, model numbers, proper nouns, error codes | BM25 Search |
| Content that means the same thing with different wording | Embeddings Search |
| Keyword matches that need filtering down to real answers | BM25 Search + rerank: true (default) |
| Fast keyword lookup at minimal cost | BM25 Search + rerank: false |
Endpoint
POST /v1/{projectId}/tables/{tableSlug}/bm25
Use the Table's slug for {tableSlug}. If the Table has no slug, use its Table ID.
Request Body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
query |
string |
Yes | - | The search query text. Words and Hangul bigrams are matched against the synced text |
count |
integer |
- | 5 |
Maximum number of results to return (1–100) |
threshold |
number |
- | 0 |
Minimum score to include (0–1). Applies to the rerank score when rerank is on, otherwise to the normalized BM25 score |
rerank |
boolean |
- | true |
Rerank the BM25 candidates with a model. false spends no AI tokens |
candidates |
integer |
- | 20 |
Number of top BM25 contents handed to the reranker (1–100). Ignored when rerank is false |
k1 |
number |
- | 1.2 |
BM25 term-frequency saturation (0–3). Higher values reward texts that repeat the query words |
b |
number |
- | 0.75 |
BM25 length normalization (0–1). 0 ignores text length, 1 fully penalizes long texts |
The defaults for k1 and b work for most Tables. Lower b for Tables made of short titles; keep the default for long bodies.
Request Examples
curl -X POST "https://api.onttle.com/v1/{projectId}/tables/products/bm25" \
-H "Authorization: Bearer $ONTTLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "AirPods Pro 2nd generation case",
"count": 5,
"rerank": true,
"candidates": 20
}'
Keyword search without reranking
curl -X POST "https://api.onttle.com/v1/{projectId}/tables/products/bm25" \
-H "Authorization: Bearer $ONTTLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "SKU-20481",
"count": 3,
"rerank": false
}'
TypeScript Example
const res = await fetch(
'https://api.onttle.com/v1/{projectId}/tables/products/bm25',
{
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'AirPods Pro 2nd generation case',
count: 5,
threshold: 0.5,
}),
},
)
const { list, reranked } = await res.json()
// list: Contents ordered by score (includes score and bm25_score)
// reranked: whether the reranker actually ran
Response Format
Results are returned as a list array ordered by descending score. Each item includes the Contents fields plus two scores.
{
"list": [
{
"id": "cnt_01hxk2",
"slug": "airpods-pro-2-case",
"score": 0.92,
"bm25_score": 1,
"data": {
"name": "AirPods Pro 2nd Gen Silicone Case"
}
}
],
"reranked": true
}
| Field | Type | Description |
|---|---|---|
list |
object[] |
Matching Contents |
score |
number |
Final score (0–1): the rerank relevance, or equal to bm25_score when rerank is false |
bm25_score |
number |
Normalized BM25 score (0–1). The best keyword match is 1 |
reranked |
boolean |
Whether reranking ran. false when rerank was off or the reranker failed and BM25 scores were returned |
Managing Endpoint Activation
The bm25 endpoint is enabled by default when a Table is created. Go to API in the Project's left menu, open the Table's Search by keywords (BM25) page, and use the toggle in the top right to enable or disable it. The same toggle is available in the API endpoints list of the Table settings.
Troubleshooting
| Symptom | Check |
|---|---|
| No results | Verify Vector sync status is SUCCESS, make sure the query contains words that appear in the synced text, lower threshold |
| Keywords match but answers are wrong | Verify rerank: true and raise candidates so more contents reach the reranker |
| Slow responses | Lower candidates or skip reranking with rerank: false |
reranked is false |
Either rerank: false was requested or the rerank model call failed. The latter falls back to BM25 scores and is logged server-side |
| Request rejected | Check the endpoint activation toggle and that you are using a secret key (sk-proj_…) |
Next Steps
- Embeddings Search — Use meaning-based search.
- Chats — Use
search_type: "bm25"to ground chat answers with BM25 + rerank retrieval. - Usage & Billing — See how reranker tokens are recorded under
AI.ASK.TOKENS.