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:
- Syntax blindness: Code is structured, hierarchical, and brittle. A missing comma or an unimported struct invalidates logic. Chunking splits function signatures from their implementations.
- Boilerplate collisions: Files named
handler.go,index.ts, orconfig.yamlshare semantic similarity across dozens of microservices, polluting vector results with completely irrelevant services. - 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.
- Trigram Extraction: When Sourcegraph clones and syncs your repositories via
gitserver, Zoekt parses all text and code files into overlapping 3-character sequences (trigrams). - Posting Lists & Memory Mapping (
mmap): Zoekt builds inverted index files called shards. These shards map each trigram to exact repository IDs, file paths, and byte offsets. Because shards are memory-mapped directly into the OS cache, Zoekt can evaluate complex regex patterns and exact symbol names across thousands of repositories in under 50 milliseconds. - ctags Integration: Zoekt indexes language symbols (classes, methods, variables) extracted via Universal Ctags, giving structural weight to symbol definitions over plain comments.
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.
- SCIP runs during CI/CD pipelines or background indexing jobs. It parses your code using compiler-level semantic tooling (such as
scip-typescript,scip-java,scip-python, orscip-go). - It generates a precise code graph detailing exact symbol definitions, implementations, and call hierarchies across repository boundaries.
- When Cody needs to understand an API call, it queries the SCIP graph. Instead of guessing how a method works, it injects the exact target definition into the prompt.
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.
- Server-Side Embeddings: Sourcegraph Enterprise can generate vector embeddings for designated repositories, but uses them as a complementary ranking signal rather than the primary backbone.
- Client-Side
symf: When working on uncommitted local code or in environments without an enterprise server, the Cody extension runs a lightweight local binary calledsymf. It indexes the local workspace on device to provide quick semantic search without sending uncommitted files to external indexers.
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:
- 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? - 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:
- Zoekt retrieves files containing matching method names and configuration keys.
- SCIP navigates cross-repository imports to find referenced structs and signatures.
- Contextual BM25 and embedding rankers surface conceptually relevant snippets.
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:
- It scores candidate snippets based on symbol match accuracy, path proximity, and recency.
- It truncates surrounding irrelevant lines, preserving function signatures, type definitions, and the specific lines of interest.
- It packages the prioritized snippets into a unified prompt payload and dispatches it to the model.
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 Layer | Mechanism | Practical Impact |
|---|---|---|
| Code Host ACL Sync | Sourcegraph 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 Filters | Site 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 Routing | Commercial 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:
- The 10-Repository Chat Ceiling:
Manual
@-mentionscap 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. - 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 mergedmainstate, not an unmerged feature branch opened an hour ago. Local uncommitted changes are only captured in the developer's immediate active editor viasymfand local buffer state. - 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 forzoekt-indexserverandgitserver. 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.