Skip to content

Commit 487827a

Browse files
Add Documentation for Experimental Codebase Indexing Feature (#204)
* Add complete documentation for the new experimental Codebase Indexing feature that enables semantic code search using AI embeddings. ## New Documentation - **docs/features/experimental/codebase-indexing.mdx**: Comprehensive feature documentation covering: - Semantic search capabilities using Tree-sitter parsing and AI embeddings - Setup requirements for OpenAI/Ollama embedding providers and Qdrant vector database - Configuration steps and status indicators - File processing with smart code parsing and automatic filtering - Best practices for model selection and security considerations - Current limitations and future enhancements - Privacy and security considerations ## Updated Navigation & Cross-references - **sidebars.ts**: Added Codebase Indexing to Features > Experimental navigation menu - **docs/features/experimental/experimental-features.md**: - Added Codebase Indexing to experimental features list - Added screenshot showing the experimental features settings panel - **docs/faq.md**: Added FAQ entries explaining: - What Codebase Indexing is and its semantic search capabilities - Cost considerations for embedding generation and vector storage ## Assets - **static/img/experimental-features/experimental-features.png**: Screenshot of experimental features settings panel ## Technical Details Covered - Tree-sitter integration for AST-based code parsing - Support for both OpenAI and Ollama embedding providers - Qdrant vector database integration with local and cloud deployment options - Incremental indexing with file watching and hash-based caching - Smart file filtering excluding binaries, large files, and common ignore patterns - codebase_search tool integration for AI-powered code discovery The documentation is targeted at a semi-technical audience and provides practical setup guidance while explaining the underlying semantic search technology. * Add comprehensive documentation for the experimental codebase_search tool and reorganize the tool category structure to better distinguish between read and search functionality. ## New Documentation - **docs/advanced-usage/available-tools/codebase-search.md**: Complete tool documentation covering: - Semantic search capabilities using AI embeddings and vector similarity - Integration with experimental Codebase Indexing feature with proper warning - Parameters, requirements, and configuration dependencies (OpenAI/Ollama + Qdrant) - Detailed workflow explanation from query processing to result formatting - Best practices for effective semantic queries vs. traditional text search - Directory scoping capabilities and result interpretation guidelines - Usage examples demonstrating authentication, database, error handling, and testing searches - Similarity scoring explanation and result structure details ## Updated Navigation & Organization - **sidebars.ts**: Added codebase_search to Available Tools navigation menu - **docs/advanced-usage/available-tools/tool-use-overview.md**: Reorganized tool categories: - Split "Read Group" into separate "Read Group" and "Search Group" categories - **Read Group**: File system reading and exploration (read_file, list_files, list_code_definition_names) - **Search Group**: Pattern and semantic searching (search_files, codebase_search) - Updated tool group table to reflect the new logical separation - Updated common patterns example to showcase semantic search with codebase_search - Improved categorization aligns with actual tool usage patterns ## Technical Coverage The documentation accurately reflects the tool's implementation including: - CodeIndexManager integration and availability validation - Dual output format for AI and UI consumption - Vector similarity search with cosine similarity and 0.4 threshold - Performance optimizations (50 result limit, Tree-sitter language support) - Path filtering and workspace-relative result formatting - Integration with experimental indexing infrastructure This provides users with clear guidance on semantic code search capabilities while maintaining appropriate warnings about the experimental nature of the feature. * Refactor code structure for improved readability and maintainability
1 parent 30f1862 commit 487827a

File tree

8 files changed

+430
-4
lines changed

8 files changed

+430
-4
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# codebase_search
2+
3+
:::warning Experimental Feature
4+
The `codebase_search` tool is part of the experimental [Codebase Indexing](/features/experimental/codebase-indexing) feature. This feature is under active development and may change significantly in future releases. It requires additional setup including an embedding provider and vector database.
5+
:::
6+
7+
The `codebase_search` tool performs semantic searches across your entire codebase using AI embeddings. Unlike traditional text-based search, it understands the meaning of your queries and finds relevant code even when exact keywords don't match.
8+
9+
## Parameters
10+
11+
The tool accepts these parameters:
12+
13+
- `query` (required): Natural language search query describing what you're looking for
14+
- `path` (optional): Directory path to limit search scope to a specific part of your codebase
15+
16+
## What It Does
17+
18+
This tool searches through your indexed codebase using semantic similarity rather than exact text matching. It finds code blocks that are conceptually related to your query, even if they don't contain the exact words you searched for. Results include relevant code snippets with file paths, line numbers, and similarity scores.
19+
20+
## When is it used?
21+
22+
- When Roo needs to find code related to specific functionality across your project
23+
- When looking for implementation patterns or similar code structures
24+
- When searching for error handling, authentication, or other conceptual code patterns
25+
- When exploring unfamiliar codebases to understand how features are implemented
26+
- When finding related code that might be affected by changes or refactoring
27+
28+
## Key Features
29+
30+
- **Semantic Understanding**: Finds code by meaning rather than exact keyword matches
31+
- **Cross-Project Search**: Searches across your entire indexed codebase, not just open files
32+
- **Contextual Results**: Returns code snippets with file paths and line numbers for easy navigation
33+
- **Similarity Scoring**: Results ranked by relevance with similarity scores (0-1 scale)
34+
- **Scope Filtering**: Optional path parameter to limit searches to specific directories
35+
- **Intelligent Ranking**: Results sorted by semantic relevance to your query
36+
- **UI Integration**: Results displayed with syntax highlighting and navigation links
37+
- **Performance Optimized**: Fast vector-based search with configurable result limits
38+
39+
## Requirements
40+
41+
This tool is only available when the experimental Codebase Indexing feature is properly configured:
42+
43+
- **Feature Enabled**: Codebase Indexing must be enabled in experimental settings
44+
- **Embedding Provider**: OpenAI API key or Ollama configuration required
45+
- **Vector Database**: Qdrant instance running and accessible
46+
- **Index Status**: Codebase must be indexed (status: "Indexed" or "Indexing")
47+
48+
## Limitations
49+
50+
- **Experimental Feature**: Part of the experimental codebase indexing system
51+
- **Requires Configuration**: Depends on external services (embedding provider + Qdrant)
52+
- **Index Dependency**: Only searches through indexed code blocks
53+
- **Result Limits**: Maximum of 50 results per search to maintain performance
54+
- **Similarity Threshold**: Only returns results above 0.4 similarity score
55+
- **File Size Limits**: Limited to files under 1MB that were successfully indexed
56+
- **Language Support**: Effectiveness depends on Tree-sitter language support
57+
58+
## How It Works
59+
60+
When the `codebase_search` tool is invoked, it follows this process:
61+
62+
1. **Availability Validation**:
63+
- Verifies that the CodeIndexManager is available and initialized
64+
- Confirms codebase indexing is enabled in settings
65+
- Checks that indexing is properly configured (API keys, Qdrant URL)
66+
- Validates the current index state allows searching
67+
68+
2. **Query Processing**:
69+
- Takes your natural language query and generates an embedding vector
70+
- Uses the same embedding provider configured for indexing (OpenAI or Ollama)
71+
- Converts the semantic meaning of your query into a mathematical representation
72+
73+
3. **Vector Search Execution**:
74+
- Searches the Qdrant vector database for similar code embeddings
75+
- Uses cosine similarity to find the most relevant code blocks
76+
- Applies the minimum similarity threshold (0.4) to filter results
77+
- Limits results to 50 matches for optimal performance
78+
79+
4. **Path Filtering** (if specified):
80+
- Filters results to only include files within the specified directory path
81+
- Uses normalized path comparison for accurate filtering
82+
- Maintains relevance ranking within the filtered scope
83+
84+
5. **Result Processing and Formatting**:
85+
- Converts absolute file paths to workspace-relative paths
86+
- Structures results with file paths, line ranges, similarity scores, and code content
87+
- Formats for both AI consumption and UI display with syntax highlighting
88+
89+
6. **Dual Output Format**:
90+
- **AI Output**: Structured text format with query, file paths, scores, and code chunks
91+
- **UI Output**: JSON format with syntax highlighting and navigation capabilities
92+
93+
## Search Query Best Practices
94+
95+
### Effective Query Patterns
96+
97+
**Good: Conceptual and specific**
98+
```xml
99+
<codebase_search>
100+
<query>user authentication and password validation</query>
101+
</codebase_search>
102+
```
103+
104+
**Good: Feature-focused**
105+
```xml
106+
<codebase_search>
107+
<query>database connection pool setup</query>
108+
</codebase_search>
109+
```
110+
111+
**Good: Problem-oriented**
112+
```xml
113+
<codebase_search>
114+
<query>error handling for API requests</query>
115+
</codebase_search>
116+
```
117+
118+
**Less effective: Too generic**
119+
```xml
120+
<codebase_search>
121+
<query>function</query>
122+
</codebase_search>
123+
```
124+
125+
### Query Types That Work Well
126+
127+
- **Functional Descriptions**: "file upload processing", "email validation logic"
128+
- **Technical Patterns**: "singleton pattern implementation", "factory method usage"
129+
- **Domain Concepts**: "user profile management", "payment processing workflow"
130+
- **Architecture Components**: "middleware configuration", "database migration scripts"
131+
132+
## Directory Scoping
133+
134+
Use the optional `path` parameter to focus searches on specific parts of your codebase:
135+
136+
**Search within API modules:**
137+
```xml
138+
<codebase_search>
139+
<query>endpoint validation middleware</query>
140+
<path>src/api</path>
141+
</codebase_search>
142+
```
143+
144+
**Search in test files:**
145+
```xml
146+
<codebase_search>
147+
<query>mock data setup patterns</query>
148+
<path>tests</path>
149+
</codebase_search>
150+
```
151+
152+
**Search specific feature directories:**
153+
```xml
154+
<codebase_search>
155+
<query>component state management</query>
156+
<path>src/components/auth</path>
157+
</codebase_search>
158+
```
159+
160+
## Result Interpretation
161+
162+
### Similarity Scores
163+
164+
- **0.8-1.0**: Highly relevant matches, likely exactly what you're looking for
165+
- **0.6-0.8**: Good matches with strong conceptual similarity
166+
- **0.4-0.6**: Potentially relevant but may require review
167+
- **Below 0.4**: Filtered out as too dissimilar
168+
169+
### Result Structure
170+
171+
Each search result includes:
172+
- **File Path**: Workspace-relative path to the file containing the match
173+
- **Score**: Similarity score indicating relevance (0.4-1.0)
174+
- **Line Range**: Start and end line numbers for the code block
175+
- **Code Chunk**: The actual code content that matched your query
176+
177+
## Examples When Used
178+
179+
- When implementing a new feature, Roo searches for "authentication middleware" to understand existing patterns before writing new code.
180+
- When debugging an issue, Roo searches for "error handling in API calls" to find related error patterns across the codebase.
181+
- When refactoring code, Roo searches for "database transaction patterns" to ensure consistency across all database operations.
182+
- When onboarding to a new codebase, Roo searches for "configuration loading" to understand how the application bootstraps.
183+
184+
## Usage Examples
185+
186+
Searching for authentication-related code across the entire project:
187+
```xml
188+
<codebase_search>
189+
<query>user login and authentication logic</query>
190+
</codebase_search>
191+
```
192+
193+
Finding database-related code in a specific directory:
194+
```xml
195+
<codebase_search>
196+
<query>database connection and query execution</query>
197+
<path>src/data</path>
198+
</codebase_search>
199+
```
200+
201+
Looking for error handling patterns in API code:
202+
```xml
203+
<codebase_search>
204+
<query>HTTP error responses and exception handling</query>
205+
<path>src/api</path>
206+
</codebase_search>
207+
```
208+
209+
Searching for testing utilities and mock setups:
210+
```xml
211+
<codebase_search>
212+
<query>test setup and mock data creation</query>
213+
<path>tests</path>
214+
</codebase_search>
215+
```
216+
217+
Finding configuration and environment setup code:
218+
```xml
219+
<codebase_search>
220+
<query>environment variables and application configuration</query>
221+
</codebase_search>

docs/advanced-usage/available-tools/tool-use-overview.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Tools are organized into logical groups based on their functionality:
1010

1111
| Category | Purpose | Tools | Common Use |
1212
|----------|---------|-------|------------|
13-
| **Read Group** | File system reading and searching | [read_file](/advanced-usage/available-tools/read-file), [search_files](/advanced-usage/available-tools/search-files), [list_files](/advanced-usage/available-tools/list-files), [list_code_definition_names](/advanced-usage/available-tools/list-code-definition-names) | Code exploration and analysis |
13+
| **Read Group** | File system reading and exploration | [read_file](/advanced-usage/available-tools/read-file), [list_files](/advanced-usage/available-tools/list-files), [list_code_definition_names](/advanced-usage/available-tools/list-code-definition-names) | Code exploration and analysis |
14+
| **Search Group** | Pattern and semantic searching | [search_files](/advanced-usage/available-tools/search-files), [codebase_search](/advanced-usage/available-tools/codebase-search) | Finding code patterns and functionality |
1415
| **Edit Group** | File system modifications | [apply_diff](/advanced-usage/available-tools/apply-diff), [insert_content](/advanced-usage/available-tools/insert-content), [search_and_replace](/advanced-usage/available-tools/search-and-replace), [write_to_file](/advanced-usage/available-tools/write-to-file) | Code changes and file manipulation |
1516
| **Browser Group** | Web automation | [browser_action](/advanced-usage/available-tools/browser-action) | Web testing and interaction |
1617
| **Command Group** | System command execution | [execute_command](/advanced-usage/available-tools/execute-command) | Running scripts, building projects |
@@ -32,10 +33,15 @@ Certain tools are accessible regardless of the current mode:
3233
These tools help Roo understand your code and project:
3334

3435
- [read_file](/advanced-usage/available-tools/read-file) - Examines the contents of files
35-
- [search_files](/advanced-usage/available-tools/search-files) - Finds patterns across multiple files
3636
- [list_files](/advanced-usage/available-tools/list-files) - Maps your project's file structure
3737
- [list_code_definition_names](/advanced-usage/available-tools/list-code-definition-names) - Creates a structural map of your code
3838

39+
### Search Tools
40+
These tools help Roo find patterns and functionality across your codebase:
41+
42+
- [search_files](/advanced-usage/available-tools/search-files) - Finds patterns across multiple files using regex
43+
- [codebase_search](/advanced-usage/available-tools/codebase-search) - Performs semantic searches across your indexed codebase
44+
3945
### Edit Tools
4046
These tools help Roo make changes to your code:
4147

@@ -211,7 +217,7 @@ Tools are made available based on the current mode:
211217

212218
1. **Information Gathering**
213219
```
214-
[ask_followup_question](/advanced-usage/available-tools/ask-followup-question) → [read_file](/advanced-usage/available-tools/read-file) → [search_files](/advanced-usage/available-tools/search-files)
220+
[ask_followup_question](/advanced-usage/available-tools/ask-followup-question) → [read_file](/advanced-usage/available-tools/read-file) → [codebase_search](/advanced-usage/available-tools/codebase-search)
215221
```
216222

217223
2. **Code Modification**

docs/faq.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ Yes, if you use a [local model](/advanced-usage/local-models).
136136

137137
Yes, you can create your own MCP servers to add custom functionality to Roo Code. See the [MCP documentation](https://github.com/modelcontextprotocol) for details.
138138

139+
### What is Codebase Indexing?
140+
141+
[Codebase Indexing](/features/experimental/codebase-indexing) is an experimental feature that creates a semantic search index of your project using AI embeddings. This enables Roo Code to better understand and navigate large codebases by finding relevant code based on meaning rather than just keywords.
142+
143+
### How much does Codebase Indexing cost?
144+
145+
Codebase Indexing requires an OpenAI API key for generating embeddings and a Qdrant vector database for storage. Costs depend on your project size and the embedding model used. Initial indexing is the most expensive part; subsequent updates are incremental and much cheaper.
146+
139147
## Troubleshooting
140148

141149
### Roo Code isn't responding. What should I do?
@@ -148,7 +156,7 @@ Yes, you can create your own MCP servers to add custom functionality to Roo Code
148156

149157
### I'm seeing an error message. What does it mean?
150158

151-
The error message should provide some information about the problem. If you're unsure how to resolve it, seek help in the community forums.
159+
The error message should provide some information about the problem. If you're unsure how to resolve it, seek help in [Discord](https://discord.gg/roocode).
152160

153161
### Roo Code made changes I didn't want. How do I undo them?
154162

0 commit comments

Comments
 (0)