Most AI coding assistants crumble the moment your architecture outgrows a single repository. If your application frontend consumes an internal API defined in a secondary service, which in turn depends on shared data models in a core library repository, standard local-workspace tools hallucinate signatures, invent non-existent endpoints, or shrug. At 365Finds, we consider cross-repository context the single defining test of whether an AI tool belongs in enterprise software development.
Sourcegraph Cody takes a fundamentally different engineering path. Instead of forcing your local IDE to build clumsy ad-hoc vector dumps or relying strictly on open editor tabs, Cody offloads codebase indexing and context retrieval to an enterprise backend. By combining Sourcegraph’s Zoekt trigram search engine, SCIP-based code graphs, hybrid semantic embeddings, and granular context filtering, Cody turns distributed enterprise repositories into a navigable, permission-aware context graph.
Here is an architectural breakdown of how Sourcegraph Cody indexes multi-repository codebases, how its context retrieval pipeline works during active queries, and how engineering teams should configure it for deterministic precision.
1. The Multi-Repo Problem: Why Local Vector RAG Fails
Standard AI tools use localized Retrieval-Augmented Generation (RAG). They slice open files into chunks, compute vector embeddings, store them in a temporary local vector cache, and perform nearest-neighbor searches against user prompts.
In enterprise multi-repo architectures, this model breaks down immediately:
- Missing Cross-Boundary Symbols: An API gateway repository might call an RPC method defined in another repository. A local assistant sees only the invocation, not the interface definition, leading to fabricated parameters.
- Vector Search Imprecision: Vector embeddings excel at conceptual topics (like finding "rate limiting"), but they struggle with exact symbol resolution. If your query targets
UserAuthV2.validateToken(), vector similarity might pullUserAuthV1.checkToken()because the embeddings look nearly identical. - Scale and Freshness Bottlenecks: Re-indexing 500 active microservices on developer workstations is impossible. Local caches fall out of sync with latest main-branch merges within hours.
- Context Poisoning: Dumping entire files or irrelevant repository chunks into the prompt degrades LLM reasoning. Irrelevant code consumes the token budget and misleads the model.
At 365Finds, our research emphasizes that enterprise code search must be structural and deterministic, not merely probabilistic. This is where Sourcegraph’s backend infrastructure changes the calculation.
2. The Enterprise Indexing Architecture
Sourcegraph Cody does not index multi-repository environments from the developer's client. Instead, it relies on the centralized Sourcegraph Enterprise instance (self-hosted or cloud-managed) connected directly to your organization’s code hosts (GitHub, GitLab, Bitbucket, or Perforce).
The backend executes a three-part indexing pipeline across every synced repository:
[Code Hosts: GitHub / GitLab / Bitbucket]
│
▼
Sourcegraph Backend Sync
│
┌─────────────┼─────────────┐
▼ ▼ ▼
[Zoekt Engine] [SCIP Graph] [Hybrid Embeddings]
Trigram Text Definitions Dense Vectors
& Regex Search & References Semantic Intent
Zoekt: High-Throughput Trigram Indexing
Zoekt is Sourcegraph's open-source, trigram-based search engine designed specifically for source code. Zoekt breaks every file down into 3-character n-grams (trigrams) and builds an inverted index over the code text.
- Sub-second Scalability: Zoekt indexes petabytes of code across thousands of repositories, answering exact string, symbol, and regex queries in milliseconds.
- Deterministic Keyword Matching: When Cody needs to verify whether a specific function name, interface, or configuration key exists in another repository, Zoekt resolves it instantly without vector fuzziness.
SCIP: Precise Code Graph Intelligence
Keyword search tells you where text appears; it does not tell you what the code does. Sourcegraph uses SCIP (Sourcegraph Code Intelligence Protocol), a language-agnostic code graph protocol that succeeded LSIF.
- Semantic Resolution: SCIP captures compiler-level definitions, references, implementations, and type hierarchies across files and cross-repo package boundaries.
- Precise Navigation: If Cody needs to know where an interface declared in
@repo/core-contractsis implemented in@repo/billing-service, SCIP provides a deterministic graph edge rather than a guess.
Hybrid Vector Embeddings
To complement Zoekt and SCIP, Sourcegraph supports chunk-based vector embeddings. Code is split along logical boundaries (functions, classes, structural blocks) and vectorized. When a developer asks a high-level conceptual question—such as "how do we handle dead-letter queues in our ingestion pipeline?"—semantic embeddings surface the relevant code chunks even if the exact words "dead-letter" are absent from the function name.
3. The Retrieval Pipeline: How Cody Pulls Context at Runtime
When a developer prompts Cody in their IDE (VS Code, JetBrains) or in Cody Web, the system triggers a multi-stage context retrieval pipeline.
[Developer Prompt in IDE]
│
▼
[Intent & Query Expansion]
(Extract symbols, paths, topics)
│
┌──────────────┴──────────────┐
▼ ▼
[Local Workspace Context] [Remote Multi-Repo Context]
- Active buffer & selection - Sourcegraph Search API (Zoekt)
- Recent file tabs - SCIP definition & reference graphs
- Local Git diffs - Vector embeddings
│ │
└──────────────┬──────────────┘
▼
[cody.contextFilters & RBAC]
Permission & Policy Check
│
▼
[Re-ranking & Token Budgeting]
(Deduplication & Concision)
│
▼
[Augmented LLM Prompt]
Step 1: Query Intent Parsing & Expansion
Cody first parses the user prompt. A lightweight analyzer extracts symbol candidates, file path hints, and natural language concepts. If the prompt says:
"How does
payment-servicevalidate tokens generated byauth-service?"
Cody splits this into multiple retrieval requests:
- Exact symbol lookups for token validation functions.
- File path filters targeting
payment-serviceandauth-service. - A semantic search query covering token validation mechanisms.
Step 2: Multi-Repository Traversal
Cody concurrently queries two context tiers:
- Local Context: The developer’s open file, selected code snippet, recently viewed files, and local Git diffs.
- Remote Multi-Repo Context: The Sourcegraph Search API queries the indexed enterprise repositories using Zoekt and the code graph to locate definitions, usages, and matching documentation.
Step 3: Explicit Scoping via @-mentions
While Cody can automatically detect context, 365Finds strongly advises developers working across microservices to guide retrieval explicitly using @-mentions.
@repo:org/service-name: Restricts or anchors context retrieval to a designated remote repository.@file:path/to/file: Injects an exact file across repos.@symbol: Pulls an exact cross-repo symbol definition.
This cuts retrieval latency and prevents unrelated repositories from polluting the context window.
Step 4: Access Control and Context Filtering
Enterprise security is non-negotiable. Before any remote snippet enters the LLM prompt, Cody enforces two layers of validation:
- Code Host RBAC Synchronization: Sourcegraph continuously mirrors access permissions from GitHub/GitLab. If a developer does not have read access to a proprietary repository on GitHub, Cody refuses to pull context from it.
- Context Filters (
cody.contextFilters): Administrative rules that programmatically restrict which repositories Cody can read (explained below).
Step 5: Ranking, Pruning, and Token Budgeting
LLM context windows are precious. Cody's ranking engine evaluates candidate snippets using relevance scoring:
- Proximity to referenced symbols.
- Exact match frequency versus semantic similarity.
- Recency of commits on the target branch.
The context assembler trims excessive boilerplate, collapses duplicate definitions, and injects only the essential code slices into the prompt sent to the LLM (Claude, GPT, or Gemini).
4. How to Configure Multi-Repo Context: Step-by-Step
To achieve reliable cross-repository context, enterprise teams must configure both backend indexing and administrative governance.
Step 1: Ensure Full Code Host Synchronization and Zoekt Indexing
In the Sourcegraph Site Admin dashboard, verify that all participating repositories are actively mirrored and indexed:
- Navigate to Site Admin > Repositories.
- Confirm the code host connection (e.g., GitHub Enterprise or GitLab Self-Managed) has repository discovery enabled.
- Check the Search Indexing status. Every target repository must show
Indexedunder Zoekt status. Repositories with pending or disabled indexing fall back to unindexed search, which severely degrades Cody's cross-repo retrieval speed and depth.
Step 2: Configure cody.contextFilters for Governance and Noise Reduction
We consider cody.contextFilters a mandatory configuration, not an optional preference. Without context filters, Cody may scan internal utility mirrors, archive forks, or compliance-restricted repositories.
Site administrators configure this in the Sourcegraph Site Configuration JSON (Site Admin > Configuration):
{
"cody.contextFilters": {
"include": [
{
"repoNamePattern": "^github\\.com\\/mycompany\\/(services|libraries|apis)\\/.+"
}
],
"exclude": [
{
"repoNamePattern": ".*-deprecated$"
},
{
"repoNamePattern": "^github\\.com\\/mycompany\\/security-vault"
},
{
"repoNamePattern": ".*-vendor$"
}
]
}
}
include: Explicitly limits Cody to authorized repository namespaces. Any repository outside this pattern is completely ignored by the context engine.exclude: Excludes sensitive vaults, legacy codebases, and massive third-party vendor trees that cause context poisoning.
Step 3: Connect Client IDEs to the Enterprise Endpoint
Developers must connect their IDE extension directly to the enterprise instance rather than using individual Cody Free/Pro accounts:
- Open Cody settings in VS Code or JetBrains.
- Under Enterprise Instance URL, enter
https://sourcegraph.internal.mycompany.com. - Authenticate via your enterprise SSO or User Access Token.
- Verify in the Cody chat status bar that the active enterprise instance and repository context provider are recognized.
Step 4: Train Developers on Cross-Repo Chat Patterns
Cross-repo queries require conversational intent discipline. Contrast these two queries:
- ❌ Vague: "How do we call the user service from the checkout service?"
- ✅ Precise: "In
@github.com/mycompany/services/checkout, how do we invoke the authorization check defined in@github.com/mycompany/libraries/auth-client?"
The second query allows Cody to bypass speculative multi-repo scanning and pull the exact interface definitions directly into the prompt.
5. 365Finds Institutional Evaluation & Recommendations
At 365Finds, we evaluate developer tooling based on real-world engineering trade-offs, not marketing claims. Here is our assessment of Sourcegraph Cody’s multi-repo indexing architecture:
| Feature / Dimension | Sourcegraph Cody Enterprise | Traditional Local AI Assistants |
|---|---|---|
| Search Engine | Trigram Zoekt + SCIP code graph | Local token-frequency or basic vector cache |
| Multi-Repo Breadth | Hundreds of remote repositories concurrently | Single open workspace folder or active tab |
| Cross-Repo References | Compiler-grade deterministic definitions via SCIP | Probabilistic guesses based on name similarity |
| Governance & Security | Site-wide regex context filters + Code Host RBAC | Manual .gitignore or local file exclusion |
| Infrastructure Overhead | High (Requires dedicated Sourcegraph instance) | Zero (Runs entirely on client machine) |
When We Strongly Recommend Cody
If your engineering organization operates across dozens of microservices, uses centralized API schema repos, or maintains shared internal SDKs, Sourcegraph Cody is arguably the most coherent enterprise coding assistant on the market. Its ability to anchor LLM responses in real code graphs prevents the subtle API hallucinations that plague lighter tools.
What to Watch Out For
- Infrastructure Cost: Sourcegraph Enterprise is an enterprise-grade platform. Running Zoekt and repository synchronization across thousands of repositories requires substantial compute, RAM, and SSD storage.
- Context Latency on Broad Queries: Asking completely unconstrained questions across hundreds of un-scoped repositories will introduce noticeable retrieval latency before the LLM begins streaming its response.
- The Necessity of Scoping Hygiene: Teams that rely entirely on passive retrieval will encounter occasional context poisoning. To extract the highest value from Cody, development leads must educate teams to use
@repoand@filescoping.
Sourcegraph Cody succeeds in multi-repository enterprise environments because it does not treat code search as a secondary feature of an LLM. It treats the LLM as an interface over a mature, deterministic code intelligence engine.