MCP semantic_code_search: Update handling for no code embeddings
What does this MR do and why?
As part of &19655, we are going to implement ad-hoc embeddings indexing of projects. With ad-hoc indexing, we are not immediately indexing Code Embeddings for all eligible projects. Instead, we will perform Code Embeddings indexing for a project on the first time a semantic code search is triggered on the project.
In this MR, we update the semantic code search process to handle the different "no code embeddings" scenarios:
Note: "no code embeddings" mean that the project has no Ai::ActiveContext::Code::Repository OR its state != ready.
- If
Ai::ActiveContext::Code::Repositoryrecord does not exist for a project:- trigger the
AdHocIndexingWorker(introduced in #577330 (closed)) - return a message indicating that the embeddings initial indexing has just started
- trigger the
- If
Ai::ActiveContext::Code::Repositoryexists withstate=failed- return a message indicating that the embeddings indexing failed
- If
Ai::ActiveContext::Code::Repositoryexists withstateNOTreadyorfailed- return a message indicating that the embeddings initial indexing is still ongoing
References
- Related Issue: [Code Embeddings Query] Trigger ad-hoc indexing... (#576633 - closed)
- Issue introducing the
AdHocIndexingWorker: [Code Embeddings] Create AdHocIndexingWorker (#577330 - closed)
Screenshots or screen recordings
Scenario: project has NO code embeddings
How to set up and validate locally
Prerequisites
- Setup MCP server on your GDK
- Setup the Code Embeddings Indexing pipeline on your GDK
Testing
Test the semantic_code_search tool using MCP Inspector or your preferred client for MCP testing.
-
For a project with code embeddings, the tool should return results successfully
Setup note: you can set up this project by following Prerequisites Step 2
-
For a project with NO code embeddings but eligible for it:
- an
Ai::ActiveContext::Code::Repositoryrecord should be created for the project - the record should have a
stateofcode_indexing_in_progressorembedding_indexing_in_progress(the record is initially created withstate=pending, but since the ad-hoc indexing is kicked off, the indexing process should have started by the time you are checking
Setup note: this should be any project under the
gitlab-duonamespace without anAi::ActiveContext::Code::Repositoryrecord - an
-
For a project with
Ai::ActiveContext::Code::Repositoryrecord withstate=failed- the tool should error with a message indicating that the indexing failed
Setup note: you can set up this project by following Prerequisites Step 2, then updating the project's
Ai::ActiveContext::Code::Repositoryrecord tostate=failed -
For a project with
Ai::ActiveContext::Code::Repositoryrecord withstateNOTreadyorfailed- the tool should error with a message indicating that initial indexing is still ongoing
Setup note: you can set up this project by following Prerequisites Step 2, then updating the project's
Ai::ActiveContext::Code::Repositoryrecord tocode_indexing_in_progress=failed
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 #576633 (closed)


