---
title: Custom Providers | CodeWeaver Docs
description: CodeWeaver is a code search engine for AI agents, designed to provide precise results that give agents exactly what they need for their tasks -- no more, no less.
url: "https://docs.knitli.com/guides/custom-providers"
type: static
generatedAt: "2026-04-17T17:21:09.958Z"
---

# Custom Providers
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/guides/custom-providers.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F&text=Custom%20Providers)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F&text=Custom%20Providers)[Share on Bluesky](https://bsky.app/intent/compose?text=Custom%20Providers%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F&title=Custom%20Providers)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F&t=Custom%20Providers)[Share on Email](mailto:?subject=Custom%20Providers&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F)[Share on WhatsApp](https://wa.me/?text=Custom%20Providers%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fguides%2Fcustom-providers%2F&text=Custom%20Providers)
# Custom Providers
[Section titled “Custom Providers”](#custom-providers)
> **TL;DR:** This module handles the registration and implementation of custom providers via the Dependency Injection (DI) system. Use it when you need to integrate a niche embedding model or vector store. It saves development time by allowing you to extend CodeWeaver without modifying the core codebase.

The Dependency Injection (DI) architecture of CodeWeaver makes it simple to add support for new providers. Whether you have a proprietary internal embedding API or want to experiment with a new vector database, you can plug your implementation into CodeWeaver with just a few classes.

---

## 1. Implement the Provider Class
[Section titled “1. Implement the Provider Class”](#1-implement-the-provider-class)
To create a new embedding provider, you must subclass `EmbeddingProvider`. This class defines how CodeWeaver interacts with your model’s SDK or API.


**

```
from typing import Sequence, Anyfrom codeweaver.core import CodeChunk, Providerfrom codeweaver.providers.embedding.providers import EmbeddingProvider
class MyCustomProvider(EmbeddingProvider[MyClient]):    _provider = Provider("MY_CUSTOM_PROVIDER")
    def _initialize(self, **kwargs):        # Setup your client or load your model        self.client = MyClient(api_key=self.config.api_key)
    async def _embed_documents(self, documents: Sequence[CodeChunk], **kwargs) -> list[list[float]]:        # Convert chunks to strings and send to your model        texts = [chunk.content for chunk in documents]        return await self.client.embed_batch(texts)
    async def _embed_query(self, query: Sequence[str], **kwargs) -> list[list[float]]:        # Embed a single search query        return await self.client.embed_query(query[0])
    @property    def base_url(self) -> str | None:        return "https://api.mycustomprovider.com"
```

---

## 2. Register Your Provider
[Section titled “2. Register Your Provider”](#2-register-your-provider)
Once your class is defined, register it with the CodeWeaver DI system using the `@dependency_provider` decorator. This allows CodeWeaver to discover and instantiate your provider at boot-time.


**

```
from codeweaver.core.di import dependency_provider
@dependency_provider(MyCustomProvider, scope="singleton")def create_my_custom_provider(    config: MyConfig = INJECTED,    registry: EmbeddingRegistry = INJECTED,    cache: CacheManager = INJECTED,) -> MyCustomProvider:    return MyCustomProvider(        client=MyClient(),        config=config,        registry=registry,        cache_manager=cache    )
```

---

## 3. Configuration
[Section titled “3. Configuration”](#3-configuration)
To use your new provider, simply update your `codeweaver.toml`. CodeWeaver will use the `provider` name to look up your registered class in the DI container.


**

```
[provider.embedding.0]provider = "MY_CUSTOM_PROVIDER"model_name = "my-special-model"api_key = "${MY_SECRET_KEY}"
```

---

## Best Practices
[Section titled “Best Practices”](#best-practices)
### A. Use `INJECTED` and `Depends`
[Section titled “A. Use INJECTED and Depends”](#a-use-injected-and-depends)
Always use the DI markers for dependencies like the `EmbeddingRegistry` and `CacheManager`. This ensures your provider participates in CodeWeaver’s deduplication and resilience features automatically.

### B. Define Capabilities
[Section titled “B. Define Capabilities”](#b-define-capabilities)
For optimal search results, define an `EmbeddingModelCapabilities` object for your model. This tells CodeWeaver about the model’s token limits and dimension sizes.

### C. Handle Errors Gracefully
[Section titled “C. Handle Errors Gracefully”](#c-handle-errors-gracefully)
Raise a `ProviderError` if your API fails. CodeWeaver will catch this and automatically attempt to use a local fallback provider (if enabled).

---

## Summary
[Section titled “Summary”](#summary)
Custom providers turn CodeWeaver into a truly universal context platform. By following the DI-driven patterns, you can ensure your integrations are as robust and resilient as the built-in providers.