---
id: 16763
lang: en
title: "Expert's RAG bot: hybrid search found the right material in 25% of questions, pure vector search in 42%"
published_at: "2026-10-27 20:02:16"
source_name: "Хабр: NLP"
source_url: "https://habr.com/ru/articles/1091058/?utm_campaign=1091058&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/16763"
categories: ["llm"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# Expert's RAG bot: hybrid search found the right material in 25% of questions, pure vector search in 42%

> **Краткая суть (BLUF):** The author built a Telegram bot on an expert's materials and found that most of the time goes into retrieval, not prompts. When a question is phrased differently from the source text, hybrid keyword-plus-semantic search put the right page in the top 6 in 25% of cases, while pure vector search did so in 42%. Noisy keyword search pushed correct results out of the list, because long courses flooded the output. So vector search should stay the primary channel, with keyword results appended as a short tail.  • Test bench: 24 questions in everyday language, written before looking at the corpus • Mean reciprocal rank of the correct page (MRR): 0.29 for vector, 0.10 for hybrid • The index of 1050 pages is a 4 MB numpy array, no vector database needed

An expert asked for a bot that answers in his voice and only from his own materials: PDF courses, video transcripts and recordings of sessions. If the answer isn't in the materials, the bot must honestly send the person to the live expert instead of making things up. The developer built such a bot in Python and Telegram, expecting to fiddle with prompts, but almost all the time went into retrieval: the model simply couldn't find the right material. The most surprising result of the measurements: the "hybrid" search that almost everyone recommends found the right material among the top six results in only 25% of semantic questions, while plain vector search did so in 42%.

What a "semantic question" is: a person writes "I watch the materials, but nothing sticks in my head, what should I do?", while the relevant page describes the process with the words "received, understood, accepted, applied". There are no words in common, so keyword search doesn't see that page. Semantic (vector) search compares not words but the meaning of the text, and handles such questions noticeably better.

## How the bot works and why the first version didn't

The stack is simple: Python 3.12, aiogram 3 in long-polling mode, SQLite for the user log, and Docker on a small VPS that also hosts other bots. The materials live in markdown files and are split into "pages" of about 4500 characters along paragraph boundaries. At the time of the last measurement the index held 53 materials and 630 pages. The model doesn't see the whole base: it has two tools, search over the materials and reading a page. It formulates the query itself, reads the relevant pages and answers strictly from what it has read. The author decided against putting everything into the context: the corpus is about 2.25 million characters, roughly a million tokens, and he didn't want to pay for that volume in every answer.

The first version searched with SQLite's full-text FTS5 and bm25 ranking. On a mini-test of eight questions it scored 8 out of 8, but the test was unfair: the questions were worded close to the file names. Real people don't write like that. Switching models didn't help: neither Sonnet nor Opus could fetch the material, because they had nothing to search with.

## The test bench: how the author measured quality

To tell an actual improvement from his own impression, the author built a test bench: a file of cases and a script that runs them through a chosen search mode. A case is a question, a list of materials containing the answer, and a type: "lexical" (the question's words appear in the material), "semantic" (the answer is written in different words) and "no answer" (the bot should send the person to the expert). All questions were written before looking at the corpus, in colloquial language, with typos and slang.

There are two metrics. Recall@k shows whether the right material landed anywhere in the first k results, that is, whether the model will see the right page at all. MRR is the mean of 1/rank of the first correct result: 1.0 means the right material is always first. The first finding was unpleasant: even when the question's words do appear in the material, FTS5 at k=6 found the right document in only slightly more than a third of cases. The causes: no stemming ("клиентов" doesn't match "клиенты"), long materials clog the top with sheer volume, and colloquial junk like "ваще" ("totally") enters the query on equal footing with the topic.

## Vector search without a vector database, and the hybrid that lost

Vector search needs not a database but an array: 1050 pages of 1024 numbers each take about 4 MB, and the dot product of a question with the whole matrix in numpy takes about a millisecond. The vectors are computed once and cached on disk by page hash and model name. If there is no API key or the service is down, the bot quietly falls back to FTS5 and keeps working.

Then the author did what most articles recommend: he combined both channels with RRF. Each page gets 1/(60 + rank) from each list, and the scores are summed. The expectation was simple: hybrid would be no worse than vector and better on rare words. On the same 24 cases at k=6 the opposite happened: on semantic questions hybrid scored 25% against 42% for vector, with MRR 0.10 against 0.29. Keyword search is so noisy that it mixes in junk and pushes out the correct results from the vector channel. Lowering the keyword channel's weight from 1.0 to 0.05 raised MRR only from 0.10 to 0.20, still below 0.29. The depth of the candidate pool (10, 20, 40) had no effect on the result.

In production the scheme is this: the vector results go out as they are, and up to three keyword results that weren't already there are appended at the end. On the test bench this changes neither recall nor MRR, but it insures against the case of a rare exact word, such as a name or title, where semantic similarity is weak.

## Protection against fabrication and what to take away

Rules in the prompt alone turned out to be insufficient: on a follow-up question the bot once answered from the dialogue history without calling search, and lost the expert's caveats. Now the code has a stopper: if the model is about to answer without having called search even once, the answer is discarded and the turn is sent again with the system message "search the materials first". On seven test "question → follow-up" pairs, answers without search dropped to 0 from 1. This is a nudge, not a guarantee: Sonnet 5.5 rejects a forced tool call with a 400 error.

The practical takeaway for anyone building RAG: build a test bench with real-life questions first, then choose the architecture. Don't treat hybrid search as dogma, and test it on your own data. For a small corpus, numpy without a vector database is enough. A caveat: the figures come from 24 cases on a single corpus, so this is an example of a method, not a universal constant. The author covers the remaining difficulties, including hitting the embedding provider's rate limits, in the original.

---
- **Первоисточник:** [Хабр: NLP](https://habr.com/ru/articles/1091058/?utm_campaign=1091058&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/16763
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
