Skip to content

[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:

  1. Check whether the Ai::ActiveContext::Code::Repository project exists
  2. 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

Proposal

  1. Update the Ai::ActiveContext::Queries::Code to check whether the given project has a Ai::ActiveContext::Code::Repository record

  2. If the record does not exist, indicate in the return value that the project has no code embeddings (alternatively, raise an error)

  3. 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.

Edited by Pam Artiaga