How codemogger indexing and searching works
mainCodemogger follows a five-step pipeline to make code searchable:
- Scan: Walks the directory, respects
.gitignore, and detects languages via file extensions. - Chunk: Uses
tree-sitter(WASM) to parse files and extract top-level definitions (functions, structs, classes,implblocks). Items exceeding 150 lines are split into sub-items. - Embed: Encodes chunks using a local embedding model (e.g.,
all-MiniLM-L6-v2). - Store: Saves chunks and embeddings into a single SQLite database using Turso, utilizing FTS (Full-Text Search) and vector extensions.
- Search: Supports two modes:
- Semantic: Uses vector cosine similarity for natural language queries.
- Keyword: Uses FTS with weighted fields for precise identifier lookups.
Indexing is incremental; only files with changed SHA-256 hashes are re-processed on subsequent runs.