Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:CrewAIInc CrewAI Embedder Config

From Leeroopedia

Metadata

Field Value
Implementation Name Embedder Config
Workflow Knowledge_RAG_Pipeline
Category Vector Representation
Repository crewAIInc/crewAI
Implements Principle:CrewAIInc_CrewAI_Embedding_Configuration

Overview

Concrete type alias and provider specifications for configuring embedding models across 18+ providers provided by the CrewAI RAG subsystem. The EmbedderConfig type alias unifies provider-specific TypedDicts, base provider instances, and provider classes into a single configurable type.

Source Reference

File Lines
src/crewai/rag/embeddings/types.py L32-76

Signature

EmbedderConfig: TypeAlias = (
    ProviderSpec
    | BaseEmbeddingsProvider[Any]
    | type[BaseEmbeddingsProvider[Any]]
)

Where ProviderSpec is a union of 18 provider-specific TypedDicts, each following the pattern:

class OpenAIProviderSpec(TypedDict):
    provider: Literal["openai"]
    config: dict[str, Any]

class OllamaProviderSpec(TypedDict):
    provider: Literal["ollama"]
    config: dict[str, Any]

# ... and so on for each provider

Allowed embedding providers:

AllowedEmbeddingProviders = Literal[
    "azure",
    "amazon-bedrock",
    "cohere",
    "custom",
    "google-generativeai",
    "google-vertex",
    "huggingface",
    "instructor",
    "jina",
    "ollama",
    "onnx",
    "openai",
    "openclip",
    "roboflow",
    "sentence-transformer",
    "text2vec",
    "voyageai",
    "watsonx",
]

Import

from crewai.rag.embeddings.types import EmbedderConfig

I/O Contract

Direction Type Description
Input dict with provider and config keys Provider specification dictionary matching one of the 18 provider TypedDicts
Input (alt) BaseEmbeddingsProvider instance A pre-configured embedding provider instance
Input (alt) type[BaseEmbeddingsProvider] An embedding provider class (instantiated by the framework)
Output EmbedderConfig Configuration value accepted by Knowledge, Crew, Agent, or KnowledgeStorage

Provider Configuration Details

Each provider accepts a config dictionary with provider-specific keys:

Provider Common Config Keys
openai model, api_key, api_base
ollama model, url
cohere model, api_key
huggingface model, api_key
google-generativeai model, api_key
azure model, api_key, api_base, api_version
amazon-bedrock model, region_name
sentence-transformer model
jina model, api_key
voyageai model, api_key

Code Examples

OpenAI Embedder Configuration

from crewai.rag.embeddings.types import EmbedderConfig

openai_embedder: EmbedderConfig = {
    "provider": "openai",
    "config": {
        "model": "text-embedding-3-small",
        "api_key": "sk-...",
    },
}

Ollama Local Embedder Configuration

ollama_embedder: EmbedderConfig = {
    "provider": "ollama",
    "config": {
        "model": "nomic-embed-text",
        "url": "http://localhost:11434",
    },
}

Using Embedder Config with a Crew

from crewai import Crew

crew = Crew(
    agents=[...],
    tasks=[...],
    knowledge_sources=[...],
    embedder={
        "provider": "openai",
        "config": {
            "model": "text-embedding-3-small",
        },
    },
)

Using a Provider Instance

from crewai.rag.embeddings.types import EmbedderConfig

# You can also pass a pre-configured provider instance
# instead of a dictionary specification
custom_provider = MyCustomEmbeddingsProvider(model="my-model")
embedder_config: EmbedderConfig = custom_provider

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment