Tabby uses Retrieval Augmented Code Completion to solve the problem of LLMs lacking knowledge of a large, complex codebase. Instead of sending the entire codebase (which exceeds context windows and increases latency), Tabby selectively retrieves and prepends relevant code snippets to the completion request.
How it works:
- Indexing: Tabby uses Tree-sitter queries to scan source code and extract meaningful symbols (variables, classes, methods, function signatures) from various languages.
- Retrieval: When a completion request is made, Tabby tokenizes the request and performs a BM25 search against a token reverse index of the repository to find relevant snippets.
- Formatting: The retrieved snippets are formatted as line comments (e.g.,
// Path: path/to/file.rs) and prepended to the prompt. This allows the LLM to understand the context without disrupting the existing code semantics.
This approach allows the LLM to correctly identify function signatures and dependencies that are defined in other files, preventing incorrect API calls.