SQLite instead of Elasticsearch: hybrid search on a small knowledge base

I know Elasticsearch well, so why didn't I use it for my RAG assistant? How I combined BM25 and vector search inside SQLite for a 29-passage knowledge base, and how the Turkish language got involved.

Why not Elasticsearch

At work I use Elasticsearch for search and indexing, and I like the tool. But when I looked at the size of the knowledge base for my portfolio assistant, the decision made itself: everything about me fit into 29 passages, about 380 characters each on average.

Running Elasticsearch for this would have meant about 1.5 GB of memory on its own, on an 8 GB server that also hosts other sites. Instead of operating a search cluster for 29 passages, I used SQLite, which already ships with Python. The extra memory cost is close to zero and a search takes milliseconds.

The right tool is not always the most powerful one; it is the one that fits the size of the data.

Why one search is not enough

Both classic search methods fall short on their own:

  • Keyword search (BM25) is very good with exact terms: it does not miss names like "ELK", "Proxmox" or "Hangfire". But it struggles with a question like "How does Göktuğ analyse logs?", which does not use the words in the knowledge base.
  • Vector search captures meaning: it takes a question phrased in different words to the right passage. But it is unreliable with abbreviations and names; "ELK" may not mean much to an embedding model.

So I run both and merge the results.

How it works

  1. Chunking. The knowledge base is a set of Markdown files. Each ## heading is a section, and long sections are split into chunks of about 700 characters. Each chunk starts with its document and section title (such as "Experience › Telpass"), so even a short chunk carries what it is about.
  2. Keyword index. Chunks are written to SQLite's FTS5 full-text index, and FTS5's own BM25 score does the ranking.
  3. Vectors. Each chunk is turned into a vector with a multilingual embedding model and stored in the same SQLite file. At query time the question is embedded too, and cosine similarity against the 29 vectors is computed in memory. At this size there is no need for a vector database.
  4. Fusion. The top 8 results from each method are merged into one list with Reciprocal Rank Fusion: each chunk gets 1 / (60 + rank) points for its position in each list, and the points are added up. A chunk near the top of both lists rises to the top. The best 4 chunks go to the language model.

The nice thing about RRF is that it does not try to make the two scores comparable. A BM25 score and a cosine similarity live on different scales; RRF only looks at rank.

The Turkish problem

Turkish is an agglutinative language: "proje", "projeler", "projelerde" and "projesi" are the same word, but four different terms for keyword search. Instead of adding a full stemmer, I used a very simple method:

  • Drop everything after an apostrophe ("Telpass'ta" → "telpass").
  • Lowercase the Turkish way ("İ" → "i", "I" → "ı").
  • Keep the first 5 letters of each word ("projelerde" → "proje").
  • Drop filler words such as "ve", "ile", "nedir".

The same steps run both when indexing and when a question comes in, so matching stays consistent. It is not perfect, and some short words can collide. But for a 29-passage knowledge base this simple method more than does the job, and it is a one-line function.

A bug I ran into

One day I updated my CV and rewrote the knowledge base, and the accuracy test dropped from 40 to 37. The code had not changed; the problem was in chunking. The answer to "Where does he work now?" was buried inside a long experience paragraph, and that chunk did not match the question well enough by either keywords or meaning.

The fix was not to change the search but to put the information in the right place: I added a separate "Current job" section and wrote the answer as one clear sentence. The test went back up to 39/40.

In RAG, much of the answer quality comes not from the model but from how the information is chunked.

What I learned

  • Choose the tool for the size of the data. For 29 passages, a SQLite file is enough; a search cluster is not needed.
  • Combine two searches. BM25 catches names, vector search catches meaning, and RRF merges them without worrying about scales.
  • Small language-specific steps make a big difference. Even crude stemming for Turkish improves matching noticeably.
  • Look at the knowledge base first. When search gives bad results, the problem is often not the algorithm but the chunking.