SemanticCodeSearch: Handle scenario where project has no code embeddings
What does this MR do and why?
In Agentic Chat that is connected to the GitLab MCP Server, it is possible that the semantic_code_search tool will get invoked for a project that does not have any code embeddings yet. When this happens, we need the tool to give a response that reflects the situation, ie: "project has no code embeddings" instead of "no search results found".
Note:
In future MRs, we will improve the messaging along with different states for code embeddings (not available at all, indexing in progress, etc) to give the Duo Agent better instructions.
The purpose of submitting this first MR is to unblock work around what needs to be done if a project does not have embeddings, specifically to trigger embeddings indexing for that project if eligible. Please refer to the related issue and ad-hoc indexing epic for more details.
References
Issue: [SemanticCodeSearch MCP tool] Handle projects w... (#576632 - closed)
Screenshots or screen recordings
Note: these are all tested on the same project (a local copy of the GitLab repo), but with the embeddings indexing state toggled between ready and failed. Any state that is not ready is considered as no embeddings.
Agentic Chat
MCP tool result - expand for screenshots
| Project with Code Embeddings | Project without Code Embeddings | 
|---|---|
|  |  | 
Actual usage in Agentic Chat - expand for screen recordings
| Project with Code Embeddings | Project without Code Embeddings | 
|---|---|
| In this scenario, Duo Agent keeps invoking the semantic_code_searchtool to get more detailed results | In this scenario, Duo Agent invokes the semantic_code_searchtool only once. Afterwards, it only uses other tools. | 
| agentic_chat_with_embeddings | agentic_chat_no_embeddings | 
Classic Duo Chat
Note: this is an additional testing since we are making a change in the CodebaseSearch tool for Classic Chat as well.
Classic Duo Chat usage - expand for screen recordings
| Project with Code Embeddings | Project without Code Embeddings | 
|---|---|
| classic_chat_with_embeddings | classic_chat_no_embeddings | 
Logs - payload sent to AIGW from Rails for projects without Code Embeddings
Logs
{"severity":"INFO","time":"2025-10-16T03:22:06.725Z","correlation_id":"01K7NGKX8NVYAP49B8WS80RPGA","meta.caller_id":"Llm::CompletionWorker","meta.feature_category":"ai_abstraction_layer","meta.organization_id":1,"meta.remote_ip":"172.16.123.1","meta.http_router_rule_action":"proxy","meta.user":"root","meta.user_id":1,"meta.client_id":"user/1","meta.root_caller_id":"GraphqlController#execute","params":{"messages":[{"role":"user","content":"What worker or event should I hook into to add processing for newly created projects?","context":null,"current_file":null,
# additional context array
"additional_context":[{
  "id":"gid://gitlab/Project/75",
  "category":"repository",
  # showing the content
  "content":"
Name: Gitlab
Path: gitlab-duo/gitlab
Description: GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a container, or on a cloud provider.
A semantic search was performed on the repository, but there was an error:
Project with ID 75 has no Code Embeddings.
",
# end content
  "metadata":{"enabled":true,"disabledReasons":[],"subType":"repository","subTypeLabel":"Repository","icon":"project","title":"Gitlab","secondaryText":"gitlab-duo/gitlab","webUrl":"http://gdk.test:3000/gitlab-duo/gitlab","name":"Gitlab","pathWithNamespace":"gitlab-duo/gitlab","description":"GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a container, or on a cloud provider."}
}]
# end additional context array
}],"model_metadata":null,"unavailable_resources":["Pipelines","Vulnerabilities"]},"message":"Request to v2/chat/agent","class":"Gitlab::Duo::Chat::StepExecutor","ai_event_name":"performing_request","ai_component":"duo_chat"}How to set up and validate locally
- 
Setup the GitLab MCP Server on your GDK 
- 
Connect to the server with the following configuration: - 
Transport Type: stdio
- 
Command: npx
- 
Arguments: # note: use --allow-http if your GDK is not enabled for https npx mcp-remote@latest <your-gdk-root-url>/api/v4/mcp --static-oauth-client-metadata '{"scope": "mcp"}' --allow-http
- 
Set environment variable: NODE_TLS_REJECT_UNAUTHORIZED=0
 
- 
- 
If you have trouble with authentication, try authenticating mcp-remote before running MCP Inspector 
- 
On MCP Inspector, click "List Tools" 
- 
In the list of tools, select semantic_code_search
- 
Invoke semantic_code_searchwith any project that does not have code embeddings
- 
You should get an error response with the appropriate message 
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #576632 (closed)