Shaf Lab

Full-text search

Finding documents or code by keywords or typo-tolerant matching, with engines such as Meilisearch.

Full-text search finds documents or records by the words they contain, often with typo tolerance, ranking, and filters. Engines such as Meilisearch sit next to your application and give you an index you can query in milliseconds. This is still the right default when people know some of the words they are looking for.

Build a good lexical index before you add vectors. Tokenization, stemming, synonyms, and a sensible ranking function solve a large share of queries. Then use filters — language, date, collection, permission — so the user never sees hits they should not. Permissions belong in the query, not in a later cleanup pass.

Keep the index in sync with the records. A write to the database should eventually appear in search, and a delete should disappear. For agents, expose a search tool that returns a short, ranked list with enough of the original text to act on, not an internal explain plan.

If users mostly ask questions in sentences and want a written answer, you may add retrieval and a model on top. That is AI search, and it still depends on this layer being decent.

BM25

A classic keyword ranking formula that weighs term frequency, term rarity, and document length.

BM25 is a classic formula for ranking documents by how well they match a keyword query, and the default ranking in many search engines. It rewards documents that contain the query terms, gives more weight to rare terms than common ones through inverse document frequency, and adjusts for document length so long documents do not win just by containing more words.

Two settings shape it. One controls how quickly repeated occurrences of a word stop adding score, so the tenth mention counts much less than the first; the other controls how strongly length is normalized. Common defaults are around 1.2 and 0.75. BM25 needs no training and excels at exact terms such as error codes, identifiers, and names, which is why it pairs so well with vector search in hybrid systems.