Needle
Needle is an AI-powered Visual Studio Code extension that helps you find the proverbial "needle in a haystack" within your codebase. With Needle, developers can search their code using queries like "Where do we validate user inputs?" and quickly uncover relevant, ranked results.
Features
- Semantic Search: Use natural language to search your codebase.
- Content-Aware Results: Search results understand code context including classes, methods, and hierarchies.
- Intelligent Filtering: Include or exclude files using glob patterns to narrow your search.
- Real-time Indexing: Auto-indexes your workspace and updates embeddings when files change.
- Seamless Code Navigation: Click on search results to jump directly to relevant code.
Requirements
- Visual Studio Code 1.98.0 or higher
- Python 3.6+
- An OpenAI API key (for embedding generation)
Installation
- Install the extension from the VS Code Marketplace.
- Open your project in VS Code.
- Click on the Needle icon in the Activity Bar.
- Enter your OpenAI API key when prompted.
Usage
- Click the Needle icon in the Activity Bar to open the search sidebar.
- Type a natural language query in the search box (e.g., "How is authentication implemented?").
- Optionally, provide include/exclude patterns to filter by file types or paths.
- Press Enter or click Search to perform the search.
- Click on any search result to open the corresponding file at the relevant location.
Commands
The extension provides the following commands:
Needle: Smart Find
- Launch the semantic search interface (Ctrl+Shift+P, then type "Needle: Smart Find")
Needle: Set OpenAI API Key
- Configure your OpenAI API key
Needle: Clear OpenAI API Key
- Remove your stored API key
Needle: Regenerate Embeddings Cache
- Force a re-indexing of your workspace
Configuration
Currently, Needle supports the following configuration in your VS Code settings, typically you configure this through the UI prompts though:
{
"needle.openaiApiKey": "your-api-key-here"
}
The API key can also be provided through the NEEDLE_OPENAI_API_KEY
environment variable.
How It Works
Needle uses AI embeddings to understand your code semantically:
- It indexes your workspace by analyzing code structure using VS Code's DocumentSymbol API
- Each code chunk is embedded using OpenAI's text-embedding-3-small model
- Embeddings are stored in a local ChromaDB vector database
- When you search, your query is embedded and matched against the code embeddings
- Results are ranked by semantic similarity to your query
Development
Prerequisites
- Node.js 16+
- npm
- Python 3.6+
Setup
- Clone the repository.
- Install dependencies:
npm install
- Start the development server:
npm run watch
- Press F5 to launch the extension in a new VS Code window.
Python Dependencies
The extension uses the following Python packages:
- fastapi
- uvicorn
- openai
- chromadb
These will be automatically installed in a virtual environment when the extension is first run.
Contributing
Contributions are welcome! Please read the CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License. See the LICENSE file for details.