Adding Keyword Search with BM25

Search is one POST request, but it only sees what has been synced. Here is what that means in practice.

The endpoint

Each Onttle table has a bm25 endpoint. You send a query and get back posts with a score:

await fetch(`${base}/tables/posts/bm25`, {
  method: "POST",
  body: JSON.stringify({ query, count: 20, rerank: false }),
});

Why rerank is off

By default a model reranks the keyword matches. That costs AI tokens on every search. For a blog with a handful of posts, plain BM25 scoring is enough, so this example sets rerank: false.

The catch

BM25 searches text produced by Vector sync. If you publish or edit a post and do not sync again, search will not know about it. The app also cross-checks results against the published list before showing them.

Try it

Search for webhook, BM25 or server-only on this site and see which posts come back.

← 글 목록