A web application that converts natural language queries into Sourcegraph code search queries using Deep Search API.
- 🔍 Natural language to search query translation
- 🌐 Clean, modern web interface
- ⚡ Real-time Deep Search API integration
- 🎯 Example queries to get started quickly
- 📊 Source attribution for search results
- Go 1.23 or higher
- A Sourcegraph access token
- Access to a Sourcegraph instance (default: sourcegraph.com)
-
Clone or navigate to the project:
cd nlsearch -
Set up environment variables:
cp .env.example .env # Edit .env and add your Sourcegraph token -
Run the application:
./run.sh
-
Open your browser: Navigate to
http://localhost:8080
Configure the app using environment variables:
| Variable | Description | Default |
|---|---|---|
SOURCEGRAPH_TOKEN |
Your Sourcegraph access token | Required |
SOURCEGRAPH_URL |
Sourcegraph instance URL | https://sourcegraph.com |
PORT |
Server port | 8080 |
- Go to your Sourcegraph instance (e.g., https://sourcegraph.com)
- Navigate to Settings → Access tokens
- Click "Generate new token"
- Give it a name (e.g., "NLSearch App")
- Copy the token and use it in your configuration
- Type your natural language query in the search box
- Click "Search" or press Enter
- Wait for the Deep Search API to process your query
- View the answer and sources
- "all repos which have python files"
- "find all TypeScript interfaces in the frontend"
- "show me error handling patterns in Go code"
- "repositories using React hooks"
nlsearch/
├── backend/
│ ├── main.go # Go backend server with API endpoints
│ └── go.mod # Go module definition
├── frontend/
│ └── index.html # Web UI (HTML/CSS/JS)
├── .env.example # Example environment variables
└── README.md # This file
Submit a natural language query.
Request:
{
"query": "all repos which have python files"
}Response:
{
"answer": "Here are the repositories...",
"sources": [
{
"type": "Repository",
"label": "github.com/example/repo"
}
]
}Health check endpoint.
- User submits a natural language query via the web UI
- Frontend sends the query to the backend API
- Backend creates a Deep Search conversation with the Sourcegraph API
- Backend polls for completion (up to 60 seconds)
- Result is returned to the frontend and displayed
The backend serves both the API and the frontend static files. Any changes to the frontend HTML will be reflected immediately on refresh.
For backend changes, restart the Go server:
cd backend
go run main.gocd backend
go build -o nlsearch-server main.goThen run:
SOURCEGRAPH_TOKEN=your_token ./nlsearch-server"SOURCEGRAPH_TOKEN environment variable is required"
- Make sure you've set the
SOURCEGRAPH_TOKENenvironment variable
"Failed to create conversation: unexpected status 401"
- Your access token is invalid or expired
- Generate a new token from your Sourcegraph instance
"timeout waiting for response"
- The Deep Search query is taking too long
- Try a simpler query
- The timeout is currently set to 60 seconds
"Network error"
- Check your internet connection
- Verify the
SOURCEGRAPH_URLis correct - Ensure the Sourcegraph instance is accessible
MIT License - feel free to use and modify as needed.
Contributions are welcome! Feel free to submit issues or pull requests.