A local code search engine in about 500 lines of OCaml: TF-IDF over code chunks, ranked by cosine similarity, printed as context for an LLM.
RoleBuilt it to learn OCaml
- Timeline
- 2026
- Stack
- OCaml
I wanted to learn OCaml and needed a problem small enough to finish. Cogitator indexes a codebase into chunks, splits identifiers the way programmers write them (getUserName becomes get, user, name), weights terms with TF-IDF and ranks chunks by cosine similarity. The output is a prompt with the most relevant code, ready to hand to a model.
It's deliberately simple: no embeddings, no server, no dependencies worth mentioning. The write-up of how it works, and what OCaml was good at, is in TF-IDF in OCaml.