doc/administration/semantic_code_search.md
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
[!note] For user documentation, see semantic code search.
With semantic code search, AI-native GitLab Duo features can find relevant code snippets in your repository.
pgvector extension.You should use Elasticsearch or OpenSearch for medium to large repositories.
Use PostgreSQL with pgvector only for setups with a few small repositories.
Indexing and querying performance might be limited with pgvector.
{{< history >}}
{{< /history >}}
If your GitLab instance uses Elasticsearch or OpenSearch for advanced search, you can turn on semantic code search by connecting to the same cluster:
{{< history >}}
{{< /history >}}
To configure a custom vector store connection:
| Setting | Description |
|---|---|
| URL | Comma-separated list of URLs for your Elasticsearch cluster (for example, http://localhost:9200, http://localhost:9201). |
| Username | Username of password-protected Elasticsearch servers. |
| Password | Password of password-protected Elasticsearch servers. |
| Setting | Description |
|---|---|
| URL | Comma-separated list of URLs for your OpenSearch cluster (for example, http://localhost:9200, http://localhost:9201). |
| Username | Username of password-protected OpenSearch servers. |
| Password | Password of password-protected OpenSearch servers. |
To use AWS OpenSearch Service, select Use AWS OpenSearch Service with IAM credentials and complete the fields:
| Setting | Description |
|---|---|
| AWS region | AWS region of your OpenSearch domain. |
| AWS Access Key | AWS access key ID. Required only if you're not using role instance credentials. |
| AWS Secret Access Key | AWS secret access key. Required only if you're not using role instance credentials. |
| AWS Role ARN | AWS IAM role ARN of AssumeRole authorization across accounts. |
pgvectorPrerequisites:
Enable the pgvector extension in your PostgreSQL database:
CREATE EXTENSION vector;
| Setting | Description |
|---|---|
| Host | Host name of the PostgreSQL server. |
| Port | Port of the PostgreSQL server. Default is 5432. |
| Database | Name of the PostgreSQL database. |
| Username | PostgreSQL username. |
| Password | PostgreSQL password. |
To configure an embedding model:
[!warning] When you change the embedding model or dimensions, a backfill runs that can take several hours depending on your codebase size. Semantic search remains available during this process.
{{< history >}}
semantic_search_user_model_selection. Disabled by default.{{< /history >}}
[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.
Prerequisites:
GitLab-managed models are offered on the GitLab AI Gateway.
Select the text-embedding-005 model provided by the Gemini Enterprise Agent Platform.
For more information about GitLab-managed models with a GitLab Duo Self-Hosted setup, see hybrid AI Gateway and model configuration.
[!warning] If GitLab deprecates a model you selected, you must switch to a different model yourself.
{{< history >}}
semantic_search_user_model_selection. Disabled by default.{{< /history >}}
[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.
Prerequisites:
Self-hosted models are AI models hosted on your own infrastructure.
To select a self-hosted model:
EMBEDDING model family.{{< history >}}
semantic_search_user_model_selection. Disabled by default.{{< /history >}}
[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.
The chunking strategy is the algorithm used to split code files into smaller snippets for embeddings. Select one of the following strategies:
[!warning] You can select the chunking strategy only when you configure the embedding model for the first time. To change the chunking strategy after indexing starts, you must fully reindex the instance. Support for automatic reindexing is proposed in issue 600200 and issue 602138.
{{< history >}}
{{< /history >}}
To check the status of semantic code search, including indexing status, vector store connection details, repository statistics, and embedding queue sizes, run this Rake task:
sudo gitlab-rake gitlab:semantic_search:code:info
To monitor status continuously, provide a watch interval in seconds:
sudo gitlab-rake "gitlab:semantic_search:code:info[5]"
This task refreshes the output at the specified interval. To stop the task, press <kbd>Control</kbd>+<kbd>C</kbd>.
Prerequisites:
admin_mode, ai_features, and api scopes.When embedding generation fails repeatedly, items are moved to the dead queue for manual intervention.
You can check the dead queue size in the Embedding Queues section of the
status Rake task output.
To delete all items from the dead queue, run this command:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_token>" \
"https://gitlab.example.com/api/v4/admin/active_context/dead_queue"
To move dead queue items back into a processing queue for another attempt,
use the queue parameter to specify the target.
Valid values are retry_queue, code, and code_backfill.
To attempt processing once more before potentially failing back to the dead queue,
use retry_queue:
curl --request POST \
--header "PRIVATE-TOKEN: <your_token>" \
--data "queue=retry_queue" \
"https://gitlab.example.com/api/v4/admin/active_context/dead_queue/replay"
To add items to the main code queue, use code:
curl --request POST \
--header "PRIVATE-TOKEN: <your_token>" \
--data "queue=code" \
"https://gitlab.example.com/api/v4/admin/active_context/dead_queue/replay"