[SemanticCodeSearch MCP tool] Handle projects without code embeddings
Context
As part of &19655, we are going to implement ad-hoc embeddings indexing of projects.
With ad-hoc indexing, it's possible that a user asks a question about a project, Agentic Chat triggers the SemanticCodeSearch tool, and it turns out that a project does not have code embeddings yet. In this scenario we need to:
- Check whether the
Ai::ActiveContext::Code::Repository
project exists - If it does not exist
- trigger the
AdHocIndexingWorker
(addressed in a different issue since this has a dependency) - return a response that the record does not exist yet
- trigger the
Proposal
-
Update the
Ai::ActiveContext::Queries::Code
to check whether the given project has aAi::ActiveContext::Code::Repository
record -
If the record does not exist, indicate in the return value that the project has no code embeddings (alternatively, raise an error)
-
In
Mcp::Tools::SearchCodebaseService
, support the "project does not have code embeddings yet" response. Proposed response:-
formatted_content
(the unstructured response): Text saying that the project does not have code embeddings yet -
structured_response
, we can have something like:{ "items": [], "system_instruction": "The project does not have code embeddings yet. Please use another tool." }
See this issue for an example on structured json content.
-