Interactive engineering lab

Code search tokenization: camelCase, snake_case and dual indexing

Code search tokenization: camelCase, snake_case and dual indexing. Change how identifiers are split and see which snippets a query can still find.

By Sandeep Belgavi · Published 2026-12-04 · Prepared 2026-12-03

Synthetic fixtures computed locally. No model, database or production service is contacted.

Experiment workspace

Decision trace

    The question this experiment answers

    A coding agent finds code through a search tool, and a lexical index can only match tokens it created. Does a query reach a word that sits inside a camelCase or snake_case identifier? Type a query, choose how the index treats identifiers (raw, underscore kept, split, or raw plus split), how a match is decided (phrase, all words, any word), whether acronyms and digits are split, the minimum token length and the number of results, and mark which snippets are relevant. The model reports which of eight synthetic snippets are returned, and recall and precision against your relevant list.

    Change one assumption at a time

    Start from the raw camelCase preset: a query for refund returns only the snippets where refund is already a separate token. Switch the index mode to split and the code snippets appear. Load the exact identifier preset to see a lowercase whole-identifier query fail on a split-only index, then switch to dual. Load the acronym preset and switch acronyms to split. Load the snake_case preset, where keeping underscores inside tokens hides open_return_case from a query for case, and switch the mode to raw.

    Expected outcomes

    Raw camelCase, query refund: 3 returned, 3 of 6 relevant found, recall 50%. Split: 6 of 6, recall 100%. Exact identifier issuerefund on a split-only index: 0 of 1; on the dual index: 1 of 1. Acronym query http client with acronyms kept: 1 of 2 relevant, recall 50%; with acronyms split, 2 of 2. Snake case query case with underscores kept inside tokens: 0 of 2; with the raw mode, which treats an underscore as a separator, 2 of 2. These figures match the companion SQLite FTS5 probe on the shared snippets.

    Read the metrics and the table

    Query tokens show what the query became after the same splitting rules; when the dual mode is on, both forms are listed. Returned counts snippets that matched and fit in the top results. Relevant found and recall measure how many of the snippets you marked relevant were returned; precision is the share of returned snippets that were relevant. Each table row is one snippet: the first indexed tokens, which query tokens matched, a simple score, and whether it was returned and marked relevant.

    What to take back to a real system

    Apply the same identifier splitting to documents and queries, and keep the original tokens as well, so both natural-language and exact-identifier queries work. Keep a small recall test of query and expected-file pairs drawn from real agent tasks and run it whenever the tokenizer or engine changes. Make the search tool report the query that actually ran and say explicitly when nothing matched, and give the agent a substring search as a second path.

    Limits of this model

    Eight synthetic snippets stand in for a repository. The tokenizer is a simplified model of SQLite FTS5 unicode61 with the separator rules described in the guide, and the score counts matched token occurrences rather than BM25, so it only orders results. Stemming, synonyms, embeddings and language-aware symbol indexes are out of scope.

    Views are my own and do not represent any employer, past or present.