Semantic code search
- Tier: Premium, Ultimate
- Add-on: GitLab Duo Core, Pro, or Enterprise
- Offering: GitLab.com, GitLab Self-Managed
- Status: Beta
For administrator documentation, see semantic code search administration.
Use semantic code search to find relevant code snippets in your repository based on meaning rather than keyword matching.
Semantic code search converts your codebase into vector embeddings stored in a vector database. When you search, your query is converted into an embedding and compared against your code embeddings to find semantically similar results. This approach finds relevant code even when keywords do not match.
Prerequisites
- On GitLab Self-Managed, have semantic code search turned on for the instance. On GitLab.com, semantic code search is turned on by default.
- Have beta and experimental features turned on:
- On GitLab.com, for the top-level group.
- On GitLab Self-Managed, for the instance.
- Have GitLab Duo turned on for the project.
Use semantic code search
Semantic code search is available through multiple interfaces:
- REST API: Use the
GET /api/v4/projects/:id/search/semanticendpoint to search your codebase programmatically. - MCP server tool: Use the
semantic_code_searchtool in agentic workflows. - CLI: Use the
glab search semanticcommand for command-line access.
Ad-hoc initial indexing
When you first use semantic code search in a GitLab project:
- Your repository code is indexed and converted into vector embeddings.
- These embeddings are stored in your configured vector store.
- Updates are processed incrementally when code is pushed to the default branch.
Initial indexing can take time for large repositories.