正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

Semantic code search

  • Tier: Premium, Ultimate
  • Add-on: GitLab Duo Core, Pro, or Enterprise
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
  • Status: Beta

Semantic code search uses AI to find relevant code snippets in your repository based on meaning rather than keyword matching.

Semantic code search converts your codebase into vector embeddings and stores these embeddings in a vector database. Your search query is also converted into an embedding and then compared against your code embeddings to find the most semantically similar results. This approach finds relevant code even when keywords do not match.

Improvements to this feature are proposed in epic 18018 and epic 20110.

Prerequisites

  • Have one of these configured:
  • Have these features turned on:
    • For GitLab.com, experiment features for your top-level namespace.
    • For GitLab Self-Managed, GitLab Duo experiment and beta features for the instance.
  • Have GitLab Duo turned on for your project.
  • Have a supported vector store configured:
    • Elasticsearch 8.0 and later.
    • OpenSearch 2.0 and later.

With the UI

If your GitLab instance uses Elasticsearch or OpenSearch for advanced search, you can enable semantic code search by connecting to the same cluster:

  1. In the upper-right corner, select Admin.
  2. Select Settings > Search.
  3. Expand Semantic search.
  4. Select Connect to the advanced search cluster.

With the Rails console

To create a custom vector store connection for Elasticsearch or OpenSearch, in the Rails console, create a connection with adapter and options.

Elasticsearch

connection = Ai::ActiveContext::Connection.create!(
  name: "elasticsearch",
  options: { url: ["http://your-elasticsearch-url:9200"] },
  adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter"
)
connection.activate!

Connection options:

OptionTypeRequiredDefaultDescription
urlarray of stringsYesNoneArray of URLs for your Elasticsearch cluster (for example, ["http://localhost:9200"]).
client_adapterstringNotyphoeusHTTP adapter to use. Possible values are typhoeus and net_http.
client_request_timeoutintegerNo30Request timeout in seconds.
retry_on_failureintegerNo0Number of retries on failure.
debugbooleanNofalseEnables debug logging.

OpenSearch

connection = Ai::ActiveContext::Connection.create!(
  name: "opensearch",
  options: { url: ["http://your-opensearch-url:9200"] },
  adapter_class: "ActiveContext::Databases::Opensearch::Adapter"
)
connection.activate!

Connection options:

OptionTypeRequiredDefaultDescription
urlarray of stringsYesNoneArray of URLs for your OpenSearch cluster (for example, ["http://localhost:9200"]).
client_adapterstringNotyphoeusHTTP adapter to use. Possible values are typhoeus and net_http.
client_request_timeoutintegerNo30Request timeout in seconds.
retry_on_failureintegerNo0Number of retries on failure.
debugbooleanNofalseEnables debug logging.
awsbooleanNofalseEnables AWS Signature Version 4 signing.
aws_regionstringNoNoneAWS region for your OpenSearch domain.
aws_access_keystringNoNoneAWS access key ID.
aws_secret_access_keystringNoNoneAWS secret access key.

Semantic code search is available as a GitLab MCP server tool. For more information about how to use this tool, see semantic_code_search.

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 merged to the default branch.

Initial indexing might take a few minutes depending on your repository size.