Under the Hood of MLVA
How MLVA delivers instant, 100% offline natural-language code search combining dense vector embeddings, Okapi BM25 keyword indexing, and local SQLite storage.
System Architecture Diagram
Visual overview of how MLVA processes user queries, evaluates dual AI and lexical retrieval streams in parallel, and returns calibrated results in milliseconds.
mlva "Find Python code for linear regression"- Model:
Xenova/all-MiniLM-L6-v2(384-dimensional dense vectors) - Execution: 100% offline CPU inference via ONNX Runtime (Zero GPU/Cloud)
- Method: Cosine similarity between query vector and code chunk embeddings
- Strength: Finds matching code conceptually even with zero overlapping keywords
- Tokenization: Language-aware code lexer & inverted term frequency matrix
- Execution: Local SQLite inverted index lookups
- Method: Okapi BM25 with term saturation and match coordination factors
- Strength: Pinpoints exact function names, class identifiers, and literal syntax
~/.mlva/mlva.db)mlva show 1), and direct VS Code launcher (mlva code 1).Core Pillars of the Architecture
1. Local ONNX Model Inference
MLVA bundles the Xenova/all-MiniLM-L6-v2 transformer model. Executed locally via ONNX Runtime on your host CPU, it transforms document chunks into dense 384-dimensional unit vectors. No GPU, CUDA, or Python runtime required.
2. Okapi BM25 Keyword Engine
Pure vector search can occasionally miss exact function names or variable tokens. MLVA integrates Okapi BM25 scoring with term coordination factors to guarantee that exact identifier matches are boosted alongside conceptual matches.
3. Optimized SQLite Storage
Document chunks, tokens, and vector blobs are persisted in ~/.mlva/mlva.db using better-sqlite3 with Write-Ahead Logging (WAL) mode enabled, supporting thousands of queries per second with zero network latency.
4. Task & Language Intent Calibrator
Raw cosine similarity can produce false positives if two unrelated programs share general text tokens. MLVA analyzes user query grammar, detects target languages (e.g. Python vs Java), and validates algorithmic verbs to eliminate false matches.