AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How Sourcegraph Cody Indexes and Queries Multi-Repository Codebases

Sohn Yong-il · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Most AI coding assistants crumble the moment your architecture leaves a single local folder. If your engineering organization lives across forty microservices, shared private SDKs, and a legacy monolith, pointing an LLM at an open file in VS Code produces little more than plausible-sounding hallucinations. It does not know that the authentication header changed in a shared middleware repo yesterday, or that the payload format is enforced by a protobuf schema in another repository entirely.

At 365Finds, we evaluate developer tools by how they survive enterprise reality, not how smoothly they complete a toy Python script. Sourcegraph Cody handles multi-repository private codebases fundamentally differently from competitors who rely purely on naive vector databases.

Instead of treating code as generic text to be chopped into vector embeddings, Sourcegraph Cody sits atop Sourcegraph's core enterprise platform—marrying exact trigram search, deterministic compiler-grade code graphs, and scoped semantic retrieval. Here is how that indexing and query pipeline actually operates, how to configure it across distributed repositories, and where its technical boundaries lie.


1. The Core Architecture: Why Pure Vector RAG Fails Code

To understand how Sourcegraph Cody works, you have to understand why standard Retrieval-Augmented Generation (RAG) fails at enterprise code scale.

Typical developer AI tools take a codebase, split files into arbitrary chunks (such as 300 to 500 tokens), generate numerical vector embeddings, and store them in a vector database like pgvector or Pinecone. When you ask a question, the tool runs a cosine similarity search against those vectors.

In production engineering, this breaks constantly:

  1. Syntax blindness: Code is structured, hierarchical, and brittle. A missing comma or an unimported struct invalidates logic. Chunking splits function signatures from their implementations.
  2. Boilerplate collisions: Files named handler.go, index.ts, or config.yaml share semantic similarity across dozens of microservices, polluting vector results with completely irrelevant services.
  3. Synchronization lag: Re-indexing millions of lines of code into high-dimensional vectors on every pull request is prohibitively expensive and slow.

Sourcegraph Cody rejects pure vector retrieval for codebase intelligence. 365Finds strongly endorses this architectural decision: code retrieval must prioritize deterministic exact matches and structural dependencies over fuzzy semantic guesswork.


2. How Cody Indexes Private Codebases Across Multiple Repositories

When deployed in an enterprise environment, Sourcegraph Cody draws on three distinct indexing mechanisms hosted on your Sourcegraph instance:

[ Code Hosts: GitHub / GitLab / Bitbucket ]
                   │
                   ▼ (gitserver sync & webhooks)
       [ Sourcegraph Enterprise Instance ]
        ├── 1. Zoekt (Trigram Text & Symbol Search)
        ├── 2. SCIP (Precise Definition & Reference Graph)
        └── 3. Vector Embeddings (Semantic Search Fallback)
                   ▲
                   │ GraphQL / Search API (Permission-Aware)
                   │
         [ Cody Client: VS Code / JetBrains ]
                   │ (Includes local uncommitted diffs & buffer via symf)
                   ▼
         [ LLM Prompt Context Assembly ]

A. Zoekt: Trigram Inverted Indexing for Sub-50ms Exact Search

The operational backbone of Sourcegraph Cody is Zoekt, an open-source search engine optimized specifically for source code.

B. SCIP: Deterministic Definition and Reference Graphs

Exact keyword search finds where a string appears, but it cannot know whether an imported interface in Repo A resolves to the implementation in Repo B. That requires SCIP (Source Code Intelligence Protocol), Sourcegraph's evolution of Microsoft's LSIF.

C. Selective Embeddings and Local symf

Semantic search still has a role when developers ask conceptual questions like "where do we handle credit card webhooks?" without knowing the function names.


3. How Multi-Repository Querying Works in Practice

When an engineer opens Cody in VS Code, JetBrains, or Cody Web and submits a prompt, Cody executes a multi-stage retrieval pipeline:

Step 1: Intent Extraction and Query Rewriting

Cody does not simply dump your natural language prompt into an LLM. It parses the intent, identifies potential symbol names, file paths, and error codes, and synthesizes explicit search queries for the Sourcegraph Search API.

