Back to all posts
3 min read

Why KnowHive Could Answer in Chinese While Keyword Search Missed

A document in KnowHive contained both Dijkstra and 最短路径, the Chinese term for “shortest path.” Searching the keyword index found the algorithm by its English name. Searching for the Chinese words printed in the document returned nothing.

KnowHive is a local knowledge base. It searches documents in two ways before passing passages to a language model. One search looks for words, like the index at the back of a book. The other uses vectors, numerical representations of meaning, to find related passages. As long as one search returned something relevant, the app could give a useful answer. Reading the answer told me very little about whether both searches had worked.

A test that separated the two paths

In August I queried SQLite's full-text search index, FTS5, directly against one Chinese document. The default tokenizer, the part that decides what counts as a searchable unit, treated an unspaced run of Chinese characters as one unit. Shorter terms inside it were hard to find.

Term from the documentOriginal indexThree-character index
哈希值 (hash value)MissHit
完整哈希 (complete hash)MissHit
最短路径 (shortest path)MissHit
DijkstraHitHit
SHAHitHit

This also changed how I read an earlier result. Hybrid search had done well on my bilingual programming notes. They were full of terms like Dijkstra and heapq. Those English terms could account for the keyword matches even when the surrounding Chinese contributed nothing.

Three changes had to ship together

I switched the index to trigrams, overlapping groups of three characters. For example, 最短路径 yields 最短路 and 短路径. This fixed short lookups. Feeding a whole question to the new index still produced zero hits in my test because it looked for the wording as one continuous substring.

I changed the query builder too. It splits Chinese text into overlapping groups, keeps Latin words together, and searches for any of the extracted terms. I tried a word segmenter as well. On this material it broke technical terms such as 哈希值 into individual characters, making the matches less selective.

Finally, an existing notebook already had an index. The database setup skipped creation whenever the table existed, so a new install could pass every test while a returning user kept the old behavior. I added a migration that rebuilt the keyword index from the stored passages. Their text and vectors were already on disk.

What improved, and what still misses

I compared both versions on the same 28 questions, retrieving five passages per question and keeping the evaluator fixed. About 8% of the corpus was Chinese. Context recall, a measure of how much of the required evidence we retrieved, rose from 0.8988 to 0.9524. Context precision, which measures how well relevant passages rank, moved from 0.8702 to 0.8524. Both runs used the revised query builder.

Two-character terms such as 排序 (“sorting”) still give this keyword index too little to work with. That's an easy limit to show a reader, and a useful test to keep next to the five successful lookups. The check I'd repeat in any hybrid search system is simple. Pick a phrase you can see in the document, query each search path separately, and try it on an index created before the fix. Experiment notes and results on Gitee