Chrome Extension Storage & Repositories
Relevant source files
The following files were used as context for generating this wiki page:
The Chrome Extension Storage & Repositories system provides the infrastructure for managing indexed GitHub codebases within a browser environment. This system facilitates the bridge between the GitHub web interface and high-performance vector storage, allowing users to index repositories, store metadata locally via Chrome's storage APIs, and persist vector embeddings in a Milvus database.
The architecture relies on a specialized background service worker to orchestrate data flow between the GitHub API, OpenAI embedding services, and the Milvus vector database. It utilizes chrome.storage.sync for user configurations (like API keys) and specialized managers to track which repositories have been indexed.
Sources: packages/chrome-extension/README.md, packages/chrome-extension/src/background.ts:413-430
Repository Indexing Workflow
The indexing process transforms a GitHub repository into a searchable semantic index. It involves fetching file trees, retrieving content, chunking code, generating embeddings, and storing them in Milvus.
Data Flow Architecture
The diagram shows the top-down flow from the user triggering an index in the UI to the final persistence in Milvus and metadata storage.
Sources: packages/chrome-extension/src/background.ts:432-511, packages/chrome-extension/src/content.ts:167-184
Key Components
| Component | Description | File Path |
|---|---|---|
processFileList | Orchestrates the batching of files and chunks for embedding. | packages/chrome-extension/src/background.ts |
splitCode | Implements character-based chunking (1000 chars, 200 overlap). | packages/chrome-extension/src/background.ts |
EmbeddingModel | Handles communication with OpenAI to generate 1536-dim vectors. | packages/chrome-extension/src/background.ts |
ChromeMilvusAdapter | Browser-compatible wrapper for Milvus RESTful API. | packages/chrome-extension/src/milvus/chromeMilvusAdapter.ts |
Storage Layers
The extension utilizes multiple storage mechanisms to balance performance and persistence requirements.
Metadata & Configuration
chrome.storage.sync and chrome.storage.local are used for lightweight data:
- API Keys:
githubToken,OPENAI_API_KEY, and Milvus credentials. - Repository Registry: A list of indexed repositories managed by
IndexedRepoManager, including metadata liketotalFiles,totalChunks, andindexedAttimestamps.
Sources: packages/chrome-extension/src/background.ts:348-360, packages/chrome-extension/src/content.ts:37-45
Vector Storage (Milvus)
Vector embeddings are stored in Milvus collections named with the pattern chrome_repo_[owner]_[repo]. Each entry in the database follows the CodeChunk structure:
export interface CodeChunk {
id: string; // path + chunk index
content: string; // raw code text
relativePath: string; // path in repo
startLine: number; // start line in file
endLine: number; // end line in file
fileExtension: string; // e.g. 'ts', 'py'
metadata: string; // JSON stringified extra info
vector?: number[]; // The 1536-dim embedding
}
Sources: packages/chrome-extension/src/milvus/chromeMilvusAdapter.ts:7-16, packages/chrome-extension/src/background.ts:98-101
Search Logic and Data Retrieval
Search operations utilize cosine similarity to find relevant code snippets based on natural language queries.
Search Sequence
The sequence illustrates how a query is transformed into a vector before performing a similarity search in Milvus.
Sources: packages/chrome-extension/src/background.ts:563-582, packages/chrome-extension/src/content.ts:303-345
Search Metrics
Results are returned with a similarity score (0-1). The UI categorizes these for the user:
- High Match: >= 80%
- Medium Match: >= 60%
- Low Match: < 60%
Sources: packages/chrome-extension/src/content.ts:379-385
Browser Compatibility Stubs
Because the extension runs in a browser environment, it uses webpack.config.js to provide polyfills and stubs for Node.js-specific modules (like crypto, path, and buffer). This is critical for the claude-context-core package to function within the extension.
Key Polyfills used:
crypto-browserifypath-browserifyvm-browserifystream-browserify
Sources: packages/chrome-extension/CONTRIBUTING.md:58-69, packages/chrome-extension/package.json:28-40
Conclusion
The Chrome Extension Storage & Repositories system effectively adapts the Claude Context indexing engine for the web. By combining Chrome's native storage for configuration with a RESTful Milvus adapter for heavy vector data, it enables semantic search directly within the GitHub UI without requiring a local Node.js environment for search operations.