Step 2: Multi-Repository Context Targeting via @-Mentions

In multi-repository setups, developers have two retrieval paths:

  1. Explicit @-Mentions: You can type @ in the Cody chat window and select Remote Repositories. Cody allows you to explicitly pin up to 10 remote repositories into a single conversation. For example:
    @repo:org/api-gateway @repo:org/auth-service @repo:org/proto-schemas
    How does the gateway validate user session JWTs against auth-service?
    
  2. Implicit Workspace Search: If configured by enterprise administrators, Cody automatically searches across indexed repositories associated with the project's workspace context.

Step 3: Hybrid Retrieval and Cross-Repo Stitching

The Sourcegraph backend executes concurrent queries across the targeted repositories:

Step 4: Token Budgeting and Re-Ranking

LLM context windows—even 128k or 200k tokens in models like Claude 3.5 Sonnet or GPT-4o—degrade in accuracy if overloaded with noise. Cody applies an aggressive token budget:


4. Enterprise Security and Permission Boundaries

For regulated industries and large enterprises, querying code across hundreds of repositories introduces serious data leakage risks. Sourcegraph Cody enforces three strict governance layers:

Governance LayerMechanismPractical Impact
Code Host ACL SyncSourcegraph mirrors permissions from GitHub, GitLab, and Bitbucket.A developer querying Cody will never receive snippets or answers derived from a repository they cannot access on the code host.
Cody Context FiltersSite admin configuration (cody.contextFilters).Administrators use RE2 regex to include or exclude specific repositories or paths from ever being sent to LLMs.
Zero-Retention LLM RoutingCommercial LLM agreements or self-hosted models.Enterprise contracts ensure model providers (Anthropic, OpenAI) do not train on context data; air-gapped environments can route to on-prem models via AWS Bedrock, Azure OpenAI, or Ollama.

To enforce context filters, Sourcegraph administrators configure the site configuration:

{
  "cody.contextFilters": {
    "include": [
      { "repoName": "^github\\.com/my-org/.*" }
    ],
    "exclude": [
      { "repoName": "^github\\.com/my-org/payment-secrets.*" },
      { "repoName": "^github\\.com/my-org/legal-compliance.*" }
    ]
  }
}

5. Technical Limits and Operational Realities

365Finds insists on evaluating tools with clear eyes about their friction points. While Sourcegraph Cody's multi-repo architecture is technically superior to generic vector-based AI assistants, teams must plan for several practical boundaries:

  1. The 10-Repository Chat Ceiling: Manual @-mentions cap at 10 remote repositories per chat session. If your system involves fifty distributed services, Cody cannot ingest the entire cluster blindly in one prompt. You must know which architectural boundaries matter to your query.
  2. Default Branch vs. Branch Lag: Zoekt indexes your default branch (usually main) by default. Unless your Sourcegraph administrators explicitly configure branch indexing, queries across remote repositories will reflect the merged main state, not an unmerged feature branch opened an hour ago. Local uncommitted changes are only captured in the developer's immediate active editor via symf and local buffer state.
  3. Infrastructure Resource Overhead: Zoekt shards live in RAM via mmap. A company with 20,000 repositories or a 50GB monorepo must provision substantial memory and CPU for zoekt-indexserver and gitserver. Running compiler-precise SCIP across millions of lines also requires dedicated CI compute runners. If an engineering team under-provisions their Sourcegraph instance, Cody's multi-repo retrieval will bottleneck on query latency.

6. The 365Finds Verdict

If your codebase is a single standalone Next.js application, Sourcegraph Cody is overkill; simpler tools like GitHub Copilot or Cursor will satisfy your needs with less administrative friction.

However, if your organization operates across dozens of private repositories, microservices, or complex polyrepos where type definitions live in one place and implementations live in another, 365Finds considers Sourcegraph Cody's hybrid indexing model—anchored by Zoekt's sub-50ms trigram engine and SCIP's deterministic code graph—the most technically coherent architecture on the market. It treats code as a formal dependency graph rather than prose, and that distinction makes all the difference when answers must compile.

References