Bocha Search Server
Relevant source files
The following files were used as context for generating this wiki page:
The Bocha Search Server (integrated within the broader DeepCode search and indexing infrastructure) is a component of the Model Context Protocol (MCP) ecosystem designed to provide advanced search capabilities for research paper reproduction and code implementation. Its primary purpose is to facilitate the retrieval of high-relevance algorithmic details, conceptual frameworks, and code implementation patterns from external repositories and internal document segments.
Within the DeepCode project, this search functionality is orchestrated by specialized agents that interact with various MCP servers to bridge the gap between academic research papers and production-ready code. It operates alongside the Document Segmentation Server and the Code Reference Indexer to ensure that the LLM has access to the most technically accurate context for code generation.
Sources: tools/document_segmentation_server.py:1-40, prompts/code_prompts.py:1-20, ui/components.py:180-210
Architecture and Integration
The search infrastructure follows a multi-agent orchestration pattern where a central agent coordinates with specific MCP servers to execute search and retrieval tasks. The system utilizes semantic vector embeddings combined with graph-based dependency analysis to rank search results.
System Workflow
The following diagram illustrates how search and indexing are integrated into the overall CodeRAG (Retrieval-Augmented Generation) system.
The system combines semantic analysis with dependency graph mapping to provide context-aware results to the generation engine.
Sources: ui/components.py:230-265, workflows/code_implementation_workflow_index.py:155-180
Key Components and Logic
1. Model Context Protocol (MCP) Integration
The search server functions as an MCP server, providing tools that the DeepCode agents call using a standardized JSON-RPC based protocol. This allows the implementation agents to query external and internal data sources without having to manage raw file I/O or network requests directly.
| Component | Responsibility | Relevant Files |
|---|---|---|
| FastMCP Server | Hosts tools like search_code_references and read_document_segments. | tools/code_reference_indexer.py:27, tools/document_segmentation_server.py:80 |
| MCP Client | Managed by the Agent class to connect to search servers. | workflows/code_implementation_workflow_index.py:228-250 |
| Tool Definition | Defines schemas for input parameters like keywords and max_results. | config/mcp_tool_definitions_index.py, tools/code_reference_indexer.py:240-250 |
Sources: tools/code_reference_indexer.py:24-30, workflows/code_implementation_workflow_index.py:228-250
2. Semantic Search and Scoring
Search results are prioritized using a weighted scoring system. For document segments, the system calculates relevance based on the query type (e.g., "algorithm_extraction" or "concept_analysis"). For code references, the system uses file name similarity, type matching, and keyword density.
The scoring engine ensures that technical content such as mathematical formulations and algorithm blocks receive higher priority during retrieval.
Sources: tools/document_segmentation_server.py:590-630, tools/code_reference_indexer.py:113-146
3. Code Reference Indexing
The system provides a specialized tool, search_code_references, which searches through an indexes directory containing JSON summaries of related GitHub repositories. This allows implementation agents to find patterns from existing codebases to guide the reproduction of the target paper.
Search Logic Details:
- Target File Matching: Normalizes paths (e.g., removing
src/orcore/prefixes) to find direct relationships between reference code and the implementation plan. - Confidence Scoring: Assigns a score based on the "relationship type" (e.g.,
direct_match= 1.0,utility= 0.4). - Suggestion Generation: Automatically extracts "helpful aspects" and "usage suggestions" from the index metadata.
Sources: tools/code_reference_indexer.py:239-285, workflows/codebase_index_workflow.py:350-380
Search Parameters and Configurations
The following table summarizes the configurable parameters used by the search tools within the MCP servers:
| Parameter | Type | Default | Description |
|---|---|---|---|
max_results | Integer | 10 | The maximum number of relevant code references or segments to return. |
keywords | List/String | None | Specific terms used to filter content (e.g., "GCN", "diffusion", "loss"). |
query_type | String | "general" | The context of the search: "concept_analysis", "algorithm_extraction", or "code_planning". |
max_total_chars | Integer | 6000 | The character limit for returned content to prevent exceeding LLM token limits. |
min_confidence | Float | 0.3 | The minimum score required for a relationship to be included in results. |
Sources: tools/document_segmentation_server.py:515-535, tools/code_reference_indexer.py:240-250, workflows/codebase_index_workflow.py:380-410
Interaction Flow
When an Implementation Agent requires reference data, it follows a specific sequence of tool calls to the search and indexing servers.
This flow ensures that the agent first understands the document's structure before attempting to find implementation patterns from the indexed codebases.
Sources: workflows/code_implementation_workflow_index.py:160-200, tools/document_segmentation_server.py:465-480, prompts/code_prompts.py:480-510
Summary
The Bocha Search Server (implemented via the Code Reference Indexer and Document Segmentation Server MCP tools) is critical for DeepCode's ability to reproduce complex research. By providing intelligent, segmented, and ranked access to both the target paper's content and existing reference codebases, it enables specialized agents to implement production-ready code while maintaining mathematical and architectural integrity.
Sources: tools/document_segmentation_server.py:1-35, ui/components.py:230-